I built a RFM69 hat for a Raspberry Pi 3 B+. It works perfectly as long as I do not use the GPIO to switch on the relay that drives a solenoid valve. Unfortunatelly a lot of times the switching cause the radio module to get stuck and I have to reset it, destroying the Radio object, to make it work again.
This is the global schematic:
Looking at the schematic of the relay module it seems that the GPIO should not be disturbed by the relay switching. I tried to power the radio module with a battery, but the problem remains. The RPI seems to be unaffected by the switching: nothing is reported in the logs. Maybe something gets wrong on the SPI bus or a sudden spike in the relay can disturbe the radio module? From the schematic of breakout board I see two bypass capacitors that should protect the module from noise.
I tried to detect the change of the pins 11 and 12 from the process controlling the radio module (which is different from the one that controls the relay) in order to reset the radio. It is not very realiable though, because sometimes the event is not fired (?). Maybe there is a more clever solution? It seems to me that the python library for the RFM69 does not expose a method to poll if the radio is working.
Edit1: if the valve is disconnected the radio module works properly.
Edit2: from the tests that I made it seems that the transformer is not doing a fair job with the noise coming in the RPI and the RF module. I am thinking to build a small board with a pair of big capacitors, say 470uF, in parallel with the supply of each device. I believe that the noise frequency should be low so the big capacity needed. I could leave space for a few smaller capacitors to put in parallel for the higher frequencies. Could it be a good idea?
Edit3: I’ve built this board but it is still not working!
Edit4: I've just bought an oscilloscope and this is what I see when the solenoid valve opens:
With my brand new oscilloscope I discovered that there is a lot of noise in the line. I bought a new Mean Well power supply (RS-25-5) and it does a great job reducing the noise but unfortunatelly is not enought! I'll try with an EMI filter (CW1B-10A-L). Let's see what happens.
Update: I’ve discovered that when the radio module gets stuck, the register RegRssiThresh changes to 0xFF. Now I check every second if the register has this value and in this case a reset of the radio module solves the problem.
Main components:
Connections to RPI:
Hat:
Power and relays connections (note the lack of the ground connection on the power supply. Could it be the cause of high interferences?):