|
|
Log in / Subscribe / Register

Arduino: open source for microcontroller boards

September 12, 2023

This article was contributed by Koen Vervloesem

Arduino has emerged as one of the prime success stories of the open-hardware movement. In recent years, the company has shifted its focus toward Internet of Things (IoT) applications. As part of this transformation, it has completely redesigned its open-source integrated development environment (IDE), adding a more professional feature set for its hobbyist target audience. If you have experimented with Arduino in the past, but have lost track of its progress, now might be a good time to give it another try.

The Arduino project originated in 2005 at the Interaction Design Institute Ivrea in Italy as an educational tool for teaching students how to create and program interactive devices with sensors and actuators. Gradually, the project outgrew its academic origins and became the go-to platform for hobbyists interested in programming microcontroller boards. After a trademark dispute between the project's founders that lingered for years, the Arduino ecosystem now seems to have found a new life.

What we commonly refer to as Arduino is actually a combination of several components. First, there's the Arduino hardware, which consists of microcontroller boards with open-hardware designs. Then, there's the open-source software: an IDE that supports C++ programming using some libraries provided with the tool, coupled with an Arduino "core" that supports a specific board family. In addition, users can extend the basic functionality with third-party Arduino libraries. Finally, there's the Arduino company, which oversees the development and possesses the Arduino trademark. This article takes a look at the latest developments in each of these areas.

Open hardware

Over the years, the Arduino company has released more than a hundred hardware products, including microcontroller boards, shields (expansion boards), kits, and accessories. The hardware schematics are distributed under the Creative Commons Attribution Share-Alike 2.5 license and published on each product's web page. This means that anyone is allowed to copy and further develop the hardware design in their own project. However, they can't put the Arduino brand name and logo on their products. As a result, several Arduino-compatible products are available on the market using names ending in -duino, like Seeed Studio's Seeeduino product line of microcontroller boards.

The original Arduino boards, such as the Arduino UNO, were based on Atmel's 8-bit AVR microcontroller family. Later, more powerful, 32-bit, Atmel SAM-based boards were introduced. An example is the Arduino Due, which has gained popularity in robotics projects. Initially, Arduino boards had no network connectivity. However, due to increasing competition from Espressif's ESP8266 and ESP32 WiFi chips, Arduino started incorporating its own boards equipped with radio modules. The MKR family is based on a Cortex-M0 32-bit SAMD21 processor and comes with WiFi, Bluetooth, LoRa, Sigfox, or NB-IoT communication options. The most recent addition is the Arduino Nano ESP32, which incorporates Espressif's ESP32-S3 WiFi and Bluetooth chip.

Arduino IDE

[Arduino IDE 2]

The Arduino IDE has played a significant role in Arduino's success. While professional developers may dismiss the official development environment for its limited capabilities, it's perfectly suited for hobbyist developers. Because it doesn't come with too many bells and whistles, it's quite easy to learn.

However, the Arduino IDE has started showing its age. It was a cross-platform application written in the Java programming language, with a somewhat inflexible user interface, and it appeared that little was done to improve it. In 2019, the Arduino developers started to work on a new IDE, which was released as Arduino IDE 2.0 in September 2022. The previous version, the Arduino IDE 1.8 series, is now called the "Legacy IDE".

Arduino IDE 2.0 represents a complete overhaul of the development environment. The application's frontend is built on the Eclipse Theia framework, written in TypeScript, and uses Electron, which is a technology for building desktop applications using JavaScript, HTML, and CSS. The result is a modern, fully-featured, AGPL-3.0-licensed development environment with a flexible, responsive user interface.

For example, the new IDE allows developers to view both the serial monitor and the serial plotter data-tracking tool at the same time, while the previous version forced a choice between viewing text or a graph. The editor now includes autocompletion for variables and functions, as well as navigation shortcuts to jump to the place where a variable or function is defined. The new IDE also incorporates a debugger for stepping through a program's execution, at least on SAMD boards. While these may seem like basic features for a development environment, they were absent in the legacy IDE.

Subsequently, Arduino IDE 2.1 introduced the possibility of backing up Arduino projects to the cloud. And, more recently, Arduino IDE 2.2 added support for IDE extensions. For example, users can now install the ESP Exception Decoder, which provides human-readable stack traces and backtraces for ESP8266 and ESP32 chips within the Arduino IDE.

Anatomy of an Arduino sketch

