Wipy reading anemometer pulses from reed switch for wind speed
-
I'm trying to use a Wipy with an expansion board on my weather station. I have the temp, humidity and pressure all working okay but not the wind speed from an Anemometer.
This anemometer is just a cheap plastic 3 arm cup anemometer. That simply has a reed switch and a magnet to close the reed switch each revolution. I need to see how I can read the frequency of the anemometer into one of the input pins of the Wipy. Once I have the frequncy I can work out the wind speed using a mathematical formula. I don't need to read it all the time, I will just use a timer to check the wind speed every 30 seconds or so.I have been able to get it to work using an Arduino using a library called frequency_read.
Is there such a library for the Pycoms?
or if anyone knows of a i2c frequency counter that I could use then I'm happy to use additional hardware.Thanks in advance.
Regards
Richard.
-
@robert-hh
Thanks,It would help if the examples given on the pycom site actually worked rather than being utterly wrong!
Richard.
-
@Richard-Vince The method for getting the pulses is called get_pulses(), not recv_pulses().
-
@robert-hh said in Wipy reading anemometer pulses from reed switch for wind speed:
RMT.get_pulses()
Robert,
Thanks for the reply. The frequency would obviously be determined by the max wind speed. ATM I'm not sure what that could be here in Brisbane.Anyway. I looked up using RMT on https://docs.pycom.io/firmwareapi/pycom/machine/rmt/ and used the exact example on Pycoms docs shown for a Quick Usage Example: receiving
import machine
create a RMT object
rmt = machine.RMT(channel=3)
Configure RTM for receiving
rmt.init(gpio="P20", rx_idle_threshold=12000)
wait for any number of pulses until one longer than rx_idle_threshold
data = rmt.recv_pulses()
The problem is that when I go to run this on my Wipy I get this error
AttributeError: 'RMT' object has no attribute 'recv_pulses'Looking at the Methods for RMT it does not exist.
My Wipy is at following firmware level. 1.20.2.r6
-
@Richard-Vince What it the frequency range of the pulses. I guess it's from about 0.1Hz to ??. You could use RMT.get_pulses() for frequencies > 10Hz. That's pretty precise. For slower pulses you could use a Pin.IRQ and take the time between IRQ's using ticks_ms() or ticks_us(). While the interrupt is hardware, the time between the actual signal and the time taken is affected by IRQ latency, which can be large and varies a lot at an ESP32. So you have to do averaging. And the maximum frequency you can realistically get is about 500Hz. The good thing about this IRQ solution is, that it can run completely in the background and just updates a variable with the average time between pulses.