Compare commits

..

2 Commits

Author SHA1 Message Date
bzi
c4edb43af6 Implement I2C support into firmware 2019-02-21 21:04:55 +01:00
bzi
05ada31f0e Prepare variable environment for I2C communication 2019-02-21 21:04:22 +01:00

View File

@ -20,6 +20,10 @@ DHT dht(DHT_PIN, DHT_TYPE);
int sensorValue;
long last_sample = 0;
float hmid = 0; // humidity
float temp = 0; // temperature
float heat = 0; // heat index
float airq = 0; // air quality / gas
void setup() {
Serial.begin(SERIAL_BAUDRATE);
@ -27,6 +31,12 @@ void setup() {
pinMode(LED_BUILTIN, OUTPUT);
digitalWrite(LED_BUILTIN, LOW);
dht.begin();
Wire.begin(8); // join i2c bus with address #8
Wire.onRequest(requestEvent); // register event
}
void requestEvent() {
Wire.write("he1234");
}
void loop() {
@ -38,25 +48,25 @@ void loop() {
last_sample = now;
if (OPERATION_BLINK_EN) {digitalWrite(LED_BUILTIN, HIGH);}
float h = dht.readHumidity();
float t = dht.readTemperature();
hmid = dht.readHumidity();
temp = dht.readTemperature();
if (isnan(h) || isnan(t)) {
if (isnan(hmid) || isnan(temp)) {
Serial.println(F("Failed to read from DHT sensor!"));
} else {
float hi = dht.computeHeatIndex(t, h, false);
heat = dht.computeHeatIndex(temp, hmid, false);
Serial.print(F("Humidity: "));
Serial.print(h);
Serial.print(hmid);
Serial.print(F("% Temperature: "));
Serial.print(t);
Serial.print(temp);
Serial.print(F("°C Heat index: "));
Serial.print(hi);
Serial.println(F("°C "));
Serial.print(heat);
Serial.print(F("°C "));
}
sensorValue = analogRead(MQ135_PIN);
Serial.print("AirQuality=");
Serial.print(sensorValue, DEC);
airq = analogRead(MQ135_PIN);
Serial.print("AirQuality: ");
Serial.print(airq);
Serial.println(" PPM");
}
}