If you want to use the -Linux- command line for doing Arduino builds/uploads on a headless machine (that is to say: without an X server running...it's often the case of computers accessible only through SSH), invoking the bare "arduino" executable doesn't work (see https://github.com/arduino/Arduino/issues/1981)

A workaround is to create this little script (we'll call "arduino-headless")...:

#!/bin/bash

SCREEN=3

Xvfb :$SCREEN -nolisten tcp -screen :$SCREEN 1280x800x24 &

xvfb="$!"

DISPLAY=:$SCREEN arduino $@

kill -9 $xvfb

...to put it on your $PATH (it assumes your arduino executable is also on your $PATH) and to call it like this every time you need it (change the command line arguments to match your board, port, and sketch file.):

arduino-headless --upload --board arduino:avr:uno --port /dev/ttyACM0 -v sketch_file.ino

As you've seen, in addition to installation of the regular Arduino IDE in the headless machine, this trick requires the installation of the xvfb package (Debian and Ubuntu: sudo apt-get install xvfb; Fedora: sudo dnf install xorg-x11-server-Xvfb).

Thanks to Matthew Beckler

Share