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
So I converted to km/hr below and I think my math is ok.Converting pulses to wind speed is simple using the following formula:
2.5 mph per Hz (1 Hz = 1 pulse/second)
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
Code: Select all
GPIO.setFunction(5, GPIO.IN)
i think you need to add a pulldown resistor to the circuit, otherwise the GPIO is floating and you read unset levels.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:
Do I need a resistor in the line? Don't want to damage my Pi.Code: Select all
GPIO.setFunction(5, GPIO.IN)
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 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.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)
If lightening strikes your weather station hardware, a fuse won't help. Your Pi and everything connected to it will likely be wrecked.pumpkinpi wrote:Do I need to be concerned about lightning strikes? Do I need a fuse in the line to protect the Pi?
pumpkin
I have no intention of winning a Darwin award.davidcoton wrote:Oh, and NEVER work on your weather station when lightening is anywhere near.
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 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.
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).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.
i'll make good use of thatdavidcoton wrote:(This is what pattagghiu was suggesting above, +1 credit).
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
Code: Select all
GPIO.setFunction(5, GPIO.IN, GPIO.PUD_UP)
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.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