In the Arduino ecosystem, programs are referred to as "sketches", each saved as a file with the .ino extension. An Arduino sketch always has two functions: setup() and loop(). Here is a typical example that blinks the built-in LED of a board:

    void setup() {
      pinMode(LED_BUILTIN, OUTPUT); 
    }

    void loop() {
      digitalWrite(LED_BUILTIN, HIGH);
      delay(1000);
      digitalWrite(LED_BUILTIN, LOW);
      delay(1000);
    }

The setup() function initializes variables, sets pin modes, and performs any other necessary code that should run once after the board powers up or resets. It is the initial entry point; in this example, the LED_BUILTIN pin is configured as a digital output.

Once the setup() function completes, the loop() function is executed repeatedly until the board is powered off or reset. This is comparable to the contents of an infinite while(1) loop that is often used in the main() function of a program running on a microcontroller. In this example, the pin of the built-in LED is set to HIGH to turn on the LED, followed by a delay of 1000 milliseconds. The pin is then set to LOW to turn off the LED and then it delays again. Since the loop() function is called over and over again, this simple program causes the LED to blink.

Arduino code is written in C++, but with some library functions, such as pinMode(), digitalWrite(), and delay() in the above example. Most boards also define the LED_BUILTIN macro as the pin number to which an on-board LED is connected.

The predefined functions offered by Arduino are not particularly innovative. However, Arduino provides an abstraction layer this way that ensures the above code works on all supported microcontroller boards, regardless of the underlying architecture. And that's the big advantage of using Arduino code. Once you've learned Arduino on an Arduino UNO, you can reuse much of your knowledge on an ESP32 development board or a Raspberry Pi Pico. In contrast, if you were to use a board's native SDK or I/O registers, your LED blinking code would differ significantly among different boards, as can be observed in example C code for the Raspberry Pi Pico and for an Atmel AVR.

Under the hood, Arduino's abstraction layer is implemented by libraries that provide the same software API for different boards. Such an implementation for a specific group of chips is called an Arduino core. For example, there's a core for the traditional AVR-based Arduino boards and for the SAMD21-based Arduino boards. These cores can be installed from the Arduino IDE. Furthermore, third-party cores allow Arduino code to run on boards that are not developed by the Arduino company. Espressif, for example, maintains Arduino cores for its ESP32 and ESP8266 chips. Looking at the main.cpp file in such a core provides insight into what occurs behind the scenes of the main() function that calls the setup() and loop() functions of an Arduino sketch. Many Arduino cores are LGPL-2.1-licensed, although the AVR core has some missing license information.

From the command line

Another recent development is the introduction of Arduino CLI, a command-line interface for various Arduino-related tasks. Although its API is officially considered unstable until a 1.0 release, it's already at the heart of the Arduino IDE. The command-line interface is used by the IDE as a backend for detecting boards, building sketches, uploading firmware to the boards, installing cores and libraries, and more.

Arduino CLI is developed in the Go programming language and is released under the GPLv3 license. Anyone can use the arduino-cli command from the shell to perform all of the non-editing tasks available in the IDE.

An important advantage of this command-line approach is that this makes it possible to automatically check whether an Arduino sketch builds correctly. I used the Arduino CLI this way in the GitHub Actions workflow in the repository of my book about developing Bluetooth Low Energy applications. With this setup, every time I update an Arduino sketch in the repository, arduino-cli automatically installs the necessary core and libraries and builds the sketch.

Myriads of applications

There are thousands of libraries that can be used to extend the Arduino environment. A tutorial about writing an Arduino library is available; a library can be as simple as a header and code file implementing a C++ class. There's also a style guide to ensure usability of your library for beginners. For example, the style guide discourages the use of pointers in an API, since they can be daunting for novice users. To make a library installable from the Library Manager in the Arduino IDE, the repository needs some metadata that follows the library specification.

As a result of this beginner-friendliness, Arduino's abstraction layer, the vast amount of libraries and the extensive documentation, the Arduino ecosystem has a diverse set of projects. From robotics, home-automation systems, and wireless sensor receivers to model railway command stations and CNC routers, Arduino offers a lot of versatility.

The Arduino company

When evaluating the sustainability of any open-source ecosystem, it's crucial to consider its development model. In the case of Arduino, the company seems to have found a way to fund the open-source development of its tools and hardware by offering additional services.

The sales of official Arduino products in the Arduino Store and through authorized distributors have historically contributed to the project's development. Due to the open-source hardware designs, Arduino clones can be found at lower prices, as any manufacturer can produce them (without using the Arduino name and logo). However, purchasing an official Arduino board ensures support for further development of the Arduino ecosystem.

