Morner1234
Posts: 8
Joined: Mon Jan 13, 2020 7:25 am

Using a pulse counter on a Raspberry Pi, weird problem

Wed Jun 17, 2020 10:10 pm

Raspberry Pi starts to count pulses when I just add a cable to the gpio, it is not connected to anything else. Literally just the gpio to air. Some cables don't make it count pulses and other do, I also dont touch the cables when this happens and they dont touch any metal or anything else.

I am using a water flow sensor with the following code and deviders: https://youtu.be/wpenAP8gN3c

It worked for almost 2 months, I then left it and came back to it after +- 3 months and now all of a sudden this happens.

It would just count pulses without me even letting water run through it. I then started looking for the problem and saw that it counts without even being connected to anything, when I removed the wire completely it went away. But some wires does not alwayse trigger the pulses like others do.

pidd
Posts: 302
Joined: Fri May 29, 2020 8:29 pm
Location: Wirral, UK
Contact: Website

Re: Using a pulse counter on a Raspberry Pi, weird problem

Wed Jun 17, 2020 11:25 pm

Have you got resistors on the input pins like the youtube describes?

Morner1234
Posts: 8
Joined: Mon Jan 13, 2020 7:25 am

Re: Using a pulse counter on a Raspberry Pi, weird problem

Thu Jun 18, 2020 6:37 am

pidd wrote:
Wed Jun 17, 2020 11:25 pm
Have you got resistors on the input pins like the youtube describes?
Yes, exactly the same.

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Using a pulse counter on a Raspberry Pi, weird problem

Thu Jun 18, 2020 6:57 am

"gpio to air" is an antenna. It can pick up interference that might trigger the counting.
Some lengths of cable may be more sensitive to the interference than others.
Separation between the signal and ground wires creates a loop that will be more susceptible to interference.
What happens if you connect the signal and ground wires at the end of the open cable?
Check for a broken ground wire/connection .
Is there any electrical equipment nearby that wasn't there, or wasn't running when the system was working well?
Try turning appliance off to see if it makes a difference.

Generally:
Keep wires short.
Keep signal and ground wires together and the same length
Connect ground wires to one central point rather than chaining them between different devices.
Use screen cable with the screen connected to ground at one end.

Morner1234
Posts: 8
Joined: Mon Jan 13, 2020 7:25 am

Re: Using a pulse counter on a Raspberry Pi, weird problem

Thu Jun 18, 2020 7:23 am

PiGraham wrote:
Thu Jun 18, 2020 6:57 am
"gpio to air" is an antenna. It can pick up interference that might trigger the counting.
Some lengths of cable may be more sensitive to the interference than others.
Separation between the signal and ground wires creates a loop that will be more susceptible to interference.
What happens if you connect the signal and ground wires at the end of the open cable?
Check for a broken ground wire/connection .
Is there any electrical equipment nearby that wasn't there, or wasn't running when the system was working well?
Try turning appliance off to see if it makes a difference.

Generally:
Keep wires short.
Keep signal and ground wires together and the same length
Connect ground wires to one central point rather than chaining them between different devices.
Use screen cable with the screen connected to ground at one end.
This makes sense, thank you. There is 2 new power supplies next to it (one on each side) in an electric box.

Is there any remedy for this? I can't change to the design of the electric box. The one power supply is 5v and the other 12 which powers the 2 pumps and 1 solenoid.

PiGraham
Posts: 3929
Joined: Fri Jun 07, 2013 12:37 pm
Location: Waterlooville

Re: Using a pulse counter on a Raspberry Pi, weird problem

Thu Jun 18, 2020 8:00 am

One I forgot to mention. Keep small signal wires and power wires separated.

First try it away from possible interference (or turn those off to test)
You may need to use screen cable and perhaps put the Pi in a metal box with the cable screens connecting to the box to form a shield over the entire low voltage signal path. A diecast box and metal EMC cable glands is probably easiest or you could improvise ways to connect cable braid to the metal box.

You can also try opto isolators to isolate different circuits electrically. You may need additional power supplies.
You tcould ry differential signalling using driver and receiver chips RS422 is one standard

You could put a Wi-Fi enabled device right on the sensor to do the counting and send the count wirelessly to another device to control the switchgear.

If one piece of equipment is the main culprit you might be able to quieten that. But it's not simple to do. Check earths are good. Maybe fit EMC suppression filters. Simplest, but more a roll of the dice than a strategy, try alternate devices that (CE marked).

It really is a complex subject

Return to “Troubleshooting”