## Anemometer

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

That one looks really good. I like the way it can be scaled (or calibrated) already. It is likely not that accurate, but probably close enough for my purposes.

Need to figure out what debouncing means.

pumpkin

davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Anemometer

"Debouncing" is a technique in hardware or software to make sure that contact bounce (on closing or more rarely opening) is not detected as multiple pulses. Search for it to find detailed methods.
Signature retired

DougieLawson
Posts: 36515
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK

### Re: Anemometer

Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

Awesome. Thanks folks. I will report back in ~5 months when I have this working. (yes, this is a hobby).

pumpkin

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

Well, my anemometer arrived in short order from InSpeed. It is very well constructed. Very impressed.

Have written a short python function (as part of my weather station program) that calculates wind speed.

The website says this:
Converting pulses to wind speed is simple using the following formula:
2.5 mph per Hz (1 Hz = 1 pulse/second)
So I converted to km/hr below and I think my math is ok.

I have done some basic desk counting over the 20 seconds that I am taking a measurement and it seems to count reasonably well.

I would be interested in some other ideas to do debouncing. I wanted to detect wind speeds up to 80 km/hr which would be about 20 Hz, so that is where I came up with that sleep timer of 0.05 seconds (1/20). Does this seem reasonable?

I used a For loop that seems to run for about 20 seconds given the little 0.01 sleep timer in there. While doing this, it is looking for switch activations.

Code: Select all

``````def get_WindSpeed():
global T, wind_speed
wind_speed = 0
try:
if T == 8:
count = 0
time_start = time.time()
print ("Start wind speed check.")
for x in range (1000):
if GPIO.digitalRead(5) == 0:
webiopi.sleep(0.05)
if GPIO.digitalRead(5) == 1:
count += 1
webiopi.sleep(0.01)
time_stop = time.time()
wind_speed = 4.02336 * (count / (time_stop - time_start))
T +=1
return wind_speed
except Exception as e:
print (e)
print("Something messed up with wind script")
pass
``````
Thanks,
pumpkin

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

I have another question. The way I wired this up is to simply connect 3.3V to one side of the switch and the other side to GPIO pin 5. I am using webiopi which I like. I allows easy integration to a webpage. I have this line further up in my code to make sure the GPIO is in IN mode:

Code: Select all

``GPIO.setFunction(5, GPIO.IN)``
Do I need a resistor in the line? Don't want to damage my Pi.

Even when the anemometer is not turning, I get counts. Any idea where those are coming from? I could try hardware debouncing, but I prefer the soft approach.

pumpkin

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

### Re: Anemometer

pumpkinpi wrote:I have another question. The way I wired this up is to simply connect 3.3V to one side of the switch and the other side to GPIO pin 5. I am using webiopi which I like. I allows easy integration to a webpage. I have this line further up in my code to make sure the GPIO is in IN mode:

Code: Select all

``GPIO.setFunction(5, GPIO.IN)``
Do I need a resistor in the line? Don't want to damage my Pi.

Even when the anemometer is not turning, I get counts. Any idea where those are coming from? I could try hardware debouncing, but I prefer the soft approach.

pumpkin
i think you need to add a pulldown resistor to the circuit, otherwise the GPIO is floating and you read unset levels.
With a pulldown, when the circuit is open you'll read LOW, when the circuit is closed you'll read HIGH since it will be connected to 3,3V

You can use the integrated pi pullup/down

And you can setup the circuit even in "opposite" mode: gnd to one side, gpio on the other and a pullup on the gpio.

In your case you'll want to sense a rising edge
in the second you'll want to sense a falling edge

Btw, software debouncing when managing interrupts is always well done

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

### Re: Anemometer

Sorry man, i gave a look to you code.
You are waiting for something to happen (a state change of the input gpio).
I don't think a for loop with a sleep inside is the right choice
Please give a look to interrupts managing on gpio.. (for example, the "software debouncing" page posted by Dougie)

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

Do I need to be concerned about lightning strikes? Do I need a fuse in the line to protect the Pi?

pumpkin

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

pattagghiu wrote:Sorry man, i gave a look to you code.
You are waiting for something to happen (a state change of the input gpio).
I don't think a for loop with a sleep inside is the right choice
Please give a look to interrupts managing on gpio.. (for example, the "software debouncing" page posted by Dougie)
I am using the loop with the sleep inside as a form of debouncing the circuit. I know the desired sensing frequency, so I used that as a means of determining how much debounce I could put in there. It seems to work, but maybe I am missing something.

I am not clear on how I would wire in the resistor. I will have to do some more research on that one.

pumpkin.

davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Anemometer

pumpkinpi wrote:Do I need to be concerned about lightning strikes? Do I need a fuse in the line to protect the Pi?

pumpkin
If lightening strikes your weather station hardware, a fuse won't help. Your Pi and everything connected to it will likely be wrecked.

