You want to create a nice robotics, electronics or domotic application and you wonder: when to use Arduino vs Raspberry Pi ?
Could your application run with an Arduino board only, or a Raspberry Pi board only? Do you need both?
In this post I’ll give you some tips on when to use each board.
Main differences between Arduino vs Raspberry Pi boards
First of all you need to understand the fundamental differences between the two boards. Even if they are similar and can be both embedded – thanks to their size, they are two completely different kinds of boards.
A Raspberry Pi board contains a microprocessor. This microprocessor has an ARM architecture and can run a complete OS (Raspbian, Ubuntu). Basically you can use the Raspberry Pi just like you would use your own computer (with some performance limits though).
You can plug a screen on the HDMI port, a keyboard and a mouse on the USB ports. One of the most well-known example of a Desktop application running on Raspberry Pi is Minecraft. You can play Minecraft quite easily with your Pi!
The Raspberry Pi also has some hardware specifics features that you don’t find in a personal computer. On the Pi you have a 40 GPIO headers. Those GPIOs allow you to read data from sensors, give commands to an actuator, or even communicate with other Raspberry Pi/Arduino boards.
An Arduino board contains a microcontroller. Depending on the Arduino type you can have a different microcontroller – same family (ATMega) for Arduino Uno, Mega and Nano. A microcontroller is very different from a microprocessor. On an Arduino microcontroller you don’t get to install an OS. All you have is a program running in a loop.
On the board you also have many hardware pins, mostly digital and analog inputs/outputs. With those pins you can do many things: read data from sensor (digital, analog, SPI, I2C, UART, …), create a PWM, control a motor with a special driver, communicate with other boards and devices, etc.
To program on Arduino you’ll need to install the Arduino IDE and upload the program to your board, from your own computer.
Let’s now try to see the major differences between Arduino vs Raspberry Pi boards, by focusing on the real use you’ll make of each.
For now, as you can see, the main difference is about the control component: microprocessor vs microcontroller. Also, you saw that both boards have similar hardware functionalities, but there are still big differences there.
When to use Arduino
There are some things that you can only do with an Arduino board.
Real time processing
The performance is different in many ways. On Raspberry Pi, you have much bigger CPU, multiple cores, and much more RAM, so basically you can run much bigger programs.
However, on Raspberry Pi, with Raspbian or Ubuntu for example, the operating system is managing the resources for you. You don’t really have control over that and if you run multiple programs at the same time, you can’t be sure that you’ll achieve real-time constraints with one specific program.
On Arduino, you have much lower CPU resources (about 100 times less than Raspberry Pi), and the memory (SRAM) is really, really small (a few KB). But!.. It doesn’t mean that the Arduino is worse than Raspberry Pi for everything. As you have only one program running in a loop (using powerful C/C++ language), in a single thread, you can easily determine how long a certain task will take, and make sure it will never take longer than what you decided.
On Raspberry Pi you can achieve real time constraints for some parts of your application though, for example using the RT-Preempt patch. But it’s definitely more complicated and less suited if you need real-time for handling hardware devices and pins.
When your application is very simple
If your application is just about reading data from a few sensors (ex: temperature, pressure, infrared), processing them, and activate some basic outputs… Well you certainly don’t need a Raspberry Pi for that.
An Arduino board will be largely enough, and the development time will be much lower. All the hardware functionalities are already integrated into the Arduino library, you can use them out of the box. For Raspberry Pi you’d need to install new libraries and the process will take longer.
You saw that both boards have similar hardware functionalities, but there are still big differences there.
There are things that you can do on an Arduino board, but it’s impossible – or not suitable – on a Raspberry Pi:
- Analog inputs: An analog input pin allows you to read data which is not only 0 or 1. For example the Arduino Uno ADC (Analog to Digital Converter) allows you to read values between 0 and 1023 (0 to 5V). This can be really useful to read a percentage value from a sensor.
- PWM: On some Arduino pins (not all), you can create and use a PWM to control a device. Very basically put, a PWM allows you to send an “analog” signal, ex on the Arduino Uno, a value between 0 and 255 (0 and 5V)
- Reading or writing very fast. Try to run a consistent hardware loop at 10kHz on a Raspberry Pi in Python (or even Cpp) to read a digital pin from the GPIO header. 10 kHz means the data should be read every 100 microseconds. Keeping this precise rate will be difficult. On Arduino though, if you make sure your only control loop takes less than 100 microseconds, you’ll have nothing to worry about!
When to use Raspberry Pi
There are also some things that you can only do with a Raspberry Pi.
When you have a complex application – on the software side.
Programming on a microprocessor (Raspberry Pi) is completely different from programming on a microcontroller (Arduino).
On Arduino you will be limited to one thread with one control loop. That’s certainly not enough if you need to create a motion planning algorithm, remotely control your robot from a keyboard, stream images from a camera, and connect your robot to a web API.
Arduino is meant for low level control, when you directly need to “talk” to the hardware. For anything more high-level and more complex, you’ll need something else – a Raspberry Pi for example!
When you want to program with “real” Cpp
The Arduino language is a subset of C/Cpp. If you want to use all the Cpp functionalities in your code (like C++14 or C++17), well that’s not possible.
Only on Raspberry Pi you can really use the full features of Cpp. Using the std library, exceptions, “new” and “delete” keywords (with smart pointers) is possible with Raspberry Pi, not with Arduino.
Also, you’ll be able to compile your Cpp files yourself and with all the flags you want.
When you want to use other languages
Here you’ll be free to do everything you want, just like on your own computer. Use different languages, language versions, frameworks, etc.
If your application requires true multithreading, only Raspberry Pi can do that. I wrote “true” multithreading because on Arduino, you can still code your program in a certain way so you can achieve something close. To know more about that, check out how to fake multithreading on Arduino.
On your Raspberry Pi, you can use any language feature (ex: std::thread in Cpp, the threading library in Python) to create any thread you want.
When you want to use ROS
Well, this website is dedicated to programming robot, so I had to add this point!
ROS, aka Robot Operating System, is a great set of tools which allows you to develop robotics projects fast. ROS on a Raspberry Pi is really a great fit because you can embed it directly in your robot.
You can easily install ROS on your Raspberry Pi. ROS needs a real operating system to work, for example Ubuntu, thus you can’t install it on Arduino.
Note that ROS is currently not made for the very low level hardware control.
When to use both Arduino and Raspberry Pi in your project
It’s not always Arduino vs Raspberry Pi. Sometimes the combination of those 2 boards is what you need.
This is the case when you have both a complex software application and real time specs, or if there are some things you can’t do on the GPIO header from the Pi.
For example, using a Raspberry Pi with ROS, and connect it to an Arduino board for direct hardware control + real-time, is a great idea! You can also use Serial communication between those 2 boards.
To conclude: make sure you first analyze what you really need in your application, before even choosing which board to use.
Don’t fall in the trap of choosing a tool by default, without knowing what you need – and don’t need – to do.
What if you’re just getting started: Arduino or Raspberry Pi?
Well, if you haven’t used any Arduino or Raspberry Pi boards before, and if you’re totally new to hardware and software, here are a few tips.
With zero experience, you might find it easier to program on an Arduino board first vs Raspberry Pi. All you have to do it install the Arduino IDE on your computer, write a basic program and upload it. For Raspberry Pi, you’ll have to flash an OS in a microSD card, install it, configure your environment, etc. And a complete Raspberry Pi setup will also be more expensive than with Arduino.
After that, well if you want to learn hardware, go with Arduino. It will be easier to create hardware application.
If you prefer to learn software, go with Raspberry Pi. Only with this board you will be able to program with Python, “real” Cpp, and other languages. You will still be able to connect a few hardware components with the GPIO header.
If you have any question related to whether you should use an Arduino or Raspberry Pi board for your project, feel free to post your question in the comment section below!