I have a working Python script for determining wind speed, my problem is that I cannot translate it into a working uPython script. I remember having similar problems when I began the Python project about 10 years ago, but ultimately was able to work it out. I have found examples of code that count button presses, but have not been able to translate that into anything useful.
If someone can point me in the right direction, I can to the lifting. Either modifying what I had or maybe measuring pulse time to get RPM (so far also unsuccessful)?
Below is the Python code that works on the Rpi, but not with MicroPython. Board is an ESP8266 (ESP-WROOM-02U).
Input is wired between 3v3 & Pin13 w/4k7 pull-down and the button is a momentary reed switch.
Descriptively: Pin13 is tied low via 4k7, until the reed switch closes the connection to 3v3 at which time I get a high pulse. I verified this and can toggle the value() between 1 & 0 with rotation.
Code: Select all
#BEGIN - Wind Speed in MPH # # DOES NOT WORK on uPython :( from machine import Pin from time import sleep import math calibration = 1.18 #0.765 #assumes WS.py is accurate and duplicates reading in MPH count = 0 interval = 0.5 # How often to report speed 5 > 0.5 WS = 0 miles_per_hour = 0 def spin(): global count count = count + 1 wind_speed_sensor = Pin(13) #Input on Pin#13 def main(): sleep(interval) WS1 = calibration * (count/interval) WS2 = WS1 * 1.609344 #print " Wind Speed = %.2f" % WS2, "/ %.2f" % WS1 print("Wind Speed = %.2f") %WS1 main()