Problems with I2C in node-red on Raspberry Pi

I'm having trouble with trying to get node-red to run my Python code and using I2C nodes on node-red.

I used the following nodes so far, yet none of them work on my end for reasons explained below.

exec node

I tested my python code on the terminal before trying to run it in node-red. If I run my python code in the terminal, it recognizes that my I2C device is connected and prints my I2C data to the terminal. But if I use the exec node with my python code (python code handles I2C), node-red hangs and my code doesn't output anything at all. Likewise, if I use the daemon node, I get a "command not found" error despite using the same command I'd use on the terminal to run my code (e.g. python /home/pi/

If I use the I2C nodes, those nodes complain that I have a "remote I/O error" despite having a device connected on the I2C pins. I even ran i2cdetect -y 1 (default I2C bus address) and I found the I2C address used. Likewise, if I use the Johnny 5 nodes, I get an error that "no such file/directory" exists despite having installed Johnny 5 on node-red.

Any help would be appreciated, as I've been trying this for almost a whole day to no avail.

EDIT: I figured it out. Thanks.

There have been numerous discussions around the contrib-i2c node(s). You can do a search in the forum for that. That node appears to be fairly persnickety to install and get to work. Several have reported it doesn't want to install from pallete manager and when they did get in that way it didn't work. You may have to drop to the command line to get it in and working. Again, do a forum search for that node. As for johnny5 I can offer no suggestions.

Found the relevant part from another thread
If you can't install the node-red-contrib-i2c(fails).

I had these kinds of problems too, before you install anything.
first of all, if you have node-red-contrib-i2 modules inside your node_modules -> delete it.

You should have these 3 modules in side your "node_modules"

  • Bindings
  • i2c-bus
  • nan

If you don't have them inside your .node-red->node_modules, then put them inside there.
After that, you can download the "node-red-contrib-i2c" module from the Manange palette.

link to the 3 modules ->

Best regards,
-------- END
maybe this will help, maybe not

1 Like

Using an exec node in this way has proved successful for others, so I suggest you try this route again, then report back with the exact problem you are seeing. Show us how you have configured the exec node and show us the node red log from the time node red is started to the point where it runs the exec node.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.