Tuesday, February 19, 2013

Raspberry Pi + GPIO + Scratch + Remote Control Car

At the beginning of 2013 I started a Code Club at my local primary school and the kids love making and playing the games.  Due to the way the club is set up in the school there is expected to be a few classes after the official Code Club sessions are completed so I've been trying to come up with some ideas of things I could bring in to the class to show the kids that Scratch can do more than make a cat move around the screen.

Then on my regular trawl of the web I found this fantastic code http://cymplecy.wordpress.com/2012/08/26/scratch-controlling-the-gpio-on-a-raspberrypi/ for controlling the GPIO pins on the Raspberry Pi using Scratch.

With an old cheap remote control car in a drawer I had the makings of a fun project for me that (hopefully) will be of interest to the kids.

 Having read that the Raspberry Pi GPIO pins are not protected, so one silly mistake on my part could cause the death of my Raspberry Pi I dusted off my old electronics knowledge and put together a small transistor based driver circuit for the 4 pins used.

one circuit per pin

I originally wired this up on a protoboard and it worked, except for when it failed. Did I mention the remote control car was cheap. Well, the aerial was just a bit of wire and with all the other wires I added to the circuit there was regular interference that caused the remote to activate the wrong signal making it unreliable. Knowing the circuit was good the logical thing to do was to put the circuit on a proper board. Rather than going all the way to etching my own circuit board I made it up on a stripboard

again, 1 circuit per pin. white blobs under resistors are cuts in the tracks

After a false start (details of things I almost did wrong) I got the 4 circuits soldered up and tested.  Worked first time.

Not the prettiest soldering but after doing near no soldering for over 20 years I was happy with the result.

Now I the circuit soldered up and it worked. With a bit of coding in Scratch I could program the remote control car for a sequence of actions like
Forward 2 second
Left 0.5 seconds.
Reverse Right 2 seconds

As you'd expect from a simple remote control car the was no way to give very accurate instruction. The motor was either on or off, no variable speed or feedback.  Even with these limitations it felt great when I clicked on the code in Scratch and car actually did what I expected it to do.



the vehicle of my success!!!

And finally he is a short video of the car in action.


This is why I love the Raspberry Pi and the fun of hacking.  With a little bit of effort you can have a lot of fun. Now I have a remote control car that I can control with drag and drop commands in Scratch on a £30 computer.