Need help running Processing sketches with Node-RED's exec node


I'd like to see if anyone can help me run a specific Processing sketch through the Node-RED user interface. I'm building a connected desk lamp and would like to be able to change its light patterns from my phone.

I can't use GPIO pins since designating a specific sketch requires more than a high/low output... what I think I need is some way to specify a string value which can be read into the Pi.

So I thought I could use an exec node to not only pass the string, but to also run the program at the same time.

The above image shows a bash file that I created later on, but originally, I put the following command in a bash file and tried to run it:

processing-java --sketch=/home/pi/Digital-lava-lamp/StartupArraySweep --run

The command works perfectly in the Pi's terminal but when I try to execute it through Node-RED I get the following error.

I've tried to work around this a number of ways, but the same error occurs each time. Here's everything that I've tried so far.

  • Running the above os.system command as is
  • Adding the above command to a bash file, then running the bash file
  • Adding the above command to a Python script, and calling it using os.system
  • Checking the msg.payload box in exec node
  • Unchecking the msg.payload box in exec node

So does anybody have any suggestions on what I should try next?? I can't decipher the error to be able to fix it. If anyone can explain what's wrong here, or maybe an alternate way to accomplish my goal, I'd be very grateful. Thanks.

The error states: 'No x11 display variable was set but this program performed an operation which requires it'

The sketch wants to ouput to screen but it can't because node-red doesnt have a "screen" output available.

1 Like

This is out of date so there there may be better advice, but it may be a start.

The problem has been solved!

Many thanks to @dceejay and @bakman2. From you guys' input I learned what the "X11 Display" error meant, and the link provided a good first clue on how to fix it. So ultimately, this is what worked for me...

In the Command Terminal on the Pi, use the below command to load Java's headless library:


Note that this setting persists even after a Pi reboot, so it does not need to be constantly toggled (at least it does for me). After that, use Node-RED's exec node to run the following commands:

unset DISPLAY;
export DISPLAY=":0"

This will make Node-RED the main virtual display, allowing it to open Processing sketches using:

processing-java --sketch=[your file path here] --run

Thanks for the support! Hope this can help someone else as well.

1 Like