# Need help on how to use python in node red

**URL:** <https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315>\
**Category:** General\
**Created:** [16 December 2021 20:19 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315 "2021-12-16T20:19:05Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![elpepito](https://avatars.discourse-cdn.com/v4/letter/e/5fc32e/32.png) [@elpepito](https://discourse.nodered.org/u/elpepito)\
**Post date:** [16 December 2021 20:19 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/1 "2021-12-16T20:19:05Z")

</div>

Hello, I have a project involving a sensor with an I2C output. I'm using NODE RED and I managed to get the I2C information but I don't know how I can use a python code to make a test on the value of the I2C output and use the python script to output to a GPIO.  
Thanks

---

<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:** [16 December 2021 20:42 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/2 "2021-12-16T20:42:26Z")

</div>

Welcome to the forum @elpepito

Do you mean you want help writing the python code, or do you mean you want to call python code from node red. You can run a python script from node red using an exec node.

Why do you want to use python to output to GPIO? You can do that directly from node red.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [17 December 2021 09:29 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/3 "2021-12-17T09:29:30Z")

</div>

Node-RED is mostly javascript - so any processing inside Node-RED would be much easier using that... You can of course use an exec node to call out to a python program and get the result back if that is what you need - but there are also i2c type nodes and some sensor specific ones as well that may help do what you want.

---

<div class="post-metadata">

**Author:** ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)\
**Post date:** [17 December 2021 09:52 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/4 "2021-12-17T09:52:59Z")

</div>

Take a look at pigpiod and in particular pigs and the pipe interface [http://abyz.me.uk/rpi/pigpio/pigpiod.html](http://abyz.me.uk/rpi/pigpio/pigpiod.html)

With this library you can run I2C/SPI on any GPIO pin. It also allows you to create output wave forms and input timing/edge detection with ~10uS accuracy without having to use sudo.

Start by testing pigs commands from within a terminal session to detect your hardware and read results. Then access pigs from node-red using either exec, file in out or access the pipe interface of the library using tcp nodes.

In my experience if one is running on a Pi zero, python can put too much of a strain on memory/cpu especially if lots of devices are being accessed frequently.

P.S. The library has C and Python source examples to help you customise your device driver.

---

<div class="post-metadata">

**Author:** ![elpepito](https://avatars.discourse-cdn.com/v4/letter/e/5fc32e/32.png) [@elpepito](https://discourse.nodered.org/u/elpepito)\
**Post date:** [4 January 2022 22:06 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/5 "2022-01-04T22:06:01Z")

</div>

Hello and thank you, my project is to water automatically a plant with a humidity sensor which uses I2C. I don't know how I can get a python script running doing that on the raspberry because I don't know how to get the I2C values in python but I found how to get them with node red, but I don't know javascript, I only know python a bit. I hope it helps to understand my issues

---

<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:** [4 January 2022 22:21 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/6 "2022-01-04T22:21:22Z")

</div>

> [@elpepito](#):
>
> I hope it helps to understand my issues

Not really, I still don't know what you want help with. You don't need to know much javascript to use node-red, and there are people here who will help if you get stuck.

---

<div class="post-metadata">

**Author:** ![ozpos](https://avatars.discourse-cdn.com/v4/letter/o/278dde/32.png) [@ozpos](https://discourse.nodered.org/u/ozpos)\
**Post date:** [27 January 2022 14:30 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/7 "2022-01-27T14:30:55Z")

</div>

Did you check out the pigs interface I linked above ?

Make sure the pigpiod service is running, then make sure you can access the I2C device from the command line in a terminal session. With the above library there is no need for python or C for that matter, just send command strings to the device address from an exec node and read back the response.

---

<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:** [28 March 2022 14:31 UTC](https://discourse.nodered.org/t/need-help-on-how-to-use-python-in-node-red/55315/8 "2022-03-28T14:31:14Z")

</div>

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