weatherstation/firmware/sensors.ino

61 lines
1.2 KiB
Arduino
Raw Normal View History

2019-01-27 18:49:28 +01:00
#include "config_user.h"
2017-11-12 21:37:55 +01:00
int anemometerRotations = 0;
unsigned long currentTime = 0;
2017-11-07 22:20:14 +01:00
float fetchTemperature() {
2017-12-09 19:10:31 +01:00
//return 10;
2017-11-20 20:42:02 +01:00
return bme.readTemperature();
}
float fetchPressure() {
2017-12-09 19:10:31 +01:00
//return 10;
2017-11-20 20:42:02 +01:00
return bme.readPressure() / 100.0F;
2017-11-07 22:20:14 +01:00
}
float fetchHumidity() {
2019-01-08 22:41:48 +01:00
return bme.readHumidity();
2017-11-07 22:20:14 +01:00
}
float fetchLight() {
2019-01-27 18:49:28 +01:00
//TODO read values
uint16_t red, green, blue, white, lux;
while(!apds.colorDataReady()) {
2017-11-20 20:42:02 +01:00
delay(5);
}
2019-01-27 18:49:28 +01:00
2017-11-20 20:42:02 +01:00
apds.getColorData(&red, &green, &blue, &white);
2019-01-27 18:49:28 +01:00
//calculate lux
lux = apds.calculateLux(red, green, blue);
return lux;
2017-11-12 21:37:55 +01:00
}
void _anemometerInterrupt() {
2017-11-12 21:37:55 +01:00
anemometerRotations++;
#ifdef DEBUG
Serial.print("*");
#endif
2017-11-12 21:37:55 +01:00
}
float fetchWindspeed() {
anemometerRotations = 0;
currentTime = millis();
int interruptNumber = digitalPinToInterrupt(ANEMOMETER_PIN);
attachInterrupt(interruptNumber, _anemometerInterrupt, RISING);
2017-11-12 21:37:55 +01:00
delay(1000 * 5);
detachInterrupt(interruptNumber);
return (float)anemometerRotations / 5.0 * 2.4;
2017-11-07 22:20:14 +01:00
}
2018-07-11 11:12:53 +02:00
// Copied from https://arduinodiy.wordpress.com/2016/12/25/monitoring-lipo-battery-voltage-with-wemos-d1-minibattery-shield-and-thingspeak/
2019-01-27 18:49:28 +01:00
#ifdef BATTERY_POWERED
2018-07-11 11:12:53 +02:00
float getBatteryVoltage() {
uint16_t raw = analogRead(A0);
float volt = raw / 1023.0;
2019-01-06 15:23:48 +01:00
return volt * 4.2;
2018-07-11 11:12:53 +02:00
}
2019-01-27 18:49:28 +01:00
#endif