Strange signal spike to GPIO pins at startup of NodeRED (Pigpiod)

Not there. The resistor should be between the gpio out pin and 3.3V on the pi. It is to make sure the signal is high when the pin is not being actively driven low.

You are totally right, but I've got very confused on my situation. The placement of the resistor didn't make sense.

Earlier today I was about the install a first 10k resistor as a trial but I got confused (and scared to grill my RPI). So I stopped and think it is wise to first share my setup (also requested by @gerry'. I've tried to create a manual drawing (please let me know if it is not readable, in that case I'll try to create a digital version):

You see that I have installed 2 relay boards (and 3x 4-channel optocoupler boards to translate the PLC 24v signals into inputs on my GPIO, but that is working fine)

8-channel relay module
As you can see I've removed the jumper to power the board and connected a 5V external power source (because I was expecting the RPI not being able to deliver sufficient power). I've connected the VCC to the RPI 5v pin and the respective IN to the respective GPIO pins to control with NodeRED. For instance GPIO 14, 15 and 18. As you can see I didn't connect the GND. Which now looks strange, but it is already working for 3 years without problems (before I moved to NodeRED).

4-channel relay modules
This is powered a bit different, because there was no GND connection to power the board (as shown here). Again here you see I don't use the GND from the RPI

NodeRED flows
This is one example, where I'm controlling the curtains from a device in Home Assistant.

To make sure the problem was not caused by a signal from HA I've checked all ignore events at the bottom (+ checked it with a debug node as mentioned earlier):

And this is the configuration of the node controlling GPIO10

The questions are:

  • Is this setup correct, or is it explaining the spikes I'm getting?
  • How to place the pull up / down resistor to test whether this solves it. In articles I always see the pull resistor using the GND, 5V and an input pin at the RPI. But I have only two of these connected
  • Or of course: do you need more info, like the NodeRED jsons?

You must connect the grounds together. I am amazed it works without.
Don't connect the resistor to 5v, you will damage the pi. Connect it to 3.3v on the pi.
Do the relay boards have opto isolators? They should do.

Also try to avoid the dual purpose pins on the Pi. ( ones not coloured green in the node config) as they are more likely to be initialised by the operating system to a state that you don’t want. ( especially if it’s an output like TxD)

Agreed. @rik1984 you said you were using GPIO 6, now it appears to be 7,14,15,18. Don't use ones that in the image in the gpio node setup show that they have any pre-defined use.

I've sorta lost track here. Are your devices active high or active low? @Colin suggested tying the pin high with the resistor and if the device is active low I'd agree. If it's active high I'd suggest the resistor tie to ground and the pin drives it high.

Also. As @Colin says, you gotta get one ground plane across all devices.

@rik1984 . I have had a similar problem with GPIO nodes. I dropped the idea of using GPIO nodes to operate relays, instead I used 'exec" node to trigger python code to operate pinouts "sudo python /path/GPIOx.py". You may also try "Startup" with "AND" node to drop initial nuisance action/messages for a short period of time on power up. Hope this helps.

According to his link, gnd should not be connected.
But I want to wire 3.3 volts to the relay board instead of 5 volts and see if that makes a difference?

Well that link is just wrong.
[Edit] Actually I now realise I was wrong. The ground connection is redundant. The wiring in the link should be ok.

It will probably not be reliable at 3.3V. That is not enough volts to drive the photo isolating diodes on the board.

The 5V on the pi comes straight from the usb supply, so provided you have a decent PSU for the pi it should be able to drive the relay board ok. I drive an 8 relay board direct from the pi with no problems.

Actually, having thought about it some more, the resistor pull up is probably a bad idea. Since the Pi output is open collector and you are driving an opto isolator there is no need to pull it up, so it is not required.

Do you see the glitch on all your outputs? If so then that is more argument for moving to pins that do not have alternative uses.

The more I look at my own drawing the more confused I get. The strange thing is that all works!

  • The pull up / down principle is not applied, but not always a problem I think (also reading on the internet that there is an internal one on some ports in the RPI)
  • It seems that it is incorrect that I use the 5V GPIO pin to VCC as the signalling voltage. I think it should be 3.3V (but then the question is whether it is enough for this relay board to work). Risk to damage my RPI?
  • I could connect the grounds alltogether, but this way i'll be mixing up the ground of the RPI with that of the external power supply. As I have isolation between both circuits today this feels a bit risky?
  • Still I think I have active low configuration. The relays are switching when I send a 0 from NodeRED to the pin (I initialise at 1 and use a pulse of 0 and then back to 1). This seems to match with my setup, where I have the 5V-VCC connection to the relay board. And putting the GPIO pin on low creates the voltage difference to switch the relay. But maybe I'm seeing this wrong?
  • I also used the dual use pins because all other pins are already occupied by other interfaces (inputs and outputs).
  • @Colin: To anwer your question, the issue with the signal spike happens on other pins as well. For sure on pin 16 (GPIO23), pin 18 (GPIO24), pin 10 (GPIO15). Possibly also on the others on the 8ch relay board and maybe on the 4ch board as well, but this is hard to identify because of the devices behind the relay (they are not acting on a short push). What do you mean with:

Do you see the glitch on all your outputs? If so then that is more argument for moving to pins that do not have alternative uses.

I would understand it if the glitch was only in the outputs that are dual use this could be the solution. But I see the same problem at other pins. Or do you think this is because I have dual use pins in use. In that case I could test it by just temp removing these connections. But it sounds a bit odd to me.

As you know I'm not that into the electronics, does somebody have a good idea what to test?

  • Connect all the GNDs, including the external source, between GND RPI, GND of 8-ch board and GND of 4-channel board? (could this be explaining the spike?)
  • Move the VCC connection from 5V GPIO pin to 3.3V? (could this be explaining the spike?)
  • Test to turn the signal towards active high by disconnecting the 5V VCC connection and creating a GND-GND connection between the 8-ch board and RPI?

@Mansur, thanks for sharing your experience. I am thinking that there should be more people out there with the same issue. I'm really fond of using the GPIO NodeRED integration if possible. Can you elaborate what you mean with:

You may also try "Startup" with "AND" node to drop initial nuisance action/messages for a short period of time on power up. Hope this helps.

BTW, my drawing is a simplified version of the real situation. I have all pins in use. The first print screen was indeed about GPIO6, but I also use 7,14,15,18 and others

For a small sum you may be better off using something like this, it provides 16 additional GPIO pins rather than connecting things to the Pi directly.

Or better still, don't use a Pi for GPIO. Too much hassle. Use a microprocessor board instead, a few $$ will get you an ESP32 which has its real-time OS and can be programmed via Arduino IDE or ESPhome, MicroPython or even Node-RED MCU. Wi-Fi connected and output direct to MQTT.

For a couple of bucks try a 10uF tantalum cap between your pins and a good ground. Both on the pi and on the relay boards or whatever you are driving. Don't know where you are but I keep a handful in my junk drawer for situations as this. May not work, but then again it may.

The OP has not shown the relay board they are using, other than to say the relays are active low. There are versions of the board that have separate grounds and if the Vcc - JD-Vcc link is removed the opto output transistor / relay coil can be operated from a different voltage to the pi. If, say, a separate 5 volt supply is used to drive the relays connected to JD-Vcc (link removed) and the relay ground pin is connected to the relay power supply ground. Then the pi 3.3 v is connected to relay board Vcc, when the pi turns its output pin low the opto led will light up thus energising the relay. This provided galvanic isolation between the pi and the relay power supply because the grounds are not commoned. The article posted above is correct for boards configured as described above. I use this type of relay board with ESP devices and they work exactly as I have described. The IN pins on the relay board are the opto LED cathodes.

@bobcroft You are right, I'm using both the
HW-316 - 4 channel

And HW-281 - 8 channel

I think they are both isolated and indeed by not connecting the ground I think it is still isolated in my setup.

Reading your message I think it is worth a try to change the 5V to VCC connection to 3.3V to VCC connection. This is working for you? I'm not sure whether this solves my problem with NodeRED but at least it is a better solution. You don't use the GNDs to pull up/down?

Hi @gerry , is this the setup you are aiming for?

I could test this with one of the GPIO pins. This will also mean moving from 5V to 3.3V (or I could keep VCC on 5V) and connecting the grounds, which will break the isolation of the board as I understood that both GND pins on the relay board are connected. Thanks for your offer out of your junk drawer, I live in NL but I could easily order them online.

I just found out that the spike is happening on ALL GPIO output pins to both relay boards I have. By disabling all outputs in NodeRED, rebooting the RPI and one-by-one enabling the outputs I can even see the respective LED on the relay board shortly blinking as soon as it is activated in NodeRED. It is still funny it only happens the first time after a reboot (possibly when NR takes over the control of this GPIO pin)

Thanks btw for the other suggstions, like the GPIO expansion board and the microprosessor board based on ESP32. Is this the type you mean? https://nl.aliexpress.com/item/1005004987481682.html?gatewayAdapt=glo2nld Or of course to go for the Modbus PLC module which is a bit more expensive but I think the cleanest option

Does your PLC have serial Modbus? If so then you could use that and do away with the relays.

Alternatively, why not do away with the PLC altogether and do it all in the Pi?