So far, AFAIK the only official ways to program Arduino boards were through the Arduino IDE program, or the cloud-based Arduino Create which works in your web browser and does not require any installation on your computer.
While graphical interfaces are nice and user-friendly, many of us are more productive while working using the command line, especially if commands can be scripted. So Arduino decided to work on a command line interface (CLI) for professional users, and have just announced a preview release.
arduino-cli works in Windows, Linux, and Mac OS, and allows you install libraries, boards, and cores (e.g. esp32 Arduino core), compile the code, and upload the binary to the target board.
If you want to get started quickly, you can download the binary “alpha” releases in the announcement board, but instead I opted to build the client myself as explained on Github. Everything below is done in Ubuntu 18.04.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
sudo snap install go --classic go get -u github.com/arduino/arduino-cli cd ~/go/bin/ jaufranc@FX8350:~/go/bin$ ./arduino-cli Arduino Command Line Interface (arduino-cli). Usage: arduino-cli [command] Examples: arduino-cli <command> [flags...] Available Commands: board Arduino board commands. compile Compiles Arduino sketches. config Arduino Configuration Commands. core Arduino Core operations. help Help about any command lib Arduino commands about libraries. sketch Arduino CLI Sketch Commands. upload Upload Arduino sketches. version Shows version number of arduino CLI. Flags: --config-file string The custom config file (if not specified ./.cli-config.yml will be used). --debug Enables debug output (super verbose, used to debug the CLI). --format string The output format, can be [text|json]. (default "text") -h, --help help for arduino-cli Use "arduino-cli [command] --help" for more information about a command. |
I don’t have a board handy right now, so I’ll just try some commands to create new project, install boards, and build the code again mostly following the README in github.
- Creating a new sketch
1 2 |
$ ./arduino-cli sketch new cnxsoft-test Sketch created in: /home/jaufranc/Arduino/cnxsoft-test |
This create a Sketch with minimal code:
1 2 3 4 5 6 7 |
$ cat /home/jaufranc/Arduino/cnxsoft-test/cnxsoft-test.ino void setup() { } void loop() { } |
- Modifying the code with vi/emacs, or other editors
1 2 3 4 5 6 7 8 9 10 |
void setup() { pinMode(LED_BUILTIN, OUTPUT); } void loop() { digitalWrite(LED_BUILTIN, HIGH); delay(1000); digitalWrite(LED_BUILTIN, LOW); delay(1000); } |
- Finding core and install it:
1 2 3 4 5 |
$ ./arduino-cli core search esp8266 Searching for platforms matching 'esp8266' ID Version Installed Name esp8266:esp8266 2.4.1 Yes |
There’s no ESP32, so I used esp8266 instead, and it’s already installed on my system so nothing to do here if you plan to go with ESP8266, but if you had another board with the core not installed, that’s how we’d go:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
$ ./arduino-cli core search arduino Searching for platforms matching 'arduino' ID Version Installed Name Intel:arc32 2.0.2 No Intel Curie Boards arduino:avr 1.6.21 Yes Arduino AVR Boards arduino:nrf52 1.0.2 No Arduino nRF52 Boards arduino:sam 1.6.11 No Arduino SAM Boards (32-bits ARM Cortex-M3) arduino:samd 1.6.18 No Arduino SAMD Boards (32-bits ARM Cortex-M0+) arduino:stm32f4 1.0.1 No Arduino STM32F4 Boards littleBits:avr 1.0.0 No littleBits Arduino AVR Modules $ ./arduino-cli core install arduino:samd Downloading arduino:arm-none-eabi-gcc@4.8.3-2014q1... arduino:arm-none-eabi-gcc@4.8.3-2014q1 downloaded Downloading arduino:bossac@1.7.0... arduino:bossac@1.7.0 downloaded Downloading arduino:openocd@0.9.0-arduino6-static... arduino:openocd@0.9.0-arduino6-static downloaded Downloading arduino:CMSIS@4.5.0... arduino:CMSIS@4.5.0 downloaded Downloading arduino:CMSIS-Atmel@1.1.0... arduino:CMSIS-Atmel@1.1.0 downloaded Downloading arduino:arduinoOTA@1.2.0... arduino:arduinoOTA@1.2.0 downloaded Downloading arduino:samd@1.6.18... arduino:samd@1.6.18 downloaded Installing arduino:arm-none-eabi-gcc@4.8.3-2014q1 arduino:arm-none-eabi-gcc@4.8.3-2014q1 installed Installing arduino:bossac@1.7.0 arduino:bossac@1.7.0 installed Installing arduino:openocd@0.9.0-arduino6-static arduino:openocd@0.9.0-arduino6-static installed Installing arduino:CMSIS@4.5.0 arduino:CMSIS@4.5.0 installed Installing arduino:CMSIS-Atmel@1.1.0 arduino:CMSIS-Atmel@1.1.0 installed Installing arduino:arduinoOTA@1.2.0 arduino:arduinoOTA@1.2.0 installed Installing arduino:samd@1.6.18... arduino:samd@1.6.18 installed |
- Listing and installing libraries
Command the list already installed libraries:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
$ ./arduino-cli lib list Name Installed Location Adafruit_APDS9960_Library 1.0.5 sketchbook Adafruit_Circuit_Playground 1.8.0 sketchbook Adafruit_ESP8266 1.0.0 sketchbook Adafruit_HTU21DF_Library 1.0.1 sketchbook Adafruit_NeoPixel 1.1.6 sketchbook ArduinoJson 5.13.2 sketchbook .... Temboo 1.2.1 sketchbook Timer-master sketchbook USBHost 1.0.5 sketchbook WiFiManager 0.12 sketchbook |
Command to search for a library to install:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
$ ./arduino-cli lib search wifi101 Name: "WiFi101OTA" Author: Arduino Maintainer: Arduino <info@arduino.cc> Sentence: Update sketches on your board over WiFi Paragraph: Requires an Arduino/Genuino SAMD board Website: http://www.arduino.cc/en/Reference/WiFi101OTA Category: Other Architecture: samd Types: Arduino Versions: [1.0.0, 1.0.1, 1.0.2] Name: "WiFi101" Author: Arduino Maintainer: Arduino <info@arduino.cc> Sentence: Network driver for ATMEL WINC1500 module (used on Arduino/Genuino Wifi Shield 101 and MKR1000 boards) Paragraph: This library implements a network driver for devices based on the ATMEL WINC1500 wifi module Website: http://www.arduino.cc/en/Reference/WiFi101 Category: Communication Architecture: * Types: Arduino Versions: [0.5.0, 0.5.1, 0.6.0, 0.7.0, 0.8.0, 0.9.0, 0.9.1, 0.10.0, 0.11.0, 0.11.1, 0.11.2, 0.12.0, 0.12.1, 0.13.0, 0.14.0, 0.14.1, 0.14.2, 0.14.3, 0.14.4, 0.14.5, 0.15.0, 0.15.1, 0.15.2] |
Installing the library:
1 2 3 |
$ ./arduino-cli lib install "WiFi101" WiFi101@0.15.2 downloaded Installed WiFi101@0.15.2 |
- Building our sketch for MKR1000
1 2 3 |
$ ./arduino-cli compile --fqbn arduino:samd:mkr1000 /home/jaufranc/Arduino/cnxsoft-test Build options changed, rebuilding all Sketch uses 9736 bytes (3%) of program storage space. Maximum is 262144 bytes. |
- Checking board connection
While I don’t have a board here with me, I do has a USB to TTL debug board detected by the following command:
1 2 3 |
$ ./arduino-cli board list FQBN Port ID Board Name /dev/ttyUSB0 10c4:ea60 unknown |
It shows “unknown” because it’s not an Arduino board, but you’d have the same results if the Arduino core for your board was not installed for example. If it is, the board name will be displayed.
- JSON parsing
They also implemented an option to output JSON data for parsing by other program. e.g.:
1 |
$ ./arduino-cli --format json board list | jq |
jq is a command line JSON processor used to “beautify” the output.
Arduino Command Line Interface is a welcomed development, and it looks to work reasonably well considering it’s still alpha stage software.
Jean-Luc started CNX Software in 2010 as a part-time endeavor, before quitting his job as a software engineering manager, and starting to write daily news, and reviews full time later in 2011.
Support CNX Software! Donate via cryptocurrencies, become a Patron on Patreon, or purchase goods on Amazon or Aliexpress
That’s a great news for two reasons. The first one is that it will significantly simplify CLI usage. I’ve mostly used arduino via the CLI already because their IDE is a real pain to use, the editor almost doesn’t work, it does everything it can to annoy you. So I enabled verbose mode for executed commands, took note of them and placed them inside makefiles. But that was really not trivial to use, especially when it comes to dependencies. So at least now I should be able to compile regular programs without having to edit them in their awful editor.… Read more »
Man.. the embedded space is so bizarre, it always seems like they sorta reinvented the wheel instead of using existing tools. They say “Many of you requested a way to use our tools in Makefiles” and then present some weird custom solution of theirs – instead of a way to build a link things in a sane/standard way. They’ve done a LOT of the hard work of making stuff “just-work”, but why didn’t they do all this using the normal tool-chain like CMake/git/GNU-tools/crosstool-NG/etc.? (well the only obvious reason is Arduino/Platformio/and-company try to establish lock in)
Normally you do the other way around: first you design the CLI, then you map the GUI on top of it to execute those commands. Here it is the other way around…
I am now building a gitlab-ci example, together with a deployment based on a Kubernetes cluster running on an armbian box for the flashing, stay tuned…
Idea: a vim plugin 🙂
This seems very similar to platformIO…
Well, I’m using arduino-builder for over a year already, works quite fine once you know how to set up the build.options.json file. Works also perfectly on arm architechtures, so you can for example develop/fix stuff easily directly on the ras-pi board working as a long-term base for your arduino project…