Arduino CLI is a tool that has revolutionized the way of working with Arduino boards from the command line. Since its launch, it has marked a before and after, allowing developers and engineers to manage projects with extreme flexibility and customization, without having to depend on traditional integrated development environments. The importance of Arduino CLI lies in the fact that it not only speeds up development, but also offers multi-platform compatibility.
So, the Arduino CLI is not only useful, but in many cases, it represents a powerful solution for those looking to integrate their development tools into automated scripts or work on embedded systems with ARM architectures, such as the Raspberry Pi. In addition, thanks to the versatility it offers, it has become a fundamental part of the Arduino ecosystem. Today we will explore in depth all its features, how to install it, and what you can do with it.
What is Arduino CLI? A technical introduction
Arduino Command Line Interface (CLI) is a command-line application that allows users to compile, upload, and manage programs for any Arduino board without opening the graphical IDE. This tool is especially useful for those who prefer to work from the terminal or are looking to automate tasks.
Arduino CLI is designed to be scalable and allows you to perform most of the tasks that you would normally do from the Arduino IDE, but with the advantage of integrating it into scripts or pipelines. With simple commands you can install dependencies, manage libraries, and perform other tasks that are essential for project development. In addition, its compatibility with JSON facilitates integration with other third-party programs and tools.
Installing Arduino CLI
To start using Arduino CLI, the first step is to install it on your system. The good news is that it is available for multiple platforms such as Windows, macOS, and Linux distributions, including those running on ARM architectures, such as the aforementioned Raspberry Pi.
Depending on your operating system, there are several ways to install Arduino CLI. On Arch Linux-based distributions, for example, you can install it directly from the repositories by running:
pacman -S arduino-cli
On other systems, you can get the binary from the official GitHub repository and follow the corresponding installation instructions.
Initial setup
Once installed, the next step is the initial configuration. This is done through a “yaml” file that will act as the configuration hub for all Arduino CLI operations. This file can be created with the following command:
arduino-cli config init
This command will generate the corresponding file in the directory /home/user/.arduino15/arduino-cli.yaml, which will contain the key information that Arduino CLI needs to function properly.
Add and manage license plates
One of the most useful aspects of the Arduino CLI is the ease with which you can manage the boards connected to your computer. If you have a board connected, the following command will allow you to list the available boards:
arduino-cli board list
This command will display relevant information about all connected boards, such as port and ID name. However, sometimes the board may be connected but not recognized correctly, displaying an “Unknown” message.
To fix this, you can use the command board listall
to see all compatible plates and their corresponding FQBN (Fully Qualified Board Name). If the board you want to use requires additional core installation, as is the case with some ESP32 boards, you can do so with the following command:
arduino-cli core install esp32:esp32
Creating projects with Arduino CLI
Arduino CLI allows you to easily create new projects using the command sketchTo start a new project, run the following command:
arduino-cli sketch new nombre_proyecto
This will create a new folder with your project name and a .ino file inside. This file will be the one you need to edit to add your specific code. Once you have your code ready, you can compile it using the following command:
arduino-cli compile --fqbn esp32:esp32:esp32cam
This command will compile the code using the board you specify with the parameter –fqbn. If all is well, the binary file will be generated ready to be uploaded to your board.
Uploading the code to the board
Once the code is compiled, the next step is to upload it to the board. Arduino CLI makes this process easy with a simple command:
arduino-cli upload -p /dev/ttyACM0 --fqbn esp32:esp32:esp32cam
This command will upload the code to the board connected to the specified port. In this case, an ESP32 board and the USB port /dev/ttyACM0 are being used.
Integration with text editors
Arduino CLI not only works from the command line, but can be integrated within various text editors and development environments. This allows developers to use their favorite tools while taking advantage of the Arduino CLI capabilities.
For example, you can integrate Arduino CLI with Vim using a plugin manager like vim plug. Once the plugin manager is installed, you will only have to add the following code to your file .vimrc:
Plug 'vim-arduino'
Once this is done, you will be able to perform actions such as selecting the board, programmer, and port, as well as compiling and uploading code, all directly from Vim. Other editors such as VSCode also offer integration with Arduino CLI via extensions, allowing for a more fluid and visual development experience.
Automation and scripts in IoT projects
One of the great benefits of Arduino CLI is its ability to be integrated into automated scripts, which is particularly useful in IoT projects. For example, it is possible to use Arduino CLI together with NodeJS to systematize the entire process of building and deploying IoT applications.
With simple commands like arduino-cli board attach
y arduino-cli core install
, you can automate repetitive processes that would otherwise require manual intervention. This is especially advantageous when working with multiple devices or boards, such as in the case of ESP32 or ESP8266-based projects.
Additionally, Arduino CLI provides commands to manage libraries and install dependencies. This is extremely useful when working on complex projects with multiple dependencies. This way, you can quickly install libraries (eg, arduino-cli lib install WiFi101
) or search for libraries related to a specific topic using the command lib search
.
Arduino CLI is, without a doubt, a must-have tool for those working on advanced Arduino projects. Its ability to integrate into different workflows, its compatibility with a wide range of editors, and its flexibility to automate tasks make its use almost mandatory for any advanced developer or IoT enthusiast looking to increase their productivity.
- Arduino CLI allows you to manage boards and libraries from the command line.
- It is easy to integrate into text editors like Vim or VSCode.
- Automate the creation, compilation and upload of code to Arduino boards.