Home

Awesome

AUniter Command Line Tools and Continuous Integration for Arduino

These are command line tools to easily build and upload multiple Arduino programs for multiple microcontroller boards, validate unit tests written in AUnit, and integrate with a locally hosted Jenkins continuous integration (CI) system. A single command can compile and upload multiple programs for multiple boards. This automation capability is fully utilized when running unit tests across multiple target boards. A configuration file in INI file format allows users to define short board aliases for the fully qualified board names (fqbn) which can be awkwardly long for some boards (e.g. ESP8266 or ESP32). Users can define target Environments in the configuration file corresponding to specific hardware configurations described by its board alias and other parameters such as optional C preprocessor macros.

This package provides command line scripting abilities without converting to a vastly different build environment such as PlatformIO. The underlying tool is a shell wrapper around the command line abilities built right into the Arduino IDE itself or the Arduino CLI. Therefore, the AUniter package is able to support all boards, libraries, and build configurations which are supported by the Arduino IDE. There is no duplicate installs of boards and libraries because the build and upload steps go through the Arduino IDE binary in command line mode, or the Arduino CLI command line tool.

There are 3 components to the AUniter package, of which 2 of them are obsolete, so the only remaining tool is the auniter.sh script:

  1. tools/auniter.sh
    • compile, upload, and monitor Arduino programs using a command line interface.
    • can automatically run and verify unit tests written using the AUnit testing framework
  2. Jenkins Integration (Obsolete)
    • provides Continuous Integration (CI) of unit tests upon changes to the source code repository.
    • depends on the auniter.sh described above.
    • As of v1.8 or so, I no longer use this integration because:
      1. the Arduino IDE is simply too slow, with some of my projects taking 1-2 hours to run through all the test suites,
      2. The Arduino-CLI tool cannot replace the Arduino IDE because its broken --build-properties flag, and,
      3. The Jenkins service is too brittle and cumbersome to maintain.
    • I recommend using the EpoxyDuino project to run unit tests on Linux, MacOS, or FreeBSD desktop machines.
  3. Badge Service (Obsolete)
    • runs on Google Cloud Functions
    • allows the locally hosted Jenkins system to update the status of the build, so that an indicator badge can be displayed on a source control repository like GitHub.
    • depends on the Jenkins Integration described above
    • As of v1.8 or so, I no longer use this service, because the Arduino IDE is too slow to handle the number of INO files that I needed to compile in my Continuous Integration pipeline. I may revisit this when Arduino-CLI fixes the broken parser of its --build-properties flag.

The auniter.sh script uses the command line mode of the Arduino IDE binary, or the Arduino CLI command line tool. Here are some tasks that you can perform on the command line using the auniter.sh script (the following examples use the auniter alias for auniter.sh for conciseness):

The auniter.sh script uses an INI file configuration file normally located at $HOME/.auniter.ini. It contains various user-defined configurations and aliases which look like this:

[auniter]
  monitor = picocom -b $baud --omap crlf --imap lfcrlf --echo $port

[boards]
  uno = arduino:avr:uno
  nano = arduino:avr:nano:cpu=atmega328old
  leonardo = arduino:avr:leonardo
  promicro16 = SparkFun:avr:promicro:cpu=16MHzatmega32U4
  mega = arduino:avr:mega:cpu=atmega2560
  nodemcuv2 = esp8266:esp8266:nodemcuv2:CpuFrequency=80,FlashSize=4M1M,LwIPVariant=v2mss536,Debug=Disabled,DebugLevel=None____,FlashErase=none,UploadSpeed=921600
  esp32 = esp32:esp32:esp32:PartitionScheme=default,FlashMode=qio,FlashFreq=80,FlashSize=4M,UploadSpeed=921600,DebugLevel=none

[env:uno]
  board = uno
  preprocessor = -DAUNITER_UNO

[env:nano]
  board = nano
  preprocessor = -DAUNITER_NANO -DAUNITER_LEFT_BUTTON=2 -DAUNITER_RIGHT_BUTTON=3

[env:micro]
  board = promicro16
  locking = false
  preprocessor = -DAUNITER_MICRO -DAUNITER_BUTTON=3

