Showing posts with label control. Show all posts
Showing posts with label control. Show all posts

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.


Thursday, January 17, 2013

Raspberry Pi - GPIO - Scratch - Remote Control Car

IT'S ALIVE!!!!

Tonight I wired up the remote to the circuit and the circuit to the GPIO pins on the Raspberry Pi.
Booted the Raspberry Pi and connected using Putty and Xming to get an Xwindow display on my netbook.

Ran the GPIO Scratch after installing the code I mentioned before.

 The bits of code make the car go forward, backwards and turn (forwards and backwards)

Raspberry Pi in PiBow connected to the circuit for controlling the remote control
 Ignore the Arduino in the picture I just have it attached to the
board with the proto board

When I click on the code blocks the car moved - YEAH!. So, I figured out the controls for the remote.  Make 4 small circuits to allow the GPIO Pins to activate the remote control.  With a massive amount of help from http://cymplecy.wordpress.com/2012/08/26/scratch-controlling-the-gpio-on-a-raspberrypi/ where I got the Scratch GPIO control code from I got Scratch to switch the GPIO pins and made the car move.

The quality of the car was causing some problems as the wheels would get stuck on the carpet.

This was great fun to do and as a possible beginners electronics/Raspberry Pi/Soldering/Scratch project it may suit. Wait a moment that kind of a very specific set of requirements.

Here's hoping the car is bit more accommodating on Sunday.



Wednesday, January 16, 2013

Messing with a remote control car and some transistor

As per a previous post I have arranged a Raspberry Pi event (Raspberry Jam) at Gartner's offices in Egham on Sunday the 20th January.

Originally I was considering setting up my Raspberry Pi on a big screen with the Atari 2600 emulator running and a joystick for some old school nostalgia gaming but then I thought that might be a bit boring.

Since I have volunteered to run a Code Club at my kids school I thought how about something in Scratch.  Code Club uses Scratch and Raspberry Pi has  Scratch so if I did something in Scratch then I could have it at the Raspberry Jam and then also show it to the kids at a future date as an example of what is possible with Scratch.

Code Club does programming I thought maybe something with electronics and since I have an old cheap remote control car gathering dust I thought I'd try to design a switching circuit that would allow the Raspberry Pi to control the car from within Scratch.

My knowledge of Scratch, GPIO and Python are limited so it was lucky that somebody far smarter than me has developed the code to allow Scratch to control the GPIO pins. All the details at this link -  http://cymplecy.wordpress.com/2012/08/26/scratch-controlling-the-gpio-on-a-raspberrypi/
After figuring out I needed the latest image of Raspbian for this code to work I was off.
I did the obligatory flash an LED to make sure it all worked on the Raspberry Pi and it did.

Confident that Scratch could control the GPIO pins I turned my attention to the no name, small, cheap remote control.
Out with the multi-meter to check where the switches went to and how they were wired to the one IC on the board. I figured out that the pins are all held high and then go low to be actioned.
The remote from my testing old uses 0.1mA so it probably would have been safe to just attach it to the Raspberry Pi, but not sure if this was correct I decided to put in a transistor switching circuit that would hold the line high until a high is applied to the GPIO pin for that control and then it would go low. Effectively enabling that button on the remote and sending the relevant signal to the car.

I used a 2N222a NPN transistor for the circuit and again being concerned that my very rusty electronics would fail me I posted to the Raspberry Pi Forum asking if the design was OK including a small circuit diagram.(http://www.raspberrypi.org/phpBB3/viewtopic.php?f=44&t=29730) and amazingly Gert van Loo the Gertboard guy replied saying the circuit was good with a recommendation to add a 10K resistor from the GPIO to ground so the GPIO pins start in a determined state. (Yes, I'm missing a 2 in the image I'll fix it later)

With my head swelling from Gerts positive comments but still not ready to test with my precious Raspberry Pi that I needed for Sunday (plan B of Atari 2600 is still an option) I wired up the circuit to my Arduino who's pins a bit more robust.

Created a small bit of  code that set the pins high and low to see if it responded.

RESULT - the car went, forward, backwards, turned left, turned right.all controlled by the Arduino code

This means the circuit is good.  The electronics of the transistor switches works with the cheap remote  control.

So, tomorrow (Thursday) evening I will wire it to my Raspberry Pi and see if the final product works and then can I control it in Scratch.

If yes, then I will have it with me on Sunday.

Roll on tomorrow evening and roll on Sunday.