# GPIO on Raspberry Pi are stopped

**URL:** <https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053>\
**Category:** General\
**Created:** [13 July 2022 13:25 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053 "2022-07-13T13:25:13Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [13 July 2022 13:25 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/1 "2022-07-13T13:25:13Z")

</div>

What happens to GPIO on Raspberry Pi?  
I am attaching three images generated within three four minutes. Is there any explanation?  
Everything happens after a clean install.  
 ![what_is_this](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/b/3/b3881c884d10d7d28d8270d6a3d61145cdb61285.png)  
 ![what_is_this2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/0/606f48d9968f912031cff0aa98cbc4202de8e9ff.png)  
 ![what_is_this3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/1/6/165a301614b65bb46d84b6f23fc1fe13a0b534c7.png)

---

<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:** [13 July 2022 14:01 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/2 "2022-07-13T14:01:29Z")

</div>

What is connected to this pins?  
Do you have SPI active on the Pi?  
Update: I have two pi's one with a sensehat and the other without. On the one with the sense hat, I get the same issue as you do. On the onw without a hat, no problem exists.

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [13 July 2022 17:18 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/3 "2022-07-13T17:18:27Z")

</div>

There are optocouplers connected to the pins, the pins have internal pullup resistors. I have fresh installed Dietpi latest version and Node red latest version, I've been using this scheme for years and never had a problem until now. I noticed this effect about a month ago. I notice in the forum that this problem is not from yesterday. Whether there is something connected to the pin is not important in my opinion, this thing should work. Please help.  
Greetings.

---

<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:** [13 July 2022 19:31 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/4 "2022-07-13T19:31:32Z")

</div>

> [@devifast](#):
>
> I have fresh installed Dietpi latest version and Node red latest version, I've been using this scheme for years and never had a problem until now. I noticed this effect about a month ago.

So did this show up after the update of diet or Node-RED?  
Which version of Node-RED and node.js are you using? (you can get this from the startup log)

> [@devifast](#):
>
> I notice in the forum that this problem is not from yesterday.

Can you explain this and/or point to threads you a referring to?

As a test, can you take the optocoupler off the pins to see what happens?

I do not have Dietpi installed and can only tell you what I am seeing on two different Pi's that I have but I'm running Raspbian on both.

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 07:49 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/5 "2022-07-14T07:49:23Z")

</div>

I did the following thing. I unpacked a brand new Raspberry Pi Zero W2 and installed a fresh copy of Dietpi and Node red but the problem remained. I am convinced that the problem is somewhere in the software, because as I mentioned before, this bug did not exist.

---

<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 July 2022 07:52 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/6 "2022-07-14T07:52:43Z")

</div>

Please stop node red and restart it in a terminal. Leave the terminal open and wait for the error to appear. Then copy/paste the full terminal output (not screenshot) and paste it here. Use the `</>` button at the top of the forum entry window when pasting it.

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 07:57 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/7 "2022-07-14T07:57:07Z")

</div>

How do I run it in a terminal? I'm asking for more detailed instructions because I'm not an expert.  
Thanks.

---

<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:** [14 July 2022 08:01 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/8 "2022-07-14T08:01:27Z")

</div>

SSH into the pi nd run

```auto
node-red-stop
node-red

```

that should stop and start node-red

Keep in mind that this may be an issue with with the laatest version of DietPi

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 08:10 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/9 "2022-07-14T08:10:55Z")

</div>

I did it. With Dietpi, the commands are slightly different, I stopped, then started, the terminal is constantly open on one monitor and on the other it is Node red. On the tenth deploy the error appeared again and nothing happened in the terminal.

 ![restart](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/c/f/cf1b30a3531324660770e41319a97837cbea7603.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:** [14 July 2022 08:12 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/10 "2022-07-14T08:12:45Z")

</div>

Please note my previous post which said

> [@Colin](#):
>
> Then copy/paste the full terminal output (not screenshot) and paste it here. Use the `</>` button at the top of the forum entry window when pasting it.

Also the command you have used starts it as a service so the node red log is not shown. Did the command  
`node-red`  
as suggested, not work?

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 08:20 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/11 "2022-07-14T08:20:55Z")

</div>

```auto
root@DietPi:~# node-red
-bash: node-red: command not found
root@DietPi:~# node red
node:internal/modules/cjs/loader:959
  throw err;
  ^

Error: Cannot find module '/root/red'
    at Module._resolveFilename (node:internal/modules/cjs/loader:956:15)
    at Module._load (node:internal/modules/cjs/loader:804:27)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
    at node:internal/main/run_main_module:17:47 {
  code: 'MODULE_NOT_FOUND',
  requireStack: []
}

Node.js v18.6.0
root@DietPi:~#

```

---

<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 July 2022 08:39 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/12 "2022-07-14T08:39:09Z")

