Arduino enjoys a very high reputation in the IoT maker community for its very good and easy to use combination of developer boards and the appropriate tools. As a developer, you don’t have to look at any details about the used electronics. Both the framework and the sample code can be used directly with the tools like the Arduino IDE. But what happens “behind the scenes” in the tool chain?
The embedded hardware is almost always accessible via so-called developer boards. These consist of a microcontroller (MCU) with integrated or additional external memory on the board, input/output pins for the connection of sensors or actuators, and an interface for connection to and communication with the PC – usually USB. This supplies the board directly with power (5V via USB), and – depending on the board – reduces it to a lower voltage, e.g. 3.3V. The microcontroller can be addressed via a serial interface because of an interface chip, e.g. from FTDI or SiliconLabs.
Where are the major differences? On the one hand, the MCUs used can have a big impact. They range from 8-bit MCUs such as the Arduino Uno to 16-bit MCUs such as an MSP430 from Texas Instruments, to 32-bit MCUs such as the ARM Cortex M series. This is coupled with a clock frequency that can range from the single-digit MHz range up to several hundred MHz. An increase in speed and computing power of the MCU allows faster or more powerful applications (e.g. modern encryption), but also requires more power.
In order to be able to program for these MCUs or boards, firmware (i.e. software that is embedded in the chip) is required. At this point, there are basically a lot of choices for developers. While “small” MCUs are programmed in C or C++, additional script languages are available for the more powerful 32-bit variants, e.g. Embedded Lua or subsets of Python (MicroPython) and Javascript (Espruino).
Shopping for embedded devices…
How can you find out which combination of hardware, framework and software makes sense for your own introduction to the topic? This question can be answered from several perspectives:
- If you are interested in development in a certain programming language – and especially scripting languages – you need a board with sufficient performance with a suitable firmware interpreter is available. For example, boards from PyCom are programmed in MicroPython. Practically all boards are suitable for C or C++.
- If integration into a platform is also important in addition to device development, manufacturers who serve both are more likely to be chosen. An example of this is Particle, whose boards can be remotely controlled via the cloud service of the same name.
- As soon as you have a specific application in mind that requires special sensors, actuators or even network capabilities, a board that can technically meet these requirements and for which suitable libraries are available is helpful. Examples of network capabilities include ESP8266/ESP32 and the MKR boards from Arduino, the first integrating WiFi and BLE, the latter also integrating SigFox or GSM in addition to WiFi.
- If, in addition to prototyping, the path towards professional product development is also to be possible, the freedom of choice is somewhat limited. Aspects such as power saving and price or long-term supply capabilities are in the foreground here. In most cases C/C++ is programmed here with manufacturer-adapted embedded operating systems.
Toolchain
After the choice of a board or a development framework has been made, the question arises as to how the whole thing is specifically programmed and equipped. In the case of boards that are Arduino-compatible, the Arduino IDE is a good example. If the board is supported, it can be selected in the menu or the board administrator.
The same applies to the tool chains of other manufacturers such as Particle or ARM Mbed OS. Usually you need the following parts if you want to develop in C or C++:
- A crosscompiler capable of translating C/C++ code for the processor of the target hardware. In the open source area this is often the GCC, in a variant for the target. For example: arm-none-eabi-gcc for ARM Cortex processors/MCUs or xtensa-lx106-elf-gcc for the ESP series of Espressif.
- The compiler includes additional tools such as linkers, preprocessors, archivers and others that work together to create an executable binary for the target hardware.
- In most cases, a flashing tool is needed to get the firmware binary on the board – often via USB, in combination with a serial port, or via a programmer. Sometimes the USB interfaces of the boards allow you to access the board like a drive and copy the binary (or script for boards that support script languages) directly into a file system.
All these tools are easy to download and manually install. However, this means a lot of effort and is quite error-prone if, for example, versions of different tools do not work well together. Toolchain management solutions such as Particle or ARM Mbed Yotta master the task, but often only for your own embedded platform.
Cross-platform with PlatformIO
Learn more about IoT Conference:
PlatformIO takes a different approach. They refer to themselves as the “Open Source Ecosystem”, whose goal is to simplify IoT development. They not only want to be there for certain manufacturers, but also offer a cross-platform development environment.
At its core, PlatformIO manages the embedded toolchain you need to develop for your board. In addition to the tools listed above, this also includes the firmware frameworks and embedded operating systems with which your own code must be linked. PlatformIO is open source and is licensed under Apache 2.0.
The “core” version of the software is available as a command line application for Windows, OSX and Linux. In most cases, it is integrated into a development environment. Numerous well-known and popular IDEs are supported here. “By default” Atom or VS.Code are recommended, but JetBrains CLion, Eclipse, Qt Creator and Cloud-based IDEs such as Cloud9, CodeAnywhere or Eclipse Che are also possible. In many cases, the developer does not have to leave their beloved IDE, but can install embedded development via a plugin.
What exactly does PlatformIO consist of? The core of the software is implemented in Python and is based on the programmable build system SCons. It is capable of automatically downloading tool chains for a variety of hardware targets on demand and installing them into a private directory. The same applies to embedded frameworks that are automatically localized, downloaded and made available to the build system to match the hardware target.
If you remember your own C/C++ projects and the tedious work with makefiles, include and library paths, you can breathe a sigh of relief here. Thanks to SCons, source files are automatically found within your own project and linked to the sources of the embedded frameworks. PlatformIO also integrates library management so that external libraries (e.g. for certain sensors, displays or network protocols) can be easily found and installed.
Outlook
In the next article, we will show how to start IoT development with the help of open source tools like PlatformIO and expand from prototypes to professional targets.
IoT Conference 2020 – Program
● Deep Learning for IoT Devices
● Real Time Analytics on the Edge and in the Cloud with Azure IoT