Over time, the company broadened its focus. Although Arduino initially targeted students, for a long time it was really focused on "makers" working at the intersection of electronics, design, and programming. The Education sector steadily gained focus, though, resulting in the creation of hardware kits and educational content for middle schools, high schools, and universities. Moreover, the company introduced a Pro line, offering high-performance microcontroller boards for industrial control, robotics, and on-device artificial intelligence. Arduino also offers a dual licensing program to include its hardware and software in commercial products. Additionally, it offers the Arduino Cloud, a web-based platform with a web editor and dashboard.

There are a few problems in and around the Arduino ecosystem, however. Because of its use of an abstraction layer, the resulting firmware running on a board isn't as efficient as possible. While this isn't a problem for many hobbyist projects, this could lead to problems for applications that need the highest performance or precise timings for communication with other chips. Another issue is Arduino's focus on non-professional developers and non-experts in electronics. As a result, a lot of Arduino sketches, libraries, and suggestions in forums and elsewhere online vary greatly in their quality. In addition, the company's increasing focus on its cloud services is something to keep an eye on; the revenue may be needed to keep developing the Arduino ecosystem, which is fine as long as using those services remains voluntary.

Conclusion

Arduino has undoubtedly found its sweet spot in the space of embedded development for makers and in education. It has lower hardware requirements and stays "closer to the hardware" than MicroPython, but some smart API decisions (like discouraging pointers) make its use of C++ quite user-friendly. It doesn't offer a full-fledged real-time operating system such as Zephyr, yet it manages to offer a basic hardware abstraction layer for various architectures. As for the new Arduino IDE 2 series, it represents a significant improvement over the legacy IDE, without descending into the complexity of Visual Studio Code with PlatformIO, which is a commonly touted combination for embedded development. Whether you're just starting out with electronics or are ready to tap into a large library ecosystem to build and program some specialized hardware, Arduino has much to offer.


Index entries for this article
GuestArticlesVervloesem, Koen


to post comments

Arduino: open source for microcontroller boards

Posted Sep 12, 2023 22:17 UTC (Tue) by vjanelle (subscriber, #44943) [Link] (2 responses)

Isn't there some conflict recently with some of their newer boards that they are unwilling to release the firmware sources for without an NDA?

Arduino: open source for microcontroller boards

Posted Sep 14, 2023 15:29 UTC (Thu) by anarcat (subscriber, #66354) [Link] (1 responses)

Yeah, it's really weird seeing this article pop up on LWN right now, right in the middle of a controversial time in open hardware communities. Adafruit wrote an interesting blog post summarizing the current situation. Arduino, in there, doesn't fare very well:
I’ve contacted Arduino on behalf of some of the lead developers of Arduino hardware and open-source libraries and asked if they would consider Open-source certifying any any of the Arduino boards (non-“Pro” boards), Arduino declined.
So to end the lead with:
now might be a good time to give it another try
and totally missing that current controversy in an Arduino is kind of missing a bit thing here... If anything, I would really like LWN to cover what the alternatives to arduino are right now...

Arduino software vs Arduino hardware

Posted Sep 16, 2023 10:35 UTC (Sat) by koenvervloesem (subscriber, #56573) [Link]

Thanks for bringing up that Adafruit blog post. I didn't remember to include it while writing my article, as I focused it on recent developments in Arduino's software ecosystem, such as the Arduino IDE 2 and the Arduino CLI. Hence the "give it another try".

The current state of open hardware is an important topic on its own, which I'll cover in a next article, including alternatives to Arduino hardware. Note that many of the alternatives, such as Adafruit's boards, are often still used with the Arduino software.

Arduino: open source for microcontroller boards

Posted Sep 13, 2023 5:36 UTC (Wed) by elboulangero (subscriber, #81193) [Link]

They also just raised capital, 32 millions in 2022, and 22 millions just now: https://blog.arduino.cc/2023/09/06/what-will-we-do-with-a...

Arduino: open source for microcontroller boards

Posted Sep 13, 2023 8:34 UTC (Wed) by PengZheng (subscriber, #108006) [Link]

> To make a library installable from the Library Manager in the Arduino IDE, the repository needs some metadata that follows the library specification.

Why not use Conan package manager directly? It support private deployment and cross-compilation pretty well.

Arduino: open source for microcontroller boards

Posted Sep 16, 2023 4:21 UTC (Sat) by calumapplepie (guest, #143655) [Link]

Do the Pi Pico next, that thing is pretty d**n shiny for all that it's dirt cheap.


Copyright © 2023, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds