# Problems with I2C in node-red on Raspberry Pi

**URL:** <https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621>\
**Category:** General\
**Created:** [13 May 2020 21:33 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621 "2020-05-13T21:33:44Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![oldstuffisgood](https://avatars.discourse-cdn.com/v4/letter/o/f04885/32.png) [@oldstuffisgood](https://discourse.nodered.org/u/oldstuffisgood)\
**Post date:** [13 May 2020 21:33 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621/1 "2020-05-13T21:33:44Z")

</div>

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.

> **[node-red-contrib-i2c](https://flows.nodered.org/node/node-red-contrib-i2c)**
>
> A Node-RED node to talk to the Raspiberry PI's I2C port

  

> **[node-red-contrib-johnny5](https://flows.nodered.org/node/node-red-contrib-johnny5)**
>
> A set of node-red nodes for using Johnny-Five and IO plugins (fork)

  
exec node  
node-red-daemon

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/mycode.py).

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.

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [13 May 2020 21:44 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621/2 "2020-05-13T21:44:44Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![gerry](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gerry/32/21604_2.png) [@gerry](https://discourse.nodered.org/u/gerry)\
**Post date:** [13 May 2020 21:52 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621/3 "2020-05-13T21:52:59Z")

</div>

Found the relevant part from another thread  
start-----  
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 -\> [https://github.com/tenzinlote/i2c\_install](https://github.com/tenzinlote/i2c_install)

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

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [14 May 2020 07:36 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621/4 "2020-05-14T07:36:30Z")

</div>

> [@oldstuffisgood](#):
>
> 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

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.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [13 July 2020 07:42 UTC](https://discourse.nodered.org/t/problems-with-i2c-in-node-red-on-raspberry-pi/26621/5 "2020-07-13T07:42:36Z")

</div>

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