Arduino Command Line Interface released on August 24th by Arduino team capable of doing all functionalities already provided by Arduino IDE. This means that from now on you can compile your Arduino code vi a command in a bash/terminal without having to open the Arduino IDE. They introduced the new CLI tools in a short video on their YouTube channel.
This may not be a sensible change for most DIYers or Hobbyist who use Arduino IDE for their daily projects incorporating an Arduino Uno board. But it’s probably a big news for tool vendors or cloud IDE providers who support (or were trying to support) Arduino in their platform. Now they can delegate the major parts of the process to the Arduino CLI. This means that they can have a lot more confidence that the output of their tools is as close as possible to the Arduino IDE itself.
We want you to be able to add Arduino support to whatever development flow you prefer. Whether you use Atom, Eclipse, Emacs, Vim, VSCode, or are even building your own tools, Arduino CLI makes this possible.Arduino Team Blog
Potential use cases
There is a lot of use cases for the Arduino Command Line Interface but it’s mostly targeted for tool vendors or large companies that have a CI/CD that also includes building an Arduino program. It’s now much easier to call the Arduino CLI in a Makefile or via any other CI script tools.
If you’ve ever tried platformio.org the features provided by the Arduino CLI should be familiar for you as it does more or less the same life cycle tasks that you have in that product when you want to make an Arduino program. Also if you’ve ever tried building an Arduino program with CLion (from JetBrains company) you should know that it requires doing a lot of manual editing of configuration files or installing some plugins that are always out of date. Another big player in this field is the Eclipse C++ IDE for Arduino. The Arduino CLI should be a good news for all of them. As it extracts a big part of the responsibilities to an external component. Of course it all depends on the internal architecture of their product.
Seems as these days we have a lot of different hardware development board in the market, most of these vendors have already designed their product to support a new board as a sort of pluggable component. So it shouldn’t be huge change for them to incorporate the new tools.
Arduino CLI main features
The Arduino command line interface provides following core functionalities that covers almost all requirements to develop an application for a typical hardware development board. Here are some of the most important of them.
You can install different boards using Arduino CLI. When you connect a board via USB, it would be detected as an unknown board unless you have installed its corresponding board via board management command.
The typical usage of this command is:
# Lists all connected boards. arduino-cli board list # Attaches a sketch to a board. arduino-cli board attach --board serial:///dev/tty/ACM0 --sketch mySketch # Listing all known boards arduino-cli board listall
The Arduino command line interface (CLI) is capable of installing and uninstalling libraries. You can try to search for libraries and install them on your computer or ask the Arduino CLI to upgrade all your libraries.
You can use this command like:
arduino-cli lib install AudioZero arduino-cli lib update-index
One of the most important configurations in Arduino IDE is the board manager URL. It’s a URL of the service that provides description of a family of development boards so that you can use the Arduino IDE to program those boards. Th Arduino command line interface enables you to manage configurations like this via command line.
Configurations can be managed as:
# Initializes the new config file in the default location arduino-cli config init # prints all configurations arduino-cli config dump
The sketch command enables you to create a new folder containing an sketch file (with .ino suffix) with the basic structure of a typical Arduino program (with setup() and loop() functions).
arduino-cli sketch new MySketch
Obviously a core feature of such a tool should be to compile a sketch. When you want to compile the sketch, you should also specify the board that you should have installed previously.
arduino-cli compile -b arduino:avr:uno /home/user/Arduino/MySketch
The last step in the process of developing an application is to upload the code to your development board. This is possible via upload command.
arduino-cli upload /home/user/Arduino/MySketch
Generating JSON output
The Arduino CLI is capable of producing outputs in JSON format. This can be very beneficial when integrating it with other tools. It really simplifies processing the outputs and reasoning about the outcome of a command. As an example, you can have a list of all known boards in json format like this:
arduino-cli --format json board listall
But not all commands necessary supports json output and it’s not clear from their default help whether they support it or not. You should try them to see the output.
How stable is this initial version?
Well, as all other first releases of any software, it’s definitely not production ready yet. While playing with it, some commands threw memory access errors like %!s(PANIC=runtime error: invalid memory address or nil pointer dereference). The Arduino team have announced it as an Alpha version and invited developers to participate in its development via its GitHub repository. But it’s ready enough to be considered as a basis for product vendors to see how they can integrate it in their tools.