You can provide some protection with a lightening conductor as the highest part of the weather station. Connect it to earth with a heavy metal strap, as used for building protection. "Earth" in this context is a copper rod sunk into the ground. Keep the lightening connection well away from the RPi connections. Lightening may still cause serious damage. If you are in a high risk area, seek advice from a local protection expert. There are specialist lightening arrestors that protect power lines and phone lines, you may need to explore that route. (I have only been involved on the fringes of providing and inspecting protecting for a church building. There is a lot of conflicting advice around. But if you get a direct strike, your Pi will fry.)

Oh, and NEVER work on your weather station when lightening is anywhere near.
Signature retired

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

davidcoton wrote:Oh, and NEVER work on your weather station when lightening is anywhere near.
I have no intention of winning a Darwin award.

http://www.darwinawards.com/

davidcoton
Posts: 4243
Joined: Mon Sep 01, 2014 2:37 pm
Location: Cambridge, UK

### Re: Anemometer

pumpkinpi wrote:
I am using the loop with the sleep inside as a form of debouncing the circuit. I know the desired sensing frequency, so I used that as a means of determining how much debounce I could put in there. It seems to work, but maybe I am missing something.
Try it, if it works, it's good. Really you need an oscilloscope to see what you are getting and whether your delay will fix it. If your highest frequency is 20Hz, the debounce period should probably be less than 25ms (less than half a cycle). I seem to remember from engineering days long ago that the debounce period was usually about 1ms, but I may be mistaken.
pumpkinpi wrote: I am not clear on how I would wire in the resistor. I will have to do some more research on that one.
Use the Pi's internal pull up, activated in software (when your program initialises the hardware). Then connect the anemometer contact between the Pi input and ground. It's a safer way round than taking 3V3 out to the contact. No incoming series resistor is required. (This is what pattagghiu was suggesting above, +1 credit).
Signature retired

Massi
Posts: 1691
Joined: Fri May 02, 2014 1:52 pm
Location: Italy

### Re: Anemometer

davidcoton wrote:(This is what pattagghiu was suggesting above, +1 credit).
i'll make good use of that

pumpkinpi
Posts: 141
Joined: Fri Apr 18, 2014 7:11 pm

### Re: Anemometer

After monkeying around a bit, I think I have a script that includes debounce and that works reliably. I think I need to take the anemometer for a drive to check calibration, but this gives me a reasonable idea of speed, which was the intent of this mini-project for me.

Code: Select all

``````def get_WindSpeed():
global T, wind_speed
wind_speed = 0
try:
if T == 8:
count = 0
time_start = time.time()
print ("Start wind speed check.")
all_ok = True
while all_ok:
if GPIO.digitalRead(5) == 1:
webiopi.sleep(0.01)
if GPIO.digitalRead(5) == 0:
count += 1
if (time.time() - time_start) >= 15:
all_ok = False
time_stop = time.time()
wind_speed = 4.02336 * (count / (time_stop - time_start))
print ("Wind speed: " + str(wind_speed) + " km/hr")
if wind_speed < 1:
wind_speed = 0
print ("Wind speed: " + str(wind_speed) + " km/hr")
print ("Time: " + str(time_stop - time_start) + " s")
print ("Frequency: " + str(count/(time_stop - time_start)) + " Hz")
print ("Count: " + str(count))
T +=1
return wind_speed
except Exception as e:
print (e)
print("Something messed up with wind script")
pass
``````
I changed my circuit around so that the reed switch is between the ground and the GPIO #5. I have this line in the setup:

Code: Select all

``````GPIO.setFunction(5, GPIO.IN, GPIO.PUD_UP)
``````
Thanks for all the help here.

pumpkin

jbeale
Posts: 3511
Joined: Tue Nov 22, 2011 11:51 pm
Contact: Website

### Re: Anemometer

boyoh wrote:One option for the wind speed indicator is to use a slotted disc spinning through slotted Opto Isolator , very little mechanical drag on the shaft , A noise free clean pulse to feed in to the GPIO in/put to be counted and calibrated
I think this could work well. How long it works outside will depend on how well the enclosure protects the opto detector and whatever bearing you use (simple pivot?) from the effects of rain / snow / dust.

scruss
Posts: 2615
Joined: Sat Jun 09, 2012 12:25 pm
Location: Toronto, ON
Contact: Website

### Re: Anemometer

Incidentally, the very nice (read: ££££) Vector Instruments anemometers use photochoppers. They are extremely carefully finished though. Considering they were originally designed to measure and model potentially lethal biohazard plumes from Porton Down, they kind of have to be sensitive.
‘Remember the Golden Rule of Selling: “Do not resort to violence.”’ — McGlashan.

grompot
Posts: 19
Joined: Tue Jan 09, 2018 12:02 am

### Re: Anemometer

You can use the sensirion SDP810 125 PA or 500 PA Flow sensors. It is extremly accurate and have no moving parts.

Check my project at https://www.instructables.com/id/Handhe ... r-Station/
Also check python code at https://github.com/JJSlabbert/Sensirion_SDP810