summaryrefslogtreecommitdiff
path: root/src/app/wetterstation
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2020-07-06 18:55:49 +0200
committerDaniel Friesel <derf@finalrewind.org>2020-07-06 18:55:49 +0200
commitda828589e00f1d709053431c2249cb53c5cee37f (patch)
tree3cb38e5d2f5f7b0664a276ea061fa1a7f9210db1 /src/app/wetterstation
parentce0cd4bdafacbaee74eba78f15acccf5488a5a36 (diff)
wetterstation: Add dew sensor
Diffstat (limited to 'src/app/wetterstation')
-rw-r--r--src/app/wetterstation/main.cc50
1 files changed, 45 insertions, 5 deletions
diff --git a/src/app/wetterstation/main.cc b/src/app/wetterstation/main.cc
index 2c47d78..730f47e 100644
--- a/src/app/wetterstation/main.cc
+++ b/src/app/wetterstation/main.cc
@@ -8,9 +8,14 @@ volatile uint16_t anemometer_count = 0;
void loop(void)
{
- static uint8_t loop_count = 0;
+ static uint8_t wind_count = 0;
+ static uint8_t dew_count = 0;
static uint16_t anemometer_copy;
- if (++loop_count == 10) {
+
+ wind_count++;
+ dew_count++;
+
+ if (wind_count == 10) {
cli();
anemometer_copy = anemometer_count;
@@ -18,7 +23,39 @@ void loop(void)
sei();
kout << "Anemometer Count = " << anemometer_copy << endl;
- loop_count = 0;
+ wind_count = 0;
+ }
+
+ if (dew_count == 59) {
+ gpio.output(GPIO::pc5, 0);
+ gpio.output(GPIO::pc4, 1);
+ }
+ else if (dew_count == 60) {
+ // Measure ADC6 with AVCC reference
+ ADMUX = _BV(REFS0) | 6;
+
+ // Enable ADC with /64 prescaler
+ ADCSRA = _BV(ADEN) | _BV(ADPS2);
+
+ // Start conversion
+ ADCSRA |= _BV(ADSC);
+
+ // wait until conversion is complete
+ while (ADCSRA & _BV(ADSC)) ;
+
+ uint8_t adcr_l = ADCL;
+ uint8_t adcr_h = ADCH;
+ uint16_t dew_raw = adcr_l + (adcr_h << 8);
+ dew_raw = 1024 - dew_raw;
+
+ // Disable ADC
+ ADCSRA &= ~_BV(ADEN);
+
+ kout << "Dew Raw = " << dew_raw << endl;
+
+ dew_count = 0;
+ gpio.input(GPIO::pc5, 0);
+ gpio.input(GPIO::pc4, 0);
}
}
@@ -28,8 +65,11 @@ int main(void)
gpio.setup();
kout.setup();
- gpio.output(GPIO::pd2, 0);
- gpio.input(GPIO::pd3, 1);
+ gpio.output(GPIO::pd2, 0); // Anemometer Reed Contact
+ gpio.input(GPIO::pd3, 1); // Anemometer Reed Contact
+
+ gpio.input(GPIO::pc5, 0); // Dew Sensor GND
+ gpio.input(GPIO::pc4, 0); // Dew Sensor VCC
EICRA = _BV(ISC11);
EIMSK = _BV(INT1);