From 3133a7ba0cf3cc21b9a651b6fb91c171e7ba2840 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Mon, 23 Feb 2015 21:31:22 +0100 Subject: [PATCH 1/2] Updated library to use getHumidityPercentage, instead of getHumidityBasisPoints() in combined humidity/temperature reader --- libraries/SI7021/SI7021.cpp | 2 +- libraries/SI7021/SI7021.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/libraries/SI7021/SI7021.cpp b/libraries/SI7021/SI7021.cpp index 2bde080f1..c51ab6bef 100644 --- a/libraries/SI7021/SI7021.cpp +++ b/libraries/SI7021/SI7021.cpp @@ -128,7 +128,7 @@ void SI7021::setHeater(bool on) { // get humidity, then get temperature reading from humidity measurement struct si7021_env SI7021::getHumidityAndTemperature() { si7021_env ret = {0, 0, 0}; - ret.humidityBasisPoints = getHumidityBasisPoints(); + ret.humidityPercent = getHumidityPercent(); ret.celsiusHundredths = _getCelsiusPostHumidity(); ret.fahrenheitHundredths = (1.8 * ret.celsiusHundredths) + 3200; return ret; diff --git a/libraries/SI7021/SI7021.h b/libraries/SI7021/SI7021.h index 5aa9f4be8..d5779005a 100644 --- a/libraries/SI7021/SI7021.h +++ b/libraries/SI7021/SI7021.h @@ -23,7 +23,7 @@ This program is licensed under the GNU GPL v2 typedef struct si7021_env { int celsiusHundredths; int fahrenheitHundredths; - unsigned int humidityBasisPoints; + unsigned int humidityPercent; } si7021_env; class SI7021 From c6efc23de384248f881aded9287da1c8c22ceb89 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=B8rch?= Date: Mon, 23 Feb 2015 21:32:38 +0100 Subject: [PATCH 2/2] Updated MysensorMicro to use combined humidity and temperature readings from Si7021, in order to save current --- .../examples/MysensorMicro/MysensorMicro.ino | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino b/libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino index 11bf60826..feb6dd694 100644 --- a/libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino +++ b/libraries/MySensors/examples/MysensorMicro/MysensorMicro.ino @@ -26,6 +26,9 @@ #define MEASURE_INTERVAL 60000 +// FORCE_TRANSMIT_INTERVAL, this number of times of wakeup, the sensor is forced to report all values to the controller +#define FORCE_TRANSMIT_INTERVAL 30 + SI7021 humiditySensor; MySensor gw; @@ -45,7 +48,6 @@ long lastBattery = -100; void setup() { - Serial.begin(115200); pinMode(LED_PIN, OUTPUT); digitalWrite(LED_PIN, LOW); @@ -73,6 +75,7 @@ void setup() { gw.present(CHILD_ID_HUM,S_HUM); gw.present(CHILD_ID_BATT, S_POWER); + switchClock(1< 30) {// Every 60th time we wake up, force a transmission on all sensors. + if (measureCount > FORCE_TRANSMIT_INTERVAL + ) {// Every 60th time we wake up, force a transmission on all sensors. forceTransmit = true; measureCount = 0; } @@ -106,23 +110,19 @@ void sendTempHumidityMeasurements(bool force) lastTemperature = -100; } - float temperature = humiditySensor.getCelsiusHundredths()/10; - - temperature = temperature / 10; + si7021_env data = humiditySensor.getHumidityAndTemperature(); - int humidity = humiditySensor.getHumidityPercent(); + float temperature = data.celsiusHundredths/100; + + int humidity = data.humidityPercent; if (lastTemperature != temperature) { gw.send(msgTemp.set(temperature,1)); lastTemperature = temperature; - Serial.print("temperature "); - Serial.println(temperature); } if (lastHumidity != humidity) { gw.send(msgHum.set(humidity)); lastHumidity = humidity; - Serial.print("Humidity "); - Serial.println(humidity); } } @@ -155,7 +155,7 @@ long readVcc() { #elif defined (__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) ADMUX = _BV(MUX5) | _BV(MUX0); #elif defined (__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) - ADMUX = _BV(MUX3) | _BV(MUX2); + ADcdMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif @@ -188,4 +188,11 @@ void resetEEP() } } - +void switchClock(unsigned char clk) +{ + cli(); + + CLKPR = 1<