andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

False reading from Rain gauge pin

Fri Oct 21, 2016 6:16 pm

Hi guys im after a little help, Ive connected a rain gauge to my raspberry pi among other sensors and i keep getting false readings.

Using RPI.GPIO i have set up the desired pin as required,ive tried initializing both the pull up and pull down internal resistors but i still get false readings(as though the rain gauge has tipped) i have also tried both pull up and pull down resistors on a bread board and waited for both the rising and falling edges and still get false readings, Ive tried different bounce times, ive crossed both wires with a 100nf Cap , i even thought that the wifi dongle connected to the pi might might be creating "Noise" so tried it without that fitted.... STILL GET FALSE READINGS
nothing else could interfere with it as its sat in an enclosure in the middle of my garden, im at the end of me tether and out of ideas, its probably something simple????
PLEASE HELP :oops:

boyoh
Posts: 1506
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:14 pm

andyroo21 wrote:Hi guys im after a little help, Ive connected a rain gauge to my raspberry pi among other sensors and i keep getting false readings.

Using RPI.GPIO i have set up the desired pin as required,ive tried initializing both the pull up and pull down internal resistors but i still get false readings(as though the rain gauge has tipped) i have also tried both pull up and pull down resistors on a bread board and waited for both the rising and falling edges and still get false readings, Ive tried different bounce times, ive crossed both wires with a 100nf Cap , i even thought that the wifi dongle connected to the pi might might be creating "Noise" so tried it without that fitted.... STILL GET FALSE READINGS
nothing else could interfere with it as its sat in an enclosure in the middle of my garden, im at the end of me tether and out of ideas, its probably something simple????
PLEASE HELP :oops:
More information of your rain gauge is needed , Is it a wireless transmitter type, or are you just using
A reed switch to give you the signal, A circuit diagram will be us full
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:16 pm

Hi it's a reed switch variant connected to the pi via two wires

User avatar
DougieLawson
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:19 pm

Take a look at https://github.com/raspberrypi/weather- ... _daemon.py

That reads a 0.2794 ml per bucket rainfall tipper on GPIO#6

Code: Select all

self.rain = rainfall_interrupt_watcher(0.2794, 6, 300)
and publishes the results on a TCP/IP daemon.


https://github.com/raspberrypi/weather- ... _client.py and https://github.com/raspberrypi/weather- ... sensors.py is the code that reads the daemon and writes the results in a MySQL database.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

wh7qq
Posts: 1475
Joined: Thu Oct 09, 2014 2:50 am

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:26 pm

The GPIO pin is going to record a state change every time it senses a contact closure and just putting caps across the line is not going to de-bounce it adequately. Have a look at https://www.cl.cam.ac.uk/projects/raspb ... _switches/ or google "de-bounce gpio raspberry" for more suggestions.

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:50 pm

Thanks for your help guys this will surely help me out

User avatar
bensimmo
Posts: 4828
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 7:57 pm

If it's just a switch (reed or otherwise)
look at using gpiozero if you're using python https://gpiozero.readthedocs.io/en/v1.3 ... input.html
Button class and or digital input class.

boyoh
Posts: 1506
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: False reading from Rain gauge pin

Fri Oct 21, 2016 10:33 pm

andyroo21 wrote:Hi it's a reed switch variant connected to the pi via two wires
This is only a possibility of using a wireless signal from your rain gauge
Might mean a bit of hardware work, Try using a battery wireless door bell
Fit the push in the rain gauge, see if you can modify the reed switch
Wires to replace the bell push, In the bell unit see if you can find a
Connction that becomes active when the remote switch is operated.
Using a transistor or opto isolator ,to give input to a GPIO.
This might be a learning project for you..

Might work might not,,,,,,Regards BoyOh
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 8:26 am

i'm still having false readings, ive gone back to basics and heres the code that im using

Code: Select all

 #!/usr/bin/python
  import RPi.GPIO as GPIO

  pin = 6
  count = 0

  def bucket_tipped(channel):
      global count
      count = count + 1
      print (count * 0.210) #clib factor for my rain gauge

  GPIO.setmode(GPIO.BCM)
  GPIO.setup(pin, GPIO.IN, GPIO.PUD_UP)
  GPIO.add_event_detect(pin, GPIO.FALLING, callback=bucket_tipped, bouncetime=200)
pin 6 is still detecting false readings,ive tested this with the tipping bucket fixed so it cant move and i'm still getting readings
rain gauge circuit.png
rain gauge circuit.png (5.66 KiB) Viewed 3512 times
ive included a pic of the circuit too

User avatar
DougieLawson
Posts: 39796
Joined: Sun Jun 16, 2013 11:19 pm
Location: A small cave in deepest darkest Basingstoke, UK
Contact: Website Twitter

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 8:43 am

