Remote Control implementation for an RC Car – Part 1

There are many ways you can add remote control to a project. Off the shelf modules; Bluetooth; 2.4GHz NRF24L01+ transceivers; 433MHz/434Mhz modules or even Infra-red.

remote_control

My plan with our ZL-4 el-cheapo RC car was to use an Elecfreaks Joystick Shield, an Arduino board and the NRF24L01+ modules mainly because [a] the joystick shield has a connector for one and [b] I want to use them in another potentially commercial project and thought it would be a good learning exercise. They are also stunningly cheap at €1.26, including shipping, for each transceiver.

Unfortunately I discovered that the Adafruit Motor Shield on the RC car uses up a ton of the pins on the Arduino and makes it very hard to add the NRF24L01+. In particular it uses the SPI pins which you need to talk to the NRF24L01+.

So I went with Plan B which was the 433Mhz modules. These things are fab. They work in the unregulated ISM band like most weather stations etc and, like the NRF24L01+, are gob-smackingly cheap – €1.97 for the receiver and €2.14 for the transmitter. When I see people creating really simple projects but with 2x €20+ Zigbee modules, I just don’t understand it.

The 433MHz modules main advantage relative to the NRF24L01+ is that they can cover longer distances with a properly setup aerial. The main disadvantages are that they generally need that aerial, they have a very low bit-rate and you have to deal with most of the error correction etc yourself.

What transforms these modules into something pretty spectacular is the VirtualWire library for Arduino. This takes care of all the low-level transmit/receive code and you have to do little more than the equivalent of a print statement. Just think about this. You can send any information you like over hundreds of feet using €4 worth of electronics by simply calling:

vw_send((uint8_t *)msg, strlen(msg));

No Wifi or SMS needed! Of course this is a broadcast message and anyone can pick it up but who cares.

The one thing we do have to figure out is what happens when multiple devices are broadcasting locally. Will they interfere with each other? I know VirtualWire has CRC checking but that’s not much use if every message is corrupt.

For the remote control I have created an extremely simplistic “protocol”. The transmitter sends out the following every 200ms:

XnnnnYnnnnAnBnCnDn

Where Xnnnn is the X-axis of the joystick from 0 to 1024, Ynnnn is the Y-axis of the joystick from 0 to 1024, An is button-A 0 or 1, Bn is button-B 0 or 1, Cn is button-C 0 or 1 and Dn is button-D 0 or 1.

remote_control2

We are now successfully receiving and interpreting those messages on the RC car and doing forward/reverse. The bit we have to figure out is turning, as the car doesn’t have any steering.

More updates in a few days when we crack that nut. And I’ll obviously have to add some sort of “addressing” for the scenario where more that one RC car is being controlled in the house.

My £1.37 Shrimp Computer

I heard about the Shrimping It project a few months ago and loved it immediately. Based in Morecambe in the UK (hence the name), it’s an initiative to get Arduino compatible boards in the hands of anyone for less than £2.

I couldn’t resist and ordered the necessary ATMega chip plus Xtal from Farnell in Ireland along with the usual cheapo bits from DX in China.

You also need to splash out on a CP2102 programmer on eBay. Mine cost £2.08.

Last night I soldered the whole thing up, and amazingly for me, it worked first time. I added some headers to make connecting simpler and ran the Arduino LED Blink example on it.

I’ll be using this one for the next i-racer remote control that I build.

If you are interested in playing around with electronics or teaching your kids about it, I can’t think of a better way to spend a fiver.

Electronic Tinkering on the @Raspberry_Pi and @Arduino

I’ve been lucky to-date that I haven’t killed the RPi stone dead with my little projects. I find the simplest way to help avoid any catastrophic shorts is to use an old 40-core IDE cable (note, the “newer” 80-core ones don’t work even tho they fit). I Dremeled mine last week to fit in this very nice inexpensive case.

In many ways, that GPIO header on the RPi is like the expansion port on the ZX Spectrum. So much possibility, so much danger :-)

I’m finding myself jumping back and forth between the RPi and Arduino a lot recently. Arduino is amazing because of the huge body of code and boards that are available. Interfacing to most things often just requires wiring it straight in and pasting some code off the web. In the picture above you can see an Arduino Nano which is both tiny and cheap ($10). Where Arduino falls down is when complexity is required. A 8-bit CPU can’t just be connected straight to the internet or to a Bluetooth USB dongle. This means that some of the add-on boards (particularly Wifi) cost multiples of the Arduino itself.

