Embedded systems development: Raspberry Pi or Arduino
| Joost Schalken-Pinkster |
During our reviews of IT projects and startups, we see more and more teams that create ’embedded software’: software intended not to run inside some other device. The development of such systems has become much easier since the introduction of two standard platforms: Arduino and Raspberry Pi. These two platforms are quite different so it is important to choose the right one for each project. We discuss the pros and cons of both options.
Ten years ago, the development of embedded systems was the working field of highly specialized software and electrical engineers. You had to know the ins and outs of a specific microcontroller and its development environment before even the most basic system could be made. To obtain this knowledge you needed to read complex datasheets written in arcane language for each different chip. Microcontrollers were programmed part in assembly and part in C or C++, both low-level languages. Compared to many web development languages, these are difficult to learn and more error-prone. Also the development of the microcontroller program was not done on the same machine as on which the software would run, so you need to cross-compile on one computer for another computer. Cross-compiling makes the debugging of a program much more complex than if one is developing on a machine itself.
This all changed in 2005 with the development of the Arduino (read The untold history of Arduino for more info). The Arduino was created by the Interaction Design Institute Ivrea and has made development of embedded systems much easier: The Arduino is not just a microcontroller chip, but a directly usable board with standard connectors. Through the use of the Arduino IDE (first called the Wiring library), microcontrollers got a an API that could be easily accessed through C and C++, so programmers no longer needed to understand the internal registers and peripherals of each individual microcontroller. Also the need for assembly language programming was greatly decreased. Still the programming of microcontrollers necessitated the use of C or C++ and one still had to cross-compile a program to make it work.
Further changes occurred in 2012 when the Raspberry Pi Foundation introduced the Raspberry Pi. The Raspberry Pi contains a System-on-a-Chip (or SoC) that is as powerful as a regular computer and that can run a full operating system like Linux. The breakthrough of affordable SoCs meant developers no longer had to write their programs in the C or C++ programming language, but instead could use high-level programming languages like Python to create an embedded system. It also became possible to develop the applications on the machine itself, making the challenge to develop embedded systems much easier.
All this means that embedded development has become easier. There are now two ways of developing embedded systems: the old way based on microcontrollers (Arduino or others), and the new way using a Raspberry Pi (or other system on a chip). We compare the two ways side by side so that you can choose the right approach for your project.
The advantages of Systems-on-a-Chip over microcontrollers
Systems-on-a-Chip (SoC)-based boards are much easier to program than microcontroller-based boards (even if they are complemented by a productivity-enhancing API like the Arduino). It is estimated that modern, high-level scripting programming languages, such as Python, make programmers at least twice as productive as more low-level scripting programming languages, such as C and C++ (see papers by Luz Prechteld and Connelly Barnes).Typical memory consumption of a program implemented in a scripting language is also about twice that of a C or C++ program according to (according to Pechteld in 2000). Of course with the availability of cheaper and more powerful computers this argument is starting to lose its point. This is why voices in the embedded world are starting to question the dominance of C and C++ and why Python is sometimes mentioned as a better alternative (Max Maxfield).
In addition to programming languages with higher level features, there are more benefits to full SoCs. Developing programs on the same computer as on which the program will be run (the Raspberry Pi-development model) is faster compared to cross-compilation development with a different development computer and host-system (the Arduino-development model).
Also, with embedded systems that should be connected to the internet, SoCs provide the advantage of being able to use a full operating system (like Linux) that has a fully-working networking stack that facilitates Internet-of-Things development. Also the presence of an operating system makes it easier to update software on the device, so that errors can be corrected (including security issues) and that functionality can be upgraded over time.
The advantages of microcontrollers
If one looks at the above advantages one would wonder why anyone would still develop systems on a microcontroller. The reason for microcontrollers still have a place is that they provide lower production cost as scale, consume less power and are able to meet real-time and safety requirements.
For products that are sensitive to costs of the internal components (as is practically every product that retails below $250), a microcontroller offers a lower-priced alternative. Making accurate price comparisons in the processor-business is difficult, since information about bulk pricing is not publicly available. Still it is generally accepted that SoC’s cost a factor of 4 to 5 more than typical microcontrollers. For example an Arduino Pro Mini-clone could be bought in 2014 at a price of $2, whereas the price of a Raspberry Pi Zero W in 2017 is $10.
Power consumption advantage
Products that need to be powered by batteries are sensitive to energy consumption. This is also an area where microcontrollers like the Arduino outperform Systems-on-a-Chip like the Raspberry Pi). The Raspberry Pi Zero W requires, according to measurements by Alex Eames, a current of 120mA when it is idle and a current of 230mA when it is under load. The Arduino Pro Mini achieves an idle consumption of 3mA out of the box and a consumption of 20mA under load. This can be improved with some minor modifications to <1mA consumption in idle mode and 13mA under load according to this IoT blog. This makes the microcontroller-based solution a factor of 120 times more efficient when idle and a factor of 19 times more efficient. The latter comparison of current under load not being really fair, since the Raspberry Pi brings much more processing power to the table. Still if your system is idle 90% of the time (as most systems are), the difference is significant.
There are many products that require precise timing of their actions (like audio player, measurement devices and precision controllers). With a System on a Chip running a normal operating system, it is difficult to guarantee microsecond timing. Influences of the scheduler and background tasks will sometimes make a system-on-a-chip-based system respond a few 100 microseconds slower. That is why even the developers GPIO, one of the most-used I/O libraries for the Raspberry Pi, note on their download page that “this module is unsuitable for real-time or timing critical applications” and recommend to use an Arduino.
Products that are to be used in safety-critical situations also still often depend on a microcontroller instead of on a system-on-a-chip. Products requiring safety-critical certification (think cars, trains, airplanes) should have the smallest possible source code and be as stable as possible. In typical software development projects, between 1 and 25 errors are introduced per 1.000 lines of code (McConnel’s Code complete, pp. 521), projects with tiny code volume are less likely to be error-prone (and also cheaper to fully test and certify). With the Linux system consisting well over 15 million lines of code, with a core of 350.000 line of code, it is no surprise that Linux is not yet certified for use in safety-critical systems. Micro-controller based systems, can rely on real-time operating systems like FreeRTOS, that have been certified for use in safety-critical systems and can therefore be more easily certified for use in safety-critical situations.
With ICT Institute we review or visit more than 20 embedded software projects per year. They range from small (student projects in applied universities where we teach systems engineering) and serious Internet of Things companies where we conduct IT due diligence reviews. We see many success stories, often based the Arduino platform and the Raspberry Pi platform. Choosing a standard platform makes it easier to get started and there is no reason for not choosing one of these open platforms.
One important insight from our work with more mature companies is that choosing the right platform is not a one-off decision. You can start building a first prototype for many products using hardware you have at hand. Build, launch and test fast as they would say in agile or Lean startup. As the project progresses you will learn more about the actual non-functional requirements of your product. With this additional knowledge you can make better decisions for your next series of devices: there are many microcontrollers and SoC’s with widely different specs to choose from. At a certain point you might have to switch platform: upgrading to Raspberry Pi if you need to do more computations on board, downgrade to Arduino if you can simplify your requirements and/or change your architecture by bringing more or fewer functions from your device to the cloud.
If you need to develop a prototype of a one-of system that is not battery, time or safety-critical, it is a good engineering decision to rely on a System-on-a-Chip like the Raspberry Pi. You will benefit from higher programmer productivity and the ease of existing network stacks in your operating system. If you on the other hand need to develop a system that is battery, time or safety-critical the solution could still lay in using a microcontroller like the Arduino.
Image Arduino: wikimedia / R. Hampi.
Image PCB: FlickR / Adam Greig.
Dr. Joost Schalken-Pinkster has obtained a Ph.D. in software engineering in 2007. Since then he has worked continuously in IT as architect management consultant and lecturer. Besides working at ICT Institute, Joost is lecturer at Utrecht Applied University where he focuses on code construction, software design and software architecture.