Try a 10 nF capacitor between the GPIO and GND.
Note: Any requirement to use a crystal ball or mind reading will result in me ignoring your question.

Criticising any questions is banned on this forum.

Any DMs sent on Twitter will be answered next month.
All fake doctors are on my foes list.

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 10:27 am

DougieLawson wrote:Try a 10 nF capacitor between the GPIO and GND.
just tried that and ran the code for half an hour and still detecting false readings, would upping the cap size help ?

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 10:47 am

Are the false readings switch bounce or random?

In either case you should be able to filter them out in software.

Can you see the false readings with http://abyz.co.uk/rpi/pigpio/piscope.html

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 10:54 am

joan wrote:Are the false readings switch bounce or random?

In either case you should be able to filter them out in software.

Can you see the false readings with http://abyz.co.uk/rpi/pigpio/piscope.html
it cant be switch bounce is ive wedged something underneath the tipping bucket so i know its not the switch so id class these as random, i will look into piggpio to see if that helps

User avatar
joan
Posts: 15038
Joined: Thu Jul 05, 2012 5:09 pm
Location: UK

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 11:00 am

If you can capture the bad reading you will know its duration. As long as the duration is fairly short (probable) they should be easy to filter.

boyoh
Posts: 1506
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 12:49 pm

andyroo21 wrote:
joan wrote:Are the false readings switch bounce or random?

In either case you should be able to filter them out in software.

Can you see the false readings with http://abyz.co.uk/rpi/pigpio/piscope.html
it cant be switch bounce is ive wedged something underneath the tipping bucket so i know its not the switch so id class these as random, i will look into piggpio to see if that helps
Yes start to learn the basics, I could understand , when you said you wedged
The rain tipper with card board You have no Idea of the meaning of contact bounce
What is meant is when the reed switch contacts first come to gather you can get
Mechanical tension that can cause the contact to make and brake very fast,
This can cause very fast repetitive pulses, The time length of the repetitive
Pulses can very from switch to switch, So filtering out the bounce time must be don.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 3:47 pm

boyoh wrote:
andyroo21 wrote:
joan wrote:Are the false readings switch bounce or random?

In either case you should be able to filter them out in software.

Can you see the false readings with http://abyz.co.uk/rpi/pigpio/piscope.html
it cant be switch bounce is ive wedged something underneath the tipping bucket so i know its not the switch so id class these as random, i will look into piggpio to see if that helps
Yes start to learn the basics, I could understand , when you said you wedged
The rain tipper with card board You have no Idea of the meaning of contact bounce
What is meant is when the reed switch contacts first come to gather you can get
Mechanical tension that can cause the contact to make and brake very fast,
This can cause very fast repetitive pulses, The time length of the repetitive
Pulses can very from switch to switch, So filtering out the bounce time must be don.
i totally understand what you mean, sorry if i haven't been clear enough about my problem. at the moment i have stopped the rain gauge from ever passing the magnet past the reed switch so the circuit can not be completed, But the raspberry pi is still telling me its detecting the switch being closed

Andy

User avatar
B.Goode
Posts: 10547
Joined: Mon Sep 01, 2014 4:03 pm
Location: UK

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 4:52 pm

If the switch cannot close and complete the circuit, it seems to be equivalent to having no switch at all.

So for testing, what happens if you disconnect the switch from the cabling?

And what happens if you disconnect the cabling for the switch from the header on the RPi?

wh7qq
Posts: 1475
Joined: Thu Oct 09, 2014 2:50 am

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 7:09 pm

Your schematic diagram doesn't show values for the resistors you have on the input. It also does not indicate if the reed relay is normally open or closed...many can be wired either way. In any case, on contact closure, your input goes to the level determined by the values of the two resistors. If they are equal or nearly so, the input essentially "floats" (actual value=[R1/R2]*3.3v) and noise can pull it either way. Either the "pull-up" or "pull down" resistor should be eliminated and the switch placed between the other voltage (3.3v or Gnd). My preference would be to normally pull the input high (so resistor to 3.3v) (bucket up) and to switch low when the bucket dumps. Then your software looks for the low condition for its count.
Last edited by wh7qq on Sun Oct 23, 2016 7:29 pm, edited 1 time in total.

andyroo21
Posts: 25
Joined: Mon Mar 28, 2016 6:43 pm

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 7:26 pm

