Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i2c in nodered #250

Closed
e-abdi opened this issue Jun 26, 2023 · 2 comments
Closed

i2c in nodered #250

e-abdi opened this issue Jun 26, 2023 · 2 comments

Comments

@e-abdi
Copy link

e-abdi commented Jun 26, 2023

Hi guys, any ideas how to enable i2c for nodered container? I have the i2c enabled on the Raspberry itself but I can't seem to be able to access it inside nodered.

@Paraphraser
Copy link
Contributor

Please read #194 because this repo (gcgarner) is dormant. That issue explains what you should do to migrate to the active repo (SensorsIot).


I have never tried to use any of the GPIO pins on a Raspberry Pi for an actual project so I can only suggest things to try.

I tackle I2C problems with ESP32 or ESP8266 development boards. There are good libraries for both I2C and MQTT (for the command-and-control comms), and plenty of examples to follow.

You haven't said anything about your project so I'm a bit in the dark. There's a node-red-contrib-i2c add-on node which might do the trick. It seems to want devices in the form /dev/i2c-n where n is in the range 0…7.

My Raspberry Pi 4 appears to have I2C devices at /dev/i2c-20 and -21. If you're also using a Pi4, you could try mapping those into the container by adding these lines to the nodered service definition:

    devices:
      - "/dev/i2c-20:/dev/i2c-1"
      - "/dev/i2c-21:/dev/i2c-2"

If you're using something like a Zero2W, it seems to have a different set of I2C devices:

/dev/i2c-0  /dev/i2c-10  /dev/i2c-11  /dev/i2c-2

I have no idea how any of those devices (either the Pi4 or the Zero2W) map to pins so you'll have to figure out that part for yourself.

Hope this helps.

@e-abdi
Copy link
Author

e-abdi commented Jun 27, 2023

@Paraphraser thank you so much for the response!
That worked!
Sorry for not mentioning anything about my project.
This is a for my campervan which has IOTstack running on a raspberry and a bunch of other ESP32 and 8266 in various spots to control different relays/sensors. I just had one of these raspberry relay hats (https://wiki.52pi.com/index.php/EP-0099) laying around so I thought I use it instead of adding another esp8266.
I am using the node-red-contrib-i2c add-on as you mentioned. Just needed to map the i2c devices to the container as suggested, then used the "i2c scan" node to find the address and "i2c out" node to control the relays.

@e-abdi e-abdi closed this as completed Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants