1

I have tried everything on this url

https://stackoverflow.com/questions/10165761/java-cant-connect-to-x11-window-server-using-localhost10-0-as-the-value-of-t

session output:

root@whale:/home/kermit# echo $DISPLAY                                   
localhost:1.0
root@whale:/home/kermit# cd dev/sht30/
root@whale:/home/kermit/dev/sht30# arduino --upload sht30v1.ino --port /dev/ttyUSB0
Exception in thread "main" java.awt.AWTError: Can't connect to X11 window server using 'localhost:1.0' as the value of the DISPLAY variable.
        at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:102)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/sun.awt.X11GraphicsEnvironment.<clinit>(X11GraphicsEnvironment.java:61)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:101)
        at java.desktop/java.awt.GraphicsEnvironment$LocalGE.<clinit>(GraphicsEnvironment.java:83)
        at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:129)
        at java.desktop/sun.awt.X11.XToolkit.<clinit>(XToolkit.java:231)
        at java.base/java.lang.Class.forName0(Native Method)
        at java.base/java.lang.Class.forName(Class.java:315)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:588)
        at java.desktop/java.awt.Toolkit$2.run(Toolkit.java:583)
        at java.base/java.security.AccessController.doPrivileged(Native Method)
        at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:582)
        at processing.core.PApplet.<clinit>(Unknown Source)
        at processing.app.Preferences.save(Preferences.java:735)
        at processing.app.Preferences.init(Preferences.java:249)
        at processing.app.Base.main(Base.java:117)

How do you run arduino in headless mode on a raspberry pi?

1
  • I know this doesn't solve your problem with the Arduino IDE, but if you want to do headless development on a raspberry pi, you might want to look into PlatformIO, which does not need a GUI and can be used from the CLI. (platformio.org and docs.platformio.org/en/latest/core/index.html). Commented Feb 2, 2021 at 19:22

1 Answer 1

2

It is probably a non-existant or stale auth cookie in your .Xauthority file. This sort of thing happens when you're running your X session with one user but trying to run your X application as different user. Doing sudo or su root (or really any other user) is a common way to get in that situation. Running the IDE as root usually mean something else has already gone sideways. The typical reason for that is you're running as root instead of fixing your permissions to the Arduino serial device file.


That said, if you want to run headless builds and uploads of Arduino projects, what you're looking for is arduino-cli.

cd /path/to/directory/containing/sht30v1.ino
arduino-cli -b arduino:avr:nano compile
arduino-cli -b arduino:avr:nano upload --port /dev/ttyUSB0
8
  • What version is arduino-cli in? I am 1.8.13 Commented Feb 2, 2021 at 18:55
  • I'm not sure offhand what the latest version is. Mine has been installed for some time now, I'm not sure its version will tell you anything. The thing is though, the IDE version and the arduino-cli versions don't necessarily need to be related. And the version number that largely affects your project is the version number of the (AVR) core, currently at 1.8.3. It's version number is also only-so-related to the IDE or arduino-cli. Run the latest AVR core with the latest arduino-cli and you should be fine. Commented Feb 2, 2021 at 18:58
  • Just to give you a bit more info, I just ran their installer script (the curl to shell pipe) on their page to install the latest. arduino-cli version now reports version 0.15.0 commit 0a034d73. Again, this number has not a lot do with the others. Commented Feb 2, 2021 at 19:04
  • It looks like you've skipped over the command-line for compiling, the first of two in the answer. Commented Feb 2, 2021 at 19:12
  • I can get the sketch compiled and export the .hex files but it won't upload bpa.st/HYXCG Commented Feb 2, 2021 at 20:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.