The Arduino code for Nunchuck worked perfectly first time, but right now I’m waiting on a Bluetooth Master module from China to connect it to the i-Racer ($10 module vs $2 USB BT dongle). Whilst I’m waiting, I’ve been trying to get the Nunchuck working on the Raspberry Pi. I’ll do a full post in a few weeks but suffice to say it has not been straightforward. Scanning I2C reliably with Python is proving a struggle and I don’t know if it’s HW or SW related. Having a Python runtime and Linux kernel between your code and the Nunchuck may not be the best for realtime performance. Compare that to the Arduino code which is raw machine code with no OS, reading its pins directly on a bullet-proof I2C bus.

There are many types of boards out there to make interfacing to the Raspberry Pi easier. They range from simple breakout boards converting male headers to female headers all the way up to big motor control boards with their own microcontrollers. I haven’t bought any of these yet, so it’s up to you to figure out what is most appropriate for your project.

Slice of Pi
Only £3.90, this is a breakout board which just makes it easier to connect jumper wires and less likely that you’ll short anything out. One of its headers is XBee compatible. Probably worth getting no matter what you are doing. Very simple self-soldering to assemble and comes with all the parts

UPDATE 1 – 16/02/2013: Slice of Pi/O
Big thanks to Conor Houghton for pointing out this board which I had missed. It is the Slice of Pi with an IO expander chip. The basic idea is that you communicate to the chip using I2C and it handles all the actual interfacing and buffering. So your RPi is much less likely to be damaged. If you damage the MCP23017 chip itself, you just pop it out and put in a new one for €1.53 from Farnell. Lots of info about it here. This is in fact the board that I ended up buying. It is only £7.89 delivered to Ireland which is in keeping with the low price point of the RPi itself.

PiCrust
This is similar to the basic Slice of Pi but has more headers. However you have to order all the parts separately yourself. Still very inexpensive.

Adafruit Prototyping Plate
This is the same idea again but with lots of connectors and plenty of space to permanently solder things on. $16 in US and I’m sure someone is selling on this side of the pond too.

PiFace
This is more complex and has relays, motor control, switches etc. At €25 it won’t break the bank and  comes fully assembled. You can program in Python, C and Scratch. The last one is verrrrry interesting for something like Coder Dojos. I showed my RPi at Bandon Coder Dojo last week and got a ton of interest from kids and parents. Being able to do robotics in Scratch would blow a lot of their minds.

UPDATE 2 – 17/02/2013: RaspiRobot Board
This was just announced by Sparkfun on Friday. It’s specifically for robotics and seems decent value at $29.95. After you’ve assembled it, it provides dual bi-directional motor controllers, two open collector outputs, two switch inputs and a voltage regulator capable of powering the Pi itself. A LiPo battery or 6 x AA batteries should provide the juice you need. Obviously Model A is the one to go with for robotics due to the much reduced power consumption.

Arduino Shield Bridge
This is a neat idea. It makes it possible to connect Arduino Shields (shields are the Arduino add-on boards) to your Raspberry Pi. Whilst boards like Wifi are expensive on Arduino, there are tons of control and interfacing boards which are very cheap. Things like Joystick boards, environmental sensors, heavy-duty motor control, RFID, XBee etc. They have created an Arduino-compatible library so you can use some of the same Wiring code on the Raspberry Pi that you would use on Arduino. Note that this can’t work with everything but their site is good in explaining what will work. It is €40 which is starting to get pricey for something which may only be suitable in a subset of cases.

Alamode
This takes the same Arduino idea and extends it further by basically giving you a full Arduino board which plugs neatly into the Raspberry Pi. You can see it as either adding Arduino functionality to the RPi or giving the Arduino very inexpensive Ethernet capabilities. However at $50, we are now at twice the price of a Model-A Raspberry Pi and many Arduino boards. So you really need to be sure this is something you need and will use. I’ve hooked Arudino up to RPi but only using USB. Clunkier, simpler but a lot cheaper.

Gertboard
This is probably the best known board as it was designed by one of the people originally involved in the RPi design. Whilst it is not “the official board”, many people see it as such. It is a very high end board with lots of functionality, particularly around motor control for robotics etc. It even includes the same ATMega MCU as an Arduino. Originally a kit, you can now buy pre-assembled for £30. My guess is that it will see the most community support due to its high profile. But like so many of the other boards I’d point to the fact that it’s more expensive than the RPi itself.

If I’ve missed any others, please let me know in the comments. At the minute I’m tending towards the simpler breakout boards. With a little care, you should be ok and they aren’t adding much to the overall cost of the RPi. The power requirements of the Pi mean that using it for robotics etc probably isn’t a runner for me and I’ll stick with the Arduino for that. Ditto anything that I want to do outdoors. But for projects where you need to get the data online, an RPi is ideal.

I’m particularly excited by the idea of using Scratch to both interface to the real world and maybe even access the web. I wonder is anyone working on web services functionality for Scratch? I was disappointed that no-one did the same for MIT App Inventor and the IOIO board.

Actually, that reminds me I meant to blog about ModKit. An absolutely brilliant Arduino project to bring Scratch-style/App-Inventor-Style development to that platform.

