Exception in thread "main" java.lang.ExceptionInInitializerError
        at processing.app.Preferences.save(Preferences.java:735)
        at processing.app.Preferences.init(Preferences.java:249)
        at processing.app.Base.main(Base.java:117)
Caused by: java.awt.HeadlessException:
No X11 DISPLAY variable was set, but this program performed an operation which requires it.
        at sun.awt.HeadlessToolkit.getMenuShortcutKeyMask(HeadlessToolkit.java:234)
        at processing.core.PApplet.<clinit>(Unknown Source)
        ... 3 more

This is the error, i am getting, after proper installation of arduino.

  • And are you doing it on the Pi, or using SSH to connect to a remote Pi? – Majenko Sep 15 '17 at 20:18
  • using ssh, terminal. – Karan Bhatia Sep 15 '17 at 20:21
  • From what operating system? – Majenko Sep 15 '17 at 20:21
  • 3
    Well, good luck with that then. The Arduino IDE is a graphical program. It needs to be run from the Pi's GUI or from another X Windows based system (Linux). – Majenko Sep 15 '17 at 20:30
  • 1
    I'm voting to close this question as off-topic because this is about the Raspberry Pi, not about Arduino – Chris Stratton Sep 16 '17 at 0:53

You can't run the Arduino IDE (a graphical Integrated Development Environment) via plain SSH and expect to magically receive the user interface locally... but with some tweaking, you might achieve something, depending on what you really need to do.

If you wish to only compile a file you edited locally (on your Windows machine) and sent to the RPi (via SCP/FTP or any other way) you should be able to use Xvfb to create a virtual graphical environment from which you could execute the Arduino IDE, but you will not be able to see the UI.

I didn't test this commands on the Raspberry, but here is what I do to remotely build Arduino sketches:

/sbin/start-stop-daemon --start --quiet --pidfile /tmp/custom_xvfb_1.pid --make-pidfile --background --exec /usr/bin/Xvfb -- :1 -ac -screen 0 1280x1024x16
export DISPLAY=:1.0
arduino --verify --board ${BOARD} full/path/to/sketch.ino

I have the Arduino IDE installation path in my PATH environment variable, I have already installed the xvfb package and where ${BOARD} is one of the following:

  • arduino:avr:uno
  • arduino:avr:yun
  • arduino:avr:diecimila:cpu=atmega168
  • arduino:avr:diecimila:cpu=atmega328
  • arduino:avr:nano:cpu=atmega168
  • arduino:avr:nano:cpu=atmega328
  • arduino:avr:mega:cpu=atmega1280
  • arduino:avr:mega:cpu=atmega2560
  • arduino:avr:megaADK
  • arduino:avr:leonardo
  • arduino:avr:micro
  • arduino:avr:esplora
  • arduino:avr:mini:cpu=atmega168
  • arduino:avr:mini:cpu=atmega328
  • arduino:avr:ethernet
  • arduino:avr:bt:cpu=atmega168
  • arduino:avr:bt:cpu=atmega328
  • arduino:avr:lilypad:cpu=atmega168
  • arduino:avr:lilypad:cpu=atmega328
  • arduino:avr:pro:cpu=atmega168
  • arduino:avr:pro:cpu=atmega328
  • arduino:sam:arduino_due_x

On the other hand, if you wish to upload an already compiled (on your Windows machine) sketch onto an Arduino connected to the RPi then you don't need the Arduino IDE, you only need avrdude and there are plenty of guides on how to manually upload an .hex file using avrdude.

Last, but not least, you are also able to use the Arduino IDE running on your RPi but viewing the user interface on your Windows computer using X11 screen forwarding: something which can be very complex, unless you use some software making your life easier like MobaXterm: it's available for free for personal use and provides a very easy setup for X11 forwarding.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.