X-Git-Url: http://git.rot13.org/?a=blobdiff_plain;f=rpi_promini%2Frpi_promini.ino;h=38d318df460b4898c64d8afedcf9600c09023609;hb=3f119f62c021a7576f999a2acd1aed430d7bf3ad;hp=81964a36def5e592de35f60399244c97ee2a1635;hpb=c7ee9b92e8118fdf8f0305800f79ae709bac8e83;p=Arduino diff --git a/rpi_promini/rpi_promini.ino b/rpi_promini/rpi_promini.ino index 81964a3..38d318d 100644 --- a/rpi_promini/rpi_promini.ino +++ b/rpi_promini/rpi_promini.ino @@ -5,13 +5,13 @@ RPI pin Arduino RXD TXD TXD RXD - GPIO6 RST + BCM25 RST GND GND +5V RAW 2 433Mhz receive // 3 433Mhz outdoor temperature sensor receiver # DISABLED - 8 DHT22 + 8 DHT22 (VCC from arduino VCC) 10 433Mhz send 11 DS18B20 12 315Mhz send @@ -76,6 +76,11 @@ void send_315(char *code) { #include "DHT.h" DHT dht; +#include "RunningAverage.h" + +RunningAverage temp_avg(10); +RunningAverage hum_avg(10); + // setup void help() { @@ -94,13 +99,31 @@ void setup() { // DHT22 dht.setup(8); + temp_avg.addValue( dht.getTemperature() ); + hum_avg.addValue( dht.getHumidity() ); + } int serial_pos = 0; char serial_data[2]; // socket (0-9), state (0-1) char binary_data[32]; +unsigned int dht22_errors = 0; + +unsigned long time = millis(); void loop() { + if ( millis() - time > 2000 ) { + float t = dht.getTemperature(); + if ( dht.getStatus() == 0 ) + temp_avg.addValue( t ); + else dht22_errors++; + float h = dht.getHumidity(); + if ( dht.getStatus() == 0 ) + hum_avg.addValue( h ); + else dht22_errors++; + time = millis(); + } + if (mySwitch.available()) { Serial.print(mySwitch.getReceivedBitlength()); Serial.print(" bits "); @@ -147,11 +170,11 @@ void loop() { // DHT22 if (input == 'd') { Serial.print("temperature="); - Serial.print(dht.getTemperature()); + Serial.print(temp_avg.getAverage()); Serial.print(" humidity="); - Serial.print(dht.getHumidity()); - Serial.print(" status="); - Serial.println(dht.getStatusString()); + Serial.print(hum_avg.getAverage()); + Serial.print(" errors="); + Serial.println(dht22_errors); } if ( input >= 0x30 && input <= 0x39 && serial_pos < 2 ) {