Install arduino-cli

Install the toolset

We use the arduino-cli toolset to develop, compile and deploy arduino firmware from the Jetson board. Install arduino-cli by the following command:

curl -fsSL | sh

More information on how to use arduino-cli can be found here:

After installing, add the arduino binaries to the PATH environment variable:

echo "export PATH=$PATH:/home/jarvis/bin" >> ~/.bashrc
source ~/.bashrc

Testing the toolset by:

arduino-cli help core

Arduino CLI need a configuration file to work, create one by:

arduino-cli config init


Config file written to: /home/jarvis/.arduino15/arduino-cli.yaml

Optionally we can install picocom for serial communication from command line:

sudo apt install picocom

The final step is to allow the current user (jarvis) to access to serial devices on the system:

usermod -a -G dialout jarvis

Develop a simple led blinking application

Create a new Blinky sketch

Create new workspace directory for our Arduino sketches

mkdir -p ~/workspace/arduino
cd ~/workspace/arduino

Create a new sketch:

arduino-cli sketch new Blinky

Open the Blinky.ino sketch using vim:

vi  Blinky/Blinky.ino

Add code to blink built-in led:

void setup() {

void loop() {
    digitalWrite(LED_BUILTIN, HIGH);
    digitalWrite(LED_BUILTIN, LOW);

Install core for the Arduino Mega 2560

To be able to compile and upload sketch tho the Arduino Mega board, the corresponding core need to be installed. To find out detail about all arduino boards available on the system (Jetson), use the following command:

# Update board index
arduino-cli core update-index
# List all boards in the system
arduino-cli board list

This is the example output:

Port            Type            Board Name                          FQBN                Core       
/dev/ttyACM0    Serial Port     (USB) Arduino Mega or Mega 2560     arduino:avr:mega    arduino:avr
/dev/ttyS0      Serial Port     Unknown                                               
/dev/ttyS1      Serial Port     Unknown                                               
/dev/ttyS2      Serial Port     Unknown                                               
/dev/ttyS3      Serial Port     Unknown

Note down two values: FQBN (arduino:avr:mega) and Core arduino:avr.

As we can see, the Jetson board is connected to the Arduino Mega 2560 on the serial port /dev/ttyAMA0 and the corresponding core that needs to be installed is arduino:avr.

Install the core on the board by:

arduino-cli core install arduino:avr


Downloading packages...
arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7 downloaded                            
arduino:avrdude@6.3.0-arduino17 downloaded                                      
arduino:arduinoOTA@1.3.0 downloaded                                             
arduino:avr@1.8.3 downloaded                                                    
Installing arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7...
arduino:avr-gcc@7.3.0-atmel3.6.1-arduino7 installed
Installing arduino:avrdude@6.3.0-arduino17...
arduino:avrdude@6.3.0-arduino17 installed
Installing arduino:arduinoOTA@1.3.0...
arduino:arduinoOTA@1.3.0 installed
Installing arduino:avr@1.8.3...
Configuring platform...
arduino:avr@1.8.3 installed

Verify if the core is successfully installed and recognized by Arduino CLI:

arduino-cli core list

Compile and upload the sketch

Compile the sketch Blinky sketch using the following command:

arduino-cli compile --fqbn arduino:avr:mega Blinky

Note that the FQBN of the arduino board can be found on the output of the command: arduino-cli board list.

Output of the compilation:

Sketch uses 1536 bytes (0%) of program storage space. Maximum is 253952 bytes.
Global variables use 9 bytes (0%) of dynamic memory, leaving 8183 bytes for local variables. Maximum is 8192 bytes.

Upload the built sketch with the following command

arduino-cli upload -p /dev/ttyACM0 --fqbn arduino:avr:mega Blinky

If the upload is successful, the built in LED on the Mega board should be blinking.


The comment editor supports Markdown syntax. Your email is necessary to notify you of further updates on the discussion. It will be hidden from the public.
Powered by antd server, (c) 2019 - 2024 Dany LE