# Invalid input: NaN using rpi gpio

**URL:** <https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842>\
**Category:** General\
**Created:** [18 May 2020 08:54 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842 "2020-05-18T08:54:49Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [18 May 2020 08:54 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/1 "2020-05-18T08:54:49Z")

</div>

Hi,  
I'm trying to get the following flow working. According to the debug output of "on" or "off", msg.payload is "1" or "0" as a number. But the status of pump says `Invalid input: NaN` and `nrgpio python command not running`, but

```auto
sudo -u nodejs-node-red ./nrgpio 11 1

```

works fine.

 ![flow](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/0/e/0eeb694c3ba2be46e8b5666f75ffbc7229fe72da.png)

Flow in json:

```auto
[{"id":"9c89b46.7714ec8","type":"mqtt in","z":"8ce28174.9fb388","name":"","topic":"moisture","qos":"2","datatype":"auto","broker":"4eca0d68.048e1c","x":110,"y":140,"wires":[["6e2d378b.4cead"]]},{"id":"9f0cdea8.902a58","type":"switch","z":"8ce28174.9fb388","name":"moisture-check","property":"payload","propertyType":"msg","rules":[{"t":"lte","v":"150","vt":"num"},{"t":"gt","v":"150","vt":"num"}],"checkall":"false","repair":false,"outputs":2,"x":280,"y":140,"wires":[["6e928127.00bcb"],["cbd6ccf6.bdd2f"]]},{"id":"6e928127.00bcb","type":"change","z":"8ce28174.9fb388","name":"on","rules":[{"t":"set","p":"payload","pt":"msg","to":"1","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":540,"y":100,"wires":[["9dfe863e.05ef28","4cbb16b7.84f4"]]},{"id":"cbd6ccf6.bdd2f","type":"change","z":"8ce28174.9fb388","name":"off","rules":[{"t":"set","p":"payload","pt":"msg","to":"0","tot":"num"}],"action":"","property":"","from":"","to":"","reg":false,"x":500,"y":180,"wires":[["9dfe863e.05ef28","4cbb16b7.84f4"]]},{"id":"904486c0.910a88","type":"inject","z":"8ce28174.9fb388","name":"","topic":"","payload":"100","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":220,"wires":[["9f0cdea8.902a58"]]},{"id":"bc7c5992.5168","type":"status","z":"8ce28174.9fb388","name":"","scope":null,"x":520,"y":300,"wires":[["4cbb16b7.84f4"]]},{"id":"6e2d378b.4cead","type":"debug","z":"8ce28174.9fb388","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":280,"y":80,"wires":[]},{"id":"9dfe863e.05ef28","type":"debug","z":"8ce28174.9fb388","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","x":740,"y":60,"wires":[]},{"id":"4cbb16b7.84f4","type":"rpi-gpio out","z":"8ce28174.9fb388","name":"pump","pin":"11","set":"","level":"0","freq":"","out":"out","x":740,"y":180,"wires":[]},{"id":"4eca0d68.048e1c","type":"mqtt-broker","z":"","name":"localhost","broker":"localhost","port":"1883","clientid":"","usetls":false,"compatmode":false,"keepalive":"60","cleansession":true,"birthTopic":"","birthQos":"0","birthPayload":"","closeTopic":"","closeQos":"0","closePayload":"","willTopic":"","willQos":"0","willPayload":""}]

```

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 May 2020 09:23 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/2 "2020-05-18T09:23:07Z")

</div>

@bjo welcome to the forum!

Why are you sending the output of the `status` node to the `gpio` node? that is what is causing the issue.  
send it to a debug node.

---

<div class="post-metadata">

