…join them together!
But seriously, they are very different things for very different purposes, and it’s a bit sad that some hard-core Arduino fans hate the Raspberry Pi (though perhaps understandable). The Arduino is a relatively expensive (for its processing power) microcontroller, though it does have the backing of a huge open source community of software and hardware projects. I bought one while I was waiting for my Raspberry Pi to arrive, and to be honest we’ve learnt more about electronics and programming so far from the Arduino than we have from the RasPi.
The Raspberry Pi, however, is a ridiculously cheap actual computer with a graphics chip that can display HD video. Its potential is immense, but I can see a great future in joining the Arduino to the Raspberry Pi to get the best of both worlds. The Arduino is great for low-level stuff in the real world, with light bulbs, switches, sensors, motors etc, and the RasPi great at stuff like talking to the internet and storing larger amounts of data.
There is a hardware gizmo called the GertBoard which promises to make the GPIO pins on the Raspberry Pi more accessible to hacking and interfacing with electronics, but I’ve had a quick look at it, and it’s not for me. It’s £30, and comes as a bag of parts that require a great deal of soldering – and then one look at the manual had me heading for the hills. Just way too complex for me – and part of it seems to involve adding a microcontroller – practically piggy-backing an Arduino-type device on the Raspberry Pi. Well, I already have an Arduino I can plug in via USB, so why not just use that? I know directly addressing GPIO pins on the Raspberry Pi will be very useful, but at my level I’m quite happy turning lights on and off, ringing buzzers, maybe driving a 2-line LCD display – and USB should be fine for that.
And today I managed to get my Raspberry Pi talking to my Arduino – I could type text on the Pi’s keyboard, and the Arduino (connected via USB) would beep and flash the letters in Morse code using the Morse project we started a couple of days ago after visiting Porthcurno.
I worked out that an Arduino Uno presents itself to a Rasperry Pi (running Raspbian Wheezy 2012-08-16) as /dev/ttyACM0 but I could not get
echo 'sos' > /dev/ttyACM0
to do anything other than make the Arduino light blink. This is exactly the same problem I had in the OS X command line, so I wasn’t totally disheartened. I clearly had the right device name, but some kind of handshaking or protocol was awry. I remembered that I got round the problem in OS X using a command line ‘screen’ session, so I tried that – no luck on the Raspberry Pi, as ‘screen’ was not installed.
So, I connected my Raspberry Pi to the internet (another story in itself)* and at the command line typed
sudo apt-get install screen
Then typed on the RasPi command line:
screen /dev/ttyACM0 9600
The 9600 is the baud rate set in the Arduino Morse sketch I was using. Then any letter I typed into the console on the Pi was translated into Morse beeps and flashes on the Arduino, as I typed them. A very satisfying achievement. (You can exit a screen session by typing ‘ctrl-a d’ to disconnect.)
Arduino and Raspberry Pi – a perfect match for each other.
* getting the Raspberry Pi on the internet so I could install ‘screen’ was fun. TV upstairs, in constant use by kids. Internet router is downstairs in kitchen, where there’s no TV. Sounds like a job for SSH. To cut a long story short, I wasted hours trying to open a remote SSH session into the wrong IP address. It’s quite hard knowing what the IP address of a screenless Raspberry Pi is when you don’t have access to the broadband router’s admin page. In the end I used an OS X utility called IPScanner, but there are other tricks you can use. The most bizarre, but ingenious, one I found was installing something to blink the IP address on the Raspberry Pi’s onboard LEDs!
Once I’d got SSH working, I could leave the Raspberry Pi screenless, keyboardless and mouseless in the kitchen connected to the internet & the LAN via ethernet and to the Arduino via USB, and using an SSH session on my laptop upstairs send a morse code message to the kitchen asking for more tea. Yeah, a guy can dream… Well, I might possibly teach the kids some Morse code by getting one upstairs sending rude messages from the laptop to another in the kitchen with a Morse key chart and a pad of paper.
Next task – to install the Arduino IDE on the Raspberry Pi…