LinuxCommandLibrary

arduino

Upload code to Arduino boards

TLDR

Build a sketch

$ arduino --verify [path/to/file.ino]
copy

Build and upload a sketch
$ arduino --upload [path/to/file.ino]
copy

Build and upload a sketch to an Arduino Nano with an Atmega328p CPU, connected on port /dev/ttyACM0
$ arduino --board [arduino:avr:nano:cpu=atmega328p] --port [/dev/ttyACM0] --upload [path/to/file.ino]
copy

Set the preference name to a given value
$ arduino --pref [name]=[value]
copy

Build a sketch, put the build results in the build directory, and reuse any previous build results in that directory
$ arduino --pref build.path=[path/to/build_directory] --verify [path/to/file.ino]
copy

Save any (changed) preferences to preferences.txt
$ arduino --save-prefs
copy

Install the latest SAM board
$ arduino --install-boards "[arduino:sam]"
copy

Install Bridge and Servo libraries
$ arduino --install-library "[Bridge:1.0.0,Servo:1.2.0]"
copy

SYNOPSIS

arduino [OPTIONS] [SKETCH_FILE]

PARAMETERS

--board fqbn
    Specifies the Fully Qualified Board Name (e.g., arduino:avr:uno) for compilation or upload.

--port serial_port
    Designates the serial port (e.g., /dev/ttyUSB0 or COM3) for uploading sketches.

--upload
    Compiles and uploads the specified sketch to the microcontroller. Requires --board and usually --port.

--verify
    Compiles (verifies) the specified sketch without uploading it. Useful for checking code syntax and compilation errors.

--build-path path
    Sets a custom directory for storing build artifacts like compiled binaries (.hex files).

--save-prefs
    Saves all currently active preferences to the preferences file. Usually used after --set-pref.

--get-pref preference_key
    Retrieves and prints the value of a specific IDE preference (e.g., editor.font.size).

--set-pref preference_key=value
    Sets a specific IDE preference to a new value. The change is temporary unless --save-prefs is also used.

--pref preference_key=value
    Sets a temporary preference for the current command invocation only; does not persist.

--verbose-build
    Displays highly verbose output during the compilation process, showing compiler commands and flags.

--verbose-upload
    Displays highly verbose output during the upload process, useful for debugging upload issues.

--version
    Prints the version of the Arduino IDE.

--help
    Displays a summary of command-line options.

DESCRIPTION

The arduino command is the primary executable for the Arduino Integrated Development Environment (IDE). It allows users to launch the graphical IDE for writing, compiling, and uploading code (sketches) to Arduino-compatible microcontrollers.

Beyond its graphical interface, the command also provides a powerful command-line interface (CLI) for performing automated tasks such as compiling (verifying) and uploading sketches without launching the GUI. This headless operation is particularly useful for continuous integration (CI) environments, automated testing, or scripting build processes for Arduino projects. It provides options to specify the target board, serial port, manage preferences, and control output verbosity.

CAVEATS

The arduino command requires the Arduino IDE to be installed on the system, as it is the executable for the IDE itself. Its command-line options are primarily intended for automation and headless operations, not for routine interactive use. It relies on a Java runtime environment. The specific options and their behavior might vary slightly between different versions of the Arduino IDE.

HEADLESS OPERATIONS

The command's strength lies in its ability to perform headless operations, meaning it can compile or upload sketches without launching the full graphical user interface. This is crucial for scripting, continuous integration (CI/CD) pipelines, and automated build systems. By using --verify and --upload with appropriate --board and --port arguments, developers can integrate Arduino sketch compilation and deployment into their automated workflows.

PREFERENCE MANAGEMENT

The arduino command offers fine-grained control over IDE preferences directly from the command line. Options like --get-pref allow querying current settings, while --set-pref can modify them. The --pref option provides a way to set temporary preferences for a single command invocation, which is useful for testing different compilation settings without altering the global IDE configuration. --save-prefs is necessary to make --set-pref changes permanent.

HISTORY

The Arduino project was launched in 2005, providing an accessible platform for electronics prototyping. The Arduino IDE, an open-source development environment, was central to its ease of use. Initially, the arduino command primarily launched the graphical interface. Over time, as the need for automation in embedded development grew, robust command-line options were integrated. This evolution allowed for compiling and uploading sketches from scripts, enabling continuous integration, automated testing, and batch processing, making the Arduino ecosystem more suitable for professional and complex projects beyond simple interactive development.

SEE ALSO

avrdude(1), avr-gcc(1)

Copied to clipboard