Open Source / Technology

Off-The-Shelf Hacker: Arduino vs. Raspberry Pi

13 Feb 2016 7:00am, by

There’s still much confusion about when to use an Arduino or a Raspberry Pi, especially among “casual” or prospective off-the-shelf hackers. The question popped up during my micro-controller trend talk a couple of years back at OSCON. Last month, during my Future of Educational Technology Conference presentation, covering the Raspberry Pi, an audience member asked the same exact question.

It’s understandable. Teachers, software developers, managers and lay-persons, eager to learn this awesomely fascinating physical computing technology, likely don’t have piles of boards laying around or the time required to extensively compare and contrast the two. It’s easy to lump the Arduino, Raspberry Pi and other small-footprint computing devices together concluding that they are all interchangeable. They’re micro-controllers, after all.

With all that in mind, today we’ll focus on outcome differences, rather than rehashing the typical super-nifty, geek-impressing and eyeball-glazing hardware specs.

Single Minded Or A Complex Personality

In the world of microcontrollers, the Arduino has a one-track mind. It typically reads some inputs, maybe does a few computations, then sets some outputs. It’s capable of cycling through that process extremely quickly, down into the milliseconds. It doesn’t worry about network traffic or if it has to backup files at a certain time of day. Nor does it have the attention span or memory to monitor hundreds of different processes and tasks. Programs are small and single purpose.

An example might be watching the rotational speed of a motor shaft and then adjusting the power to keep the motor spinning at a constant speed, regardless of load. The Arduino doesn’t have an operating system like Windows, iOS, or GNU+Linux, either. Programs are called firmware because they are developed on another machine, like a GNU+Linux notebook then uploaded or “burned” into the Arduino’s EEPROM (electrically erasable programmable read only memory). A good way to think of it is that the programs are uploaded “firmly” into the Arduino’s limited memory and that’s all it does. As soon as power is applied, the Arduino runs that program.

Yup…the Arduino just reads some inputs, perhaps does a few computations then sets some outputs, very, very quickly.

By contrast, the Raspberry Pi is social, can handle lots of things simultaneously and never forgets an appointment.

First off, the Raspberry Pi does have an operating system, it’s called GNU+Linux. It’s similar to Windows or the Mac’s iOS. It boots up, puts the hardware into a stable state, starts the networking and user interfaces then sits there and does a whole bunch of other things, in the background. You don’t need another machine to program a Pi. Hook the device up to an HDMI big screen, plug in a keyboard and mouse and you’re good to go with a beautiful color desktop containing all your favorite applications, patiently waiting for your next beck and call.

Connecting to networks, is native to the Raspberry Pi. The standard GNU+Linux installation on the Pi has a complete network stack baked into the system. Not only can you interact with servers, access points, and the cloud, turning on encryption, erecting a firewall or logging in remotely from another machine are absolutely no sweat for a Pi.

Want to program the Pi to read some inputs, perhaps do a few calculations, then set some outputs?

Ha! There’re a dozen different languages and frameworks you can use for that job. Load the Arduino IDE and you can even program an Arduino, using the Pi itself. How’s that for tricky?

Back to the input and outputs, all this user interface and multi-tasking goodness requires a few, shall we say, compromises?

It’s impossible to guarantee that reading your inputs or setting your outputs will happen exactly when you want them to happen. While the Pi has quad-core processing horsepower and 1 GB of memory (in the Pi 2), it’s general purpose input/output pin control attention is shared with all the other things it has going on at the same time.

Tracking a fast-turning motor shaft will be a big challenge for a run-of-the-mill Pi and its program. It’s much better to leave that task to a singularly focused Arduino and occasionally send the Pi a message, which it can display on a desktop program, saying that the shaft is, in fact, turning, with an average speed of X. Or, conversely, change a knob on a Pi’s desktop interface that sends a message to the Arduino to increase the speed of the motor by 100 RPMs. You get the idea.

Don’t get me wrong, the Pi is definitely reliable and very capable of controlling it’s general purpose output pins, just not in an extremely time-constrained fashion.

A great example is the pulsing blue “ozone tube” on my most-advanced version 4.0 Steampunk Name Badge. I use a Python program to change the intensity of the blue LED, in the tube, by varying the pulse width of the signal to the LED’s connected output pin. As the program makes the pulse width bigger, the LED gets brighter.

 

badge-640x360

As the pulse width shrinks so does the LED’s intensity. This gives a somewhat spooky orbing character to the “ozone tube” as the program cycles up and down. Occasional demands from other Pi programs cause lags in the orderly change of the pulse width and add an unpredictable flash or drop out of the tube for a cool random kind of effect. In other words, don’t count on the timing of general purpose input/output pin events to be super exact.

Oh, and at the same time, that Pi is running an MP4 promo video on the badge’s tiny color LCD screen and letting me connect remotely from my Galaxy cell phone over WiFi, on battery power yet.

Paradoxically, in spite of lack of millisecond precision on its pins, the Pi has real-time clock capabilities, making kicking off a job in two minutes or two years, a no brainer. Set when you want a program to execute, in the cron scheduler and you can bet it will happen when the time comes. Well within a minute or two. It certainly won’t be off by an hour or a day or a month. Making a list to executing 100 jobs is also effortless because the Pi can write and save files to its file system. While you can definitely use a real-time clock module to set an output on an Arduino, asking it to track 100 seperate jobs sometime in the future, like sending a text or backing up a bunch of files, doesn’t really make much sense.

Digital Or Analog

The other big difference between the Arduino and Pi are how it’s general purpose input and outputs work.

I’ve already mentioned the pulse width capability of the pins on the Pi. The Arduino can also do pulse width outputs.

The Arduino has the interesting capability to read a voltage on one of its pins and map that voltage to a 10-bit whole number corresponding to the voltage. This is called analog-to-digital conversion or ADC. So, 0 volts will be 0, 2.5 volts will be 512 and 5.0 volts will be 1024. You use those values in your program. Not only can the Arduino read the voltage, it does so quickly enough to actually track things like waveforms, in real-time. You can do calculations and set outputs that correspond to certain values appearing on an analog input. Want to mod an analog audio signal, on the fly, based on values the pin reads. An ADC analog pin on the Arduino can do that. And, to make it even better, there are at least six channels of these ADC bad-boys on your common every day Arduino.

Sad to say, the Pi doesn’t have any analog inputs at all. They are all purely digital. In order to read analog values with a Pi, you’ll have to use an external ADC board that sends the values to the general purpose input/output pins. Reading analog inputs just isn’t a high priority for a Pi.

Don’t get discouraged about analog with the Pi. There are 17 general purpose input/output pins available on the Pi 2. And, don’t forget, when the Pi is hooked up to the Internet, you can control those pins from just about anywhere. Take that, Arduino.

Pick One

Choosing between an Arduino or a Raspberry Pi simply comes down to your requirements.

If you want simple, insanely fast input/output pin control and the ability to read analog voltages, with no fluff, use an Arduino.

If you want a tiny nano-GNU+Linux machine, that can do a bunch of computing jobs at once, has a familiar desktop just like your notebook and can control a dozen or so digital input/output pins at moderate speeds, even remotely over the network, then go to a Raspberry Pi.

Of course, my official “Dr. Torq” recommendation is to buy several sets of these off-the-shelf technological wonders and go crazy with your projects.

A newsletter digest of the week’s most important stories & analyses.