A lot of has been written on these two popular systems. Arduino had become probably the most used makers board for electronic and robotic projects and raspberry is one of the best choices when it comes to credit card sized computers.
But what one use in his project?
Well, it depends. Arduino is a micro controller. Its SOC (System On Chip) is based on the Atmel Cotrex-M ARM processors. They have a 32 Bit CPU, a small RAM memory (32K for example) and a tiny bin of Flash for uploading your compiled code. But one of the most important things is that Arduino doesn’t run an Operating System. Actually, that’s not exactly true. It runs a RTOS (Run Time Operating System) but unlike OS’s like: Linux, Windows, Android, etc the Arduino pretty much runs your code as the main and only code in the processor which means you have full control of what the processor runs.
This is great for controlling hardware devices like motors, sensors, etc and that’s why is popular in robotic projects.
The problem with Arduino is that it has very small computation power (CPU and Memory). So you can run simple code but whenever you need something a bit heavier, even like storing one single camera photo in memory it will not be possible.
Raspberry Pi however, is much more like your PC or to be more accurate, like your smart phone. It runs a regular standard OS (Linux, or Windows) and has a Quad Core Processor similar to what you will find in phones and tablets. Although all the computation power, the Pi can’t output analog (which is required by many hardware devices), and the Linux Operating System it runs is not real time meaning it can schedule your code, delay commands, and generally you don’t know exactly when your code is executed and therefore impossible to use with hardware that requires real time actions.
So what if you want a Robot that also controls motors and sensors but is also “smart” and can “think” by itself?
The answer is use both! Arduino and a Pi and that’s what we have done in our robot project: Robit
The connection is quite simple and can be done in different ways like SPI or USB. We chose the USB mainly since it’s out of the box on both sides (Arduino and the Pi).
So you connect the Arduino USB to the Pi with a simple USB cable. The USB I/O on the Arduino side is easy since it doesn’t care it it’s connected to a PC or PI or whatever.
On the Raspberry Pi once you identify the Arduino path (like /dev/ttyACM0) the communication is easy from a Python script using libraries like pyserial or any language that has a proper library for serial communication.
Next you develop a protocol that will be the language the two communicated with each other. This is typically done by defining commands that the Pi sends to the Arduino to tell him what to do. For example: mov1,200 will tell him to run on motor number 1 on speed 200.
Now the interesting question is what things to perform where?
So it’s obvious that analog input and output and real time stuff is done with Arduino. It’s also obvious that those high level stuff like HTTP server, video and image processing is done on the Pi. But it’s those little things in the middle that make it difficult.
Let’s say I’m moving a robot on wheels and I want him to move for 2 seconds. One way is having the Pi tell Arduino to start move, and after 2 seconds tell him to stop. The problem is that the Pi might miss a little because of the non-real time OS. So instead of 2 seconds we can get 2.01. In some cases that wouldn’t be a big deal.
Now, let’s say we have wheel encoders counting the number of wheel spins. Each full round (360) is 1200 encoder units (so it can count 1/1200 of a wheel spin!). Now if I want it to move exactly 60,000 units (so that’s 50 wheel spins) I need to turn the motor on, then read 60,000 encoder interrupts and then stop. This whole journey takes about 2 seconds. So we need to have 30,000 input commands read and processed a second. Unfortunately, that will never work. Two things will happen: First, Pi running a few lines of Python on each iteration will probably be too slow. Second, if you enter an output command in the Arduino’s main loop (on each iteration) it will slow down the Arduino and it will never be able to read those 60,000 rounds.
The solution is to create a more sophisticated command saying: “move motor 1 at speed 200 and for 60000 rounds”.
But what happens if we want to put in more logic? Like have an ultrasonic sensor prevent the robot running into walls? So we need another command saying: “move motor 1 at speed 200 and for 60000 rounds, but if you sense there is a wall stop”
Now, we want the pi to be able to stop the robot, say if the user sends a stop command via his smart phone (using HTTP over WiFi). So we need the Arduino to be able to terminate a command by a signal received from the USB.
Filed Under: Reviews