diff options
author | Florian Pritz <bluewind@xinu.at> | 2014-06-18 11:48:46 +0200 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2014-06-18 11:48:46 +0200 |
commit | 4c6444650da3a0aa1e2e9b00f42cc4e2af057fe6 (patch) | |
tree | d245d54eec7575d06d69d9a54598ef828779a2ed /src | |
download | templogger-v2-4c6444650da3a0aa1e2e9b00f42cc4e2af057fe6.tar.gz templogger-v2-4c6444650da3a0aa1e2e9b00f42cc4e2af057fe6.tar.xz |
initial commit
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'src')
-rw-r--r-- | src/main.cpp | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/src/main.cpp b/src/main.cpp new file mode 100644 index 0000000..d8122a6 --- /dev/null +++ b/src/main.cpp @@ -0,0 +1,52 @@ +#include <Arduino.h> +#include <Wire.h> +#include <DallasTemperature.h> +#include <DHT.h> +#include <stdlib.h> + +// Pin setup +const int oneWirePin = 7; +const int dhtPin = 2; +#define DHTTYPE DHT22 + +#define BUFSIZE 32 + +OneWire oneWire(oneWirePin); +DallasTemperature sensors(&oneWire); +DHT dht(dhtPin, DHTTYPE); + +void setup () { + Serial.begin(9600); + dht.begin(); +} + +void loop () { + sensors.requestTemperatures(); + + float t1 = sensors.getTempCByIndex(0); + + float t2 = dht.readTemperature(); + float h1 = dht.readHumidity(); + + char temp[BUFSIZE]; + + // format: <timestamp|0> t:1=<temp> t:2=<temp> h:1=<humidity> + String line = ""; + line += 0; + + line += " t:1="; + dtostrf(t1, 5, 2, temp); + line += temp; + + line += " t:2="; + dtostrf(t2, 5, 2, temp); + line += temp; + + line += " h:1="; + dtostrf(h1, 5, 2, temp); + line += temp; + + + Serial.println(line); + delay(10000); +} |