GPIO on Raspberry Pi are stopped

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 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.

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.

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)

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.

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.

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.

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

SSH into the pi nd run


that should stop and start node-red

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

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.

Please note my previous post which said

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

root@DietPi:~# node-red
-bash: node-red: command not found
root@DietPi:~# node red
  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 {
  requireStack: []

Node.js v18.6.0

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

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

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)

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
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 .

This is the result in both windows.

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.

1 Like

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 ?

There is nothing else. Only Dietpi Bullseye 32bit and Node red.

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.

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