See sample.auniter.ini for a bigger example.

Version: 1.10.0 (2023-06-18)

Changelog: CHANGELOG.md

Installation

  1. See AUniter Tools to install the auniter.sh command line tools.
  2. See AUniter Jenkins Integration to integrate with Jenkins. (Obsolete)
  3. See AUniter Badge Service to display the build status in the source repository. (Obsolete)

System Requirements

Windows is definitely not supported because the scripts require the bash shell. I am not familiar with Windows Subsystem for Linux so I do not know if it would work on that.

Limitations

Alternatives Considered

There are a number of other command line solutions for building and running Arduino programs. None of them had all the features that I wanted:

However, I was inspired by various features of all of the following alternatives.

Arduino IDE Command Line

The Arduino IDE binary. supports a command line mode where the application runs in a headless mode and run commands given as flags. The auniter.sh script is essentially a giant wrapper around the Arduino IDE binary. The motiviation for writing the wrapper was the following:

AMake

The amake tool is very similar to auniter.sh. It is a shell script that calls out to the Arduino commandline.

There are a few features of amake that I found problemmatic for my purposes.

Arduino-CLI

The Arduino CLI is currently in alpha stage. I did not learn about it until I had built the AUniter tools. It is a Go Lang program which interacts relatively nicely with the Arduino IDE.

The --cli flag in auniter.sh will cause auniter.sh to use the Arduino CLI instead of the Arduino IDE instead. Some ugly hacks were required to support the -D macro=value flag because the Arduino CLI does not support this feature directly.

Arduino-Makefile

The Arduino-Makefile package provides a way to create traditional Makefiles and use the traditional make command line program to compile an Arduino sketch. On Ubuntu Linux, this package can be installed using the normal apt program as:

$ sudo apt install arduino-mk

It installs a dependency called arduino-core. Unfortunately, the version on Ubuntu is stuck at Arduino version 1.0.5 and the process for upgrading been stuck for years.

It is possible to configure Arduino-Makefile to use the latest Arduino IDE (but I have not looked into how easy or hard that would be).

The problem with Arduino-Makefile is that it seems to allow only a single board type target in the Makefile. Changing the target board would mean editting the Makefile. Since I wanted to be able to easily compile, upload and validate against multiple boards, the Makefile solution did not seem to be flexible enough.

The second problem with Arduino-Makefile is that I prefer to avoid Makefiles. I have used them in the past and find them difficult to debug and maintain. The appeal of the Arduino development is that it is simple to use, with few or no extraneous configuration files. I wanted to preserve that feature as much as possible.

PlatformIO

PlatformIO is a comprehensive platform for IoT development. It is split into several components. The PlatformIO IDE is based on the Atom editor. The PlatformIO Core is a set of command line tools (written in Python mostly) that build, compile, and upload the code.

A given Arduino project is defined by the platformio.ini file, which is the equilvalent to the Makefile. Unlike Arduino-Makefile, multiple embedded boards (e.g. Nano, ESP8266, ESP32) can be defined in a single platformio.ini file. Like a Makefile, the platformio.ini file allows finer-grained control of the various build options, as well as better control over the dependencies.

I think it would be feasible to integrate PlatformIO tools into a locally running Jenkins service like I did with auniter.sh. However, I think it has some disadvantages.

The platformio.ini files provide better isolation between *.ino files, but the overhead seem too much for me.

Arduino Builder

The Arduino Builde seems to be a collection of Go-lang programs that provide commandline interface for compiling Arduino sketches. However, I have not been able to find any documentation that describes how to actually to use these programs.

License

MIT License

Feedback and Support

If you have any questions, comments, or feature requests for this library, please use the GitHub Discussions for this project. If you have a bug report, please file a ticket in GitHub Issues. Feature requests should go into Discussions first because they often have alternative solutions which are useful to remain visible, instead of disappearing from the default view of the Issue tracker after the ticket is closed.

Please refrain from emailing me directly unless the content is sensitive. The problem with email is that I cannot reference the email conversation when other people ask similar questions later.

Authors