You install a simple program on your PC and then do everything else in the browser (desktop app optional). It’s amazing to drag a few blocks in a browser IDE which say “blink LED” and then the LED on the Arduino on your desk starts blinking! It’s projects like this that will get kids interested in hardware and electronics big time. Perhaps it might eventually support RPi plus one of the boards above.

Baby Steps on our first real Arduino Project

The kids and I have a silly idea for an Arduino project involving doorbells. So I ordered some parts from Sparkfun in the US (love that site so much) and they arrived quickly:

Then I lashed together the bare basics to make sure what we want to do will work. Press the button:

Press it again:

etc

Amazing to see the reaction from the kids, even teenage friends of theirs. I think it’s the tactility and physicality of the whole thing. If it was a piece of code running on a PC or phone, I’m sure the response would have been “whatevah”

Next steps are to add all the other buttons and then start on the Raspberry Pi part of the project.

Off we go to Maplins now to get a few more little things for it and my other far more serious project (if you can figure out what one of the parts in the first pic is, you may be able to guess)

 

If you watch one YouTube video this weekend, watch this TED one on how Arduino is open-sourcing imagination

Massimo Banzi is one of the creators of Arduino, an Open Source hardware platform that is used everywhere from robot kits for kids to the Large Hadron Collider.

If you are, like me, bored senseless with the same old Twitter/Facebook/YaddaYadda, watch this and then watch your imagination take flight.

Two tutorials later and the kids are liking the Arduino a lot

I sat down with 8 y/o daughter and 10 y/o son this afternoon to try out our ARDX starter kit for Arduino. The first tutorial is a simple single LED which you flash on/off in software. But I was horrified to find myself stumped!

Yes, I may have a Masters in Electronic Engineering from UCD but, as anyone who did Electronics there prior to the mid-90s knows, a certain lecturer ensured that we all left completely clueless in basic circuit cop-on.

The ARDX kit on the surface has a lovely introductory booklet but it really misses the mark on practical instructions. So they tell you what every component does which is good but nowhere does it explain how the holes in a breadboard are connected. Are they long columns of commonality or short rows? Do the power lines go from top to bottom or only in small blocks? Kind of important information!

Add to that a completely indecipheral diagram for where the components should go plus several connections which were totally unnecessary and I ended up totally flustered with the two kids getting bored.

Finally I threw away the instructions, thought about it for a second and realised it was dead easy. Some trial/error figured out the breadboard layout and hurrah, a blinking LED! We played a bit with on/off timings and we were immediately ready for more.

This time we did 8 LEDs which worked right first time and we loved the default on/off pattern. One thing we realised was that a magnifying glass is a big help when trying to see the individual breadboard holes.

And that’s as far as we got. They both want to try some more interesting LED patterns and then move on to the motors, servos and sensors. The long term plan is to build something “robotic”.

More on that next weekend.

Then of course I found this site called DIYDrones about UAVs………

Learn electronics with an Arduino and @Raspberry_Pi on an old Philips TV

Been slammed with work for two weeks (will never complain about that!) which means blogging has been a bit light. But the big excitement yesterday was my ARDX Arduino Starter Kit arriving from Seeedstudio.

If you are not familair with Arduino, it is an OpenSource hardware platform for electronics projects, tinkering, robotics, home automation etc etc etc. The blue board above is the heart of it.

The Starter Kit makes it possible for anyone, even with zero electronics knowledge to assemble simple circuits with no soldering and then run code on the Arduino microcontroller to do “things”. In this kit it ranges from blinking an LED to controlling a motor. Once you get the hang of it, a whole world of experimentation awaits you. There are also tons of add-on boards called Shields to do everything from advanced motor control to LCD and GPS.

I haven’t had a chance to try anything on the Arduino yet except run a simple program to flash the on-board LED.

But I was over the moon to discover that that Raspbian distribution for Raspberry Pi has a working copy of the Arduino IDE which is what you use to write your programs, upload them to the Arduino and run them. A few minutes later, I had everything working.

Then for kicks and giggles I connected the RPi up to a 12 yo Philips portable telly. And it works too! Massive massive flashbacks to the ZX Spectrum days.

This is more amazing than it first might seem. Think about it – A computer for $25 connected to an electronics learning kit for $79 connected to an old telly. Everything you need to become competent with both computers and electronics. And you don’t even need the internet at home.

Get a wifi dongle for €6 and borrow a mobile phone charger. Then spend an hour a week in school or Coder Dojo or somewhere offering free Wifi (Mahon Point!) to grab any software updates you need and to download any webpages, manuals, example code etc. And you can do the rest at home.

Old school!

I’ll do a video and proper post on the Arduuino kit once I’ve assembled it and tried out a few of the projects over the weekend.