|
1 |
| -# WeatherMeters |
| 1 | +# Weather Meters |
| 2 | +Arduino library for processing wind speed, wind wane and rain gauge sensors (WH 1080, Sparkfun) |
| 3 | + |
| 4 | +It's interupt based library with callbacks and ready to use on any board. The only difference accros boards would be in initializing 1 second timer, ie. on STM32 you could use RTC timer, ESP32 has its own timer object, Timer1 could be used Arduino Uno (ATmega328P) etc. |
| 5 | + |
| 6 | +# Example on STM32 platform |
| 7 | + |
| 8 | +```cpp |
| 9 | +#include <RTClock.h> |
| 10 | +#include "WeatherMeters.h" |
| 11 | + |
| 12 | +#define anemometer_pin PB12 |
| 13 | +#define windvane_pin PB1 |
| 14 | +#define raingauge_pin PB14 |
| 15 | + |
| 16 | +#define SAMPLES 8 // = 8 sec output |
| 17 | + |
| 18 | +volatile bool got_data = false; |
| 19 | + |
| 20 | +RTClock rtclock(RTCSEL_LSE); |
| 21 | +WeatherMeters meters(windvane_pin, SAMPLES); |
| 22 | + |
| 23 | +void intAnemometer() { |
| 24 | + meters.intAnemometer(); |
| 25 | +} |
| 26 | + |
| 27 | +void intRaingauge() { |
| 28 | + meters.intRaingauge(); |
| 29 | +} |
| 30 | + |
| 31 | +void secondCount() { |
| 32 | + meters.secondCount(); |
| 33 | +} |
| 34 | + |
| 35 | +void readDone(void) { |
| 36 | + got_data = true; |
| 37 | +} |
| 38 | + |
| 39 | +void setup() { |
| 40 | + Serial.begin(115200); |
| 41 | + |
| 42 | + attachInterrupt(digitalPinToInterrupt(anemometer_pin), intAnemometer, FALLING); |
| 43 | + attachInterrupt(digitalPinToInterrupt(raingauge_pin), intRaingauge, FALLING); |
| 44 | + meters.attach(readDone); |
| 45 | + rtclock.attachSecondsInterrupt(secondCount); |
| 46 | + |
| 47 | + meters.init(); |
| 48 | +} |
| 49 | + |
| 50 | +void loop() { |
| 51 | + if (got_data) { |
| 52 | + got_data = false; |
| 53 | + Serial.print("Wind degrees: "); |
| 54 | + Serial.print(meters.getWindVane(), 1); |
| 55 | + Serial.print(" Wind speed: "); |
| 56 | + Serial.print(meters.getWindSpeed(), 1); |
| 57 | + Serial.print("km/h, Rain: "); |
| 58 | + Serial.print(meters.getRainGauge(), 4); |
| 59 | + Serial.println("mm"); |
| 60 | + } |
| 61 | +} |
| 62 | +``` |
0 commit comments