wh7qq wrote:Your schematic diagram doesn't show values for the resistors you have on the input. It also does not indicate if the reed relay is normally open or closed...many can be wired either way. In any case, on contact closure, your input goes to the level determined by the values of the two resistors. If they are equal or nearly so, the input essentially "floats" and noise can pull it either way. Either the "pull-up" or "pull down" resistor should be eliminated and the switch placed between the other voltage (3.3v or Gnd). My preference would be to normally pull the input high (so resistor to 3.3v) (bucket up) and to switch low when the bucket dumps. Then your software looks for the low condition for its count.
it does 1k from 3.3 v and 10k to gnd

wh7qq
Posts: 1475
Joined: Thu Oct 09, 2014 2:50 am

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 7:33 pm

So why bother with the 10K to ground? That holds your input at just about 1.1 volts. I don't recall (in fact, neither Broadcom or Raspberry seem to publish this spec and it probably varies from Pi to Pi) the exact transition point on the input but you are setting the input level closer to it than need be so greater noise susceptibility. Use the full 3.3 volt to 0 volt range. Just put the switch across the input to ground and look for the level change. Or visa-versa. Do make sure you use the 3.3 volt rail so that you don't overload the input and fry it.

See this post for nicely drawn schematic of switched input and also a nice "debounce" script in python. https://www.cl.cam.ac.uk/projects/raspb ... _switches/
Last edited by wh7qq on Mon Oct 24, 2016 12:43 am, edited 3 times in total.

boyoh
Posts: 1506
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 7:58 pm

Is this a possibility that the moving magnet that operates the reed switch
Might be introducing a signal in to the reed switch wire leads, It is well known
Fact if moving a magnet across a copper wire, this will generate a EMF in the
Wire.
I might be right or I might be wrong.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

wh7qq
Posts: 1475
Joined: Thu Oct 09, 2014 2:50 am

Re: False reading from Rain gauge pin

Sun Oct 23, 2016 8:41 pm

boyoh wrote:Is this a possibility that the moving magnet that operates the reed switch
Might be introducing a signal in to the reed switch wire leads, It is well known
Fact if moving a magnet across a copper wire, this will generate a EMF in the
Wire.
I might be right or I might be wrong.
In principle, correct but in fact, a current is generated in the conductor and the voltage developed is proportional to the resistance it feeds as well as the flux density of the magnet and the speed at which the magnet passes the conductor. If, as the OP stated, he prevents the bucket from moving, he would have nothing generated at all by the motionless magnet.

User avatar
bensimmo
Posts: 4828
Joined: Sun Dec 28, 2014 3:02 pm
Location: East Yorkshire

Re: False reading from Rain gauge pin

Mon Oct 24, 2016 7:15 am

It look to me that you have gpio set to 3v (pull-up)
Then wired it to ground via a resistor and checking for a fall in voltage?
I would check the actual voltage at he pin, see if it not floating at the mid point somewhere.

Why no just pull the gpio down(so and it an setting to zero) wire through the swith to 3V

As I assume it normally open switches per diagram, the pin will stay at zero.
When you switch it should raise towards 3V and you detect edge up (or use gpiozero and the button option)?

Something like that, just a quick look.

Edit: to be honest I would set gpio high wire to the switch and then that to gnd.
Then detect it going low.

boyoh
Posts: 1506
Joined: Fri Nov 23, 2012 3:30 pm
Location: Selby. North Yorkshire .UK

Re: False reading from Rain gauge pin

Mon Oct 24, 2016 8:43 am

Try this Opto Isolator

5v+----------------( R/S )-------------( 300r )-----------( a opto k )----------0v-

3.3v+-----------------( 10k )-----------( gpio I/P )--------( c opto e )----------0v-

Reed switch OFF I/P 1( high ) ( R/S = Reed Switch )

Reed switch On I/P 0 ( low ) giving the I/P a active 0 ( low )

5v+ Will be better for long run to R/S in garden
Last edited by boyoh on Tue Oct 25, 2016 8:01 am, edited 2 times in total.
BoyOh ( Selby, North Yorkshire.UK)
Some Times Right Some Times Wrong

wh7qq
Posts: 1475
Joined: Thu Oct 09, 2014 2:50 am

Re: False reading from Rain gauge pin

Mon Oct 24, 2016 8:11 pm

@andyroo21:
It is strictly a designer's choice to use the input normally pulled up or down with a resistor and to short to the opposite rail when the switch closes. The software has to change accordingly. You might want to put a 1K resistor in between the relay contact and the input just in case of screw-ups. Just don't (as you have done) place a voltage divider on the input that holds it at some mid-way point between the rails. You risk trying to operate the input gate in its linear mode which is subject to noise and also will increase power consumption. Also, keep GPIO inputs far away from the 5 volt supply as a short or error choosing the resistor can fry the input. The impedance of the input is so high that the voltage drop even on the long garden run is not a factor.

Return to “Troubleshooting”