</div>

In that case node-red was not installed using what I believe is the recommended way for diet pi. [Running on Raspberry Pi : Node-RED](https://nodered.org/docs/getting-started/raspberrypi)

How did you install it?

You may be able to use journalctl to access the node-red log, but I don't use diet pi so maybe something like  
`sudo journalctl -f -n 100 -u nodered -o cat`

or maybe  
`sudo journalctl -f -n 100 -u node-red -o cat`

---

<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:** [14 July 2022 08:45 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/13 "2022-07-14T08:45:23Z")

</div>

The dietPi installs things differently... do NOT try to use the default script... it will make things worse not better.

Well actually the install script should detect dietpi and add just add the extra commands - (but that is all it does) - to see the log the command required is `journalctl -f -n 100 -u node-red -o cat`  
(note the slightly different service name node-red vs nodered)

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 08:52 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/14 "2022-07-14T08:52:30Z")

</div>

> [@dceejay](#):
>
> journalctl -f -n 100 -u node-red -o cat

```auto
root@DietPi:~# journalctl -f -n 100 -u node-red -o cat
14 Jul 10:40:42 - [info] Stopping flows
14 Jul 10:40:42 - [info] Stopped flows
14 Jul 10:40:42 - [info] Starting flows
14 Jul 10:40:43 - [info] Started flows
14 Jul 10:40:46 - [info] Stopping flows
14 Jul 10:40:46 - [info] Stopped flows
14 Jul 10:40:46 - [info] Starting flows
14 Jul 10:40:47 - [info] Started flows
Stopping Node-RED (DietPi)...
14 Jul 10:59:04 - [info] Stopping flows
14 Jul 10:59:04 - [red] Uncaught Exception:
14 Jul 10:59:04 - [error] Error: write EPIPE
    at afterWriteDispatched (node:internal/stream_base_commons:160:15)
    at writeGeneric (node:internal/stream_base_commons:151:3)
    at Socket._writeGeneric (node:net:873:11)
    at Socket._write (node:net:885:8)
    at writeOrBuffer (node:internal/streams/writable:392:12)
    at _write (node:internal/streams/writable:333:10)
    at Writable.write (node:internal/streams/writable:337:10)
    at GPIOInNode.<anonymous> (/mnt/dietpi_userdata/node-red/node_modules/node-red-node-pi-gpio/36-rpi-gpio.js:111:34 )
    at /mnt/dietpi_userdata/node-red/node_modules/@node-red/runtime/lib/nodes/Node.js:329:34
    at new Promise (<anonymous>)
node-red.service: Main process exited, code=exited, status=1/FAILURE
node-red.service: Failed with result 'exit-code'.
Stopped Node-RED (DietPi).
node-red.service: Consumed 1min 7.543s CPU time.
Started Node-RED (DietPi).
14 Jul 10:59:38 - [info]
Welcome to Node-RED
===================
14 Jul 10:59:38 - [info] Node-RED version: v2.2.2
14 Jul 10:59:38 - [info] Node.js version: v18.6.0
14 Jul 10:59:38 - [info] Linux 5.15.32-v7+ arm LE
14 Jul 10:59:40 - [info] Loading palette nodes
14 Jul 10:59:43 - [info] Settings file : /mnt/dietpi_userdata/node-red/settings.js
14 Jul 10:59:43 - [info] Context store : 'default' [module=memory]
14 Jul 10:59:43 - [info] User directory : /mnt/dietpi_userdata/node-red
14 Jul 10:59:43 - [warn] Projects disabled : editorTheme.projects.enabled=false
14 Jul 10:59:43 - [info] Flows file : /mnt/dietpi_userdata/node-red/flows.json
14 Jul 10:59:44 - [info] Server now running at http://127.0.0.1:1880/
14 Jul 10:59:44 - [warn]
---------------------------------------------------------------------
Your flow credentials file is encrypted using a system-generated key.
If the system-generated key is lost for any reason, your credentials
file will not be recoverable, you will have to delete it and re-enter
your credentials.
You should set your own key using the 'credentialSecret' option in
your settings file. Node-RED will then re-encrypt your credentials
file using your chosen key the next time you deploy a change.
---------------------------------------------------------------------
14 Jul 10:59:44 - [info] Starting flows
14 Jul 10:59:44 - [info] Started flows
14 Jul 11:00:09 - [info] Stopping flows
14 Jul 11:00:09 - [info] Stopped flows
14 Jul 11:00:09 - [info] Starting flows
14 Jul 11:00:10 - [info] Started flows
14 Jul 11:00:13 - [info] Stopping flows
14 Jul 11:00:13 - [info] Stopped flows
14 Jul 11:00:13 - [info] Starting flows
14 Jul 11:00:14 - [info] Started flows
14 Jul 11:00:19 - [info] Stopping flows
14 Jul 11:00:19 - [info] Stopped flows
14 Jul 11:00:19 - [info] Starting flows
14 Jul 11:00:20 - [info] Started flows
14 Jul 11:00:23 - [info] Stopping flows
14 Jul 11:00:23 - [info] Stopped flows
14 Jul 11:00:23 - [info] Starting flows
14 Jul 11:00:24 - [info] Started flows
14 Jul 11:00:27 - [info] Stopping flows
14 Jul 11:00:27 - [info] Stopped flows
14 Jul 11:00:27 - [info] Starting flows
14 Jul 11:00:28 - [info] Started flows
14 Jul 11:00:32 - [info] Stopping flows
14 Jul 11:00:32 - [info] Stopped flows
14 Jul 11:00:32 - [info] Starting flows
14 Jul 11:00:33 - [info] Started flows
14 Jul 11:00:36 - [info] Stopping flows
14 Jul 11:00:36 - [info] Stopped flows
14 Jul 11:00:36 - [info] Starting flows
14 Jul 11:00:36 - [info] Started flows
14 Jul 11:00:39 - [info] Stopping flows
14 Jul 11:00:39 - [info] Stopped flows
14 Jul 11:00:40 - [info] Starting flows
14 Jul 11:00:40 - [info] Started flows
14 Jul 11:00:44 - [info] Stopping flows
14 Jul 11:00:44 - [info] Stopped flows
14 Jul 11:00:44 - [info] Starting flows
14 Jul 11:00:44 - [info] Started flows
14 Jul 11:00:47 - [info] Stopping flows
14 Jul 11:00:47 - [info] Stopped flows
14 Jul 11:00:47 - [info] Starting flows
14 Jul 11:00:48 - [info] Started flows
14 Jul 11:19:10 - [info] Stopping flows
14 Jul 11:19:10 - [info] Stopped flows
14 Jul 11:19:10 - [info] Starting flows
14 Jul 11:19:11 - [info] Started flows
14 Jul 11:19:39 - [info] Stopping flows
14 Jul 11:19:39 - [info] Stopped flows
14 Jul 11:19:39 - [info] Starting flows
14 Jul 11:19:40 - [info] Started flows

```

The command is correct, but the error does not appear in the terminal, it only starts and stops flow after deploy .

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 09:02 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/15 "2022-07-14T09:02:39Z")

</div>

![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/9/f9658a07a26bb4101db6e809af5ea9ce70a3d932.png)  
 ![image](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/6/1/61368e88c0e2c4639bf18eed9c34572f050d08bd.png)  
This is the result in both windows.

---

<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 July 2022 09:03 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/16 "2022-07-14T09:03:45Z")

</div>

> [@devifast](#):
>
> the error does not appear in the terminal, it only starts and stops flow after deploy .

Do you mean that at, for example, 11:19, the Stopped error was showing in the editor, but does not show in the log? In which case I am out of ideas. You might need to ask on a diet pi forum, unless someone here has other suggestions.

---

<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:** [14 July 2022 09:45 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/17 "2022-07-14T09:45:56Z")

</div>

OK - I have just installed latest dietpi - done an update - added Node-RED and installed the gpio nodes... I have added 8 GPIO input nodes and so far it seems rock solid... What else do I need to do to replicate this error ?  
Do you have  
a) any more to the flow than just the gpio pins ?  
b) any other software installed ?  
c) any other dietpi config we need to know about ?

---

<div class="post-metadata">

**Author:** ![devifast](https://avatars.discourse-cdn.com/v4/letter/d/43a26b/32.png) [@devifast](https://discourse.nodered.org/u/devifast)\
**Post date:** [14 July 2022 09:54 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/18 "2022-07-14T09:54:57Z")

</div>

There is nothing else. Only Dietpi Bullseye 32bit and 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:** [14 July 2022 16:43 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/19 "2022-07-14T16:43:11Z")

</div>

OK - I think I can replicate - it seems to occur very occasionally if you keep deploying rapidly. Having added some debug I am now somewhat confused... I can see all the nodes calling their close and closing ok - then restarting... and then randomly one of the already closed pins gets a second close event and closes itself... so... net is this could take a while to debug as it's somewhat non-obvious how this could occur.

---

<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:** [14 July 2022 18:02 UTC](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053/20 "2022-07-14T18:02:04Z")

</div>

I may have got a handle on it - pushed version 2.0.5 to npm - give it a whirl.

[Next page](https://discourse.nodered.org/t/gpio-on-raspberry-pi-are-stopped/65053.md?page=2)