**Author:** ![Steve-Mcl](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/steve-mcl/32/4826_2.png) [@Steve-Mcl](https://discourse.nodered.org/u/Steve-Mcl)\
**Post date:** [18 May 2020 09:27 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/3 "2020-05-18T09:27:27Z")

</div>

Hi, pretty sure you shouldn't be running node-red as sudo but hey ho.

Put debug nodes on all outputs of all nodes & see what is actually going into the pump. Trace it back to see where the problem originates.

If you get stuck, put a unique name all your debug nodes, screen shot the flow and debug output. (The named debug nodes help someone correlate each message in the debug window to the screenshot)

---

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [18 May 2020 09:58 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/4 "2020-05-18T09:58:52Z")

</div>

I just tried to get an idea why `nrgpio python command not running` happens, I thougt the status node could tell me that. But the python command is also not running when pump gets triggered correctly.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 May 2020 10:06 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/5 "2020-05-18T10:06:38Z")

</div>

> [@bjo](#):
>
> I thougt the status node could tell me that.

It can tell you some information, but you don't want to send it to the gpio node since that expect to see a 1 or 0 ot true or false. Send it to a debug node

Or are you saying you want to see the status displayed in the backend but not in the debug node?

> [@bjo](#):
>
> nrgpio python command not running

where are you seeing that?

---

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [18 May 2020 12:19 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/6 "2020-05-18T12:19:30Z")

</div>

According to the debug node, the sent numbers to the gpio node are correct. But the debug window still tells `nrgpio python command not running` and I have no clue why the python command fails.

 ![flow2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/a/1/a1cf62aac2ea7749da598527aa90164e15e3d67f.png)

---

<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:** [18 May 2020 12:35 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/7 "2020-05-18T12:35:51Z")

</div>

How did you install node-red? Did you use the recommended script from  
[https://nodered.org/docs/getting-started/raspberrypi](https://nodered.org/docs/getting-started/raspberrypi)

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [18 May 2020 12:54 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/8 "2020-05-18T12:54:38Z")

</div>

Try running `sudo apt install rpi.gpio` and restart NR and see what happens

---

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [18 May 2020 13:49 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/9 "2020-05-18T13:49:14Z")

</div>

It's already installed, `testgpio.py` from `node-red-node-pi-gpio` throws no exception.  
But running `./nrgpio out 11 1` as node-red-user throws

```auto
Traceback (most recent call last):
  File "./nrgpio.py", line 84, in <module>
    GPIO.setup(pin,GPIO.OUT)
RuntimeError: No access to /dev/mem. Try running as root!

```

So I should check the udev rules.

---

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [18 May 2020 13:53 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/10 "2020-05-18T13:53:08Z")

</div>

It's installed from AUR: [https://aur.archlinux.org/packages/nodejs-node-red/](https://aur.archlinux.org/packages/nodejs-node-red/) as also python-raspberry-gpio, node-red-node-pi-gpio was installed manually.

---

<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:** [18 May 2020 14:03 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/11 "2020-05-18T14:03:18Z")

</div>

Google suggests that error can be caused by mis-matched versions of s/w. Are you running Arch Linux rather than Raspbian?

---

<div class="post-metadata">

**Author:** ![bjo](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bjo/32/22177_2.png) [@bjo](https://discourse.nodered.org/u/bjo)\
**Post date:** [19 May 2020 07:40 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/12 "2020-05-19T07:40:54Z")

</div>

Thanks for all your help! Finally I stumpled upon [https://sourceforge.net/p/raspberry-gpio-python/tickets/115/](https://sourceforge.net/p/raspberry-gpio-python/tickets/115/), put

```auto
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="gpio", MODE="0660"
SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'"
SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:gpio /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"

```

into a udev rule and got it working. Raspbian has this rule out of box, but not Arch Linux.

---

<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:** [19 May 2020 08:36 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/13 "2020-05-19T08:36:28Z")

</div>

@bjo Did you also have to add the user to gpio group or was that already in place ?

---

<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:** [2 June 2020 08:36 UTC](https://discourse.nodered.org/t/invalid-input-nan-using-rpi-gpio/26842/14 "2020-06-02T08:36:29Z")

</div>

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