Slim Node Si7021 sensor example
-
-
Ok, so I messed up my previous sensor trying to solder the bridge (don't ask...) I have now (I think) soldered it and reconnected it, am now getting the following:
Serial started Voltage: 3359 mV send: 132-132-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=fail:0 send: 132-132-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=fail:1.5.4 send: 132-132-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=fail:0 sensor started, id=132, parent=0, distance=1 send: 132-132-0-0 s=255,c=3,t=11,pt=0,l=15,sg=0,st=fail:EgTmpHumBat5min send: 132-132-0-0 s=255,c=3,t=12,pt=0,l=10,sg=0,st=fail:1.0 151106 send: 132-132-0-0 s=0,c=0,t=6,pt=0,l=0,sg=0,st=fail: find parent send: 132-132-255-255 s=255,c=3,t=7,pt=0,l=0,sg=0,st=bc: send: 132-132-0-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=fail: Node and 2 children presented.
I'm going to try get everything on a breadboard, but now I see fails, what's that all about?
PS will upload some pics of the soldered bridge...
-
@rsachoc google "mysensors st fail"
-
I am currently trying to use that red 3.3v module too and it doesn't seem to work. I have the sketch from above running with the "normal" blue module where I remove the voltage converter so that it works at 3.3V without a problem.
Then I switched to the red one (with these small 3 solderpads connected) and the scl/sda lines switched (the order is different form the blue one) but the program gets stuck at the same position as above (without the st=fail's though). So I assume thatsi7021_env data = humiditySensor.getHumidityAndTemperature();
fails. Does anyone have one of these sensors up and running? Any ideas where the error is? Otherwise I guess I have to stick with the blue ones.
-
@LastSamurai
The red ones are HTU21D and need another library (they are different from the SI7021).
Use the Adafruit library for this module (look on their site for HTU21D).
-
@GertSanders hmmm I think I'm using that same one as @LastSamurai so I suspect that's the issue? It's the one linked in the first post
I guess if that's the problem it should have been obvious to me, it even says HTU21D on mine! Silly me!
-
@rsachoc
Either one of these libraries will work with the HTU21D modules.Both modules do the same, but have different I2C adresses so you can actually use both at the same time (of you like to compare them), but you need different libraries to call each one.
-
@GertSanders Thanks, I don't know why I didn't realize that
I will try that out tomorrow.
-
@LastSamurai I'm having a go as well at updating the .ino file with the different library, but I'm not a coder so I'm "having a hack" - if you have any luck could you post your code?
-
@rsachoc Yes, I actually just tried it out and its working.
Here is my code for now (just for testing):
I basically just switched libraries/* Sketch with Si7021 and battery monitoring. by m26872, 20151109 Changed by LastSamurai 15052016 */ #include <MySensor.h> #include <Wire.h> #include <SPI.h> #include <SparkFunHTU21D.h> #include <RunningAverage.h> //#define DEBUG #ifdef DEBUG #define DEBUG_SERIAL(x) Serial.begin(x) #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #else #define DEBUG_SERIAL(x) #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #endif #define NODE_ID 100 // <<<<<<<<<<<<<<<<<<<<<<<<<<< Enter Node_ID #define CHILD_ID_TEMP 0 #define CHILD_ID_HUM 1 // #define SLEEP_TIME 15000 // 15s for DEBUG #define SLEEP_TIME 300000 // 5 min #define FORCE_TRANSMIT_CYCLE 36 // 5min*12=1/hour, 5min*36=1/3hour #define BATTERY_REPORT_CYCLE 2016 // Once per 5min => 12*24*7 = 2016 (one report/week) #define VMIN 1900 #define VMAX 3300 #define HUMI_TRANSMIT_THRESHOLD 3.0 // THRESHOLD tells how much the value should have changed since last time it was transmitted. #define TEMP_TRANSMIT_THRESHOLD 0.5 #define AVERAGES 2 int batteryReportCounter = BATTERY_REPORT_CYCLE - 1; // to make it report the first time. int measureCount = 0; float lastTemperature = -100; int lastHumidity = -100; RunningAverage raHum(AVERAGES); HTU21D humiditySensor; MySensor gw; MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message MyMessage msgHum(CHILD_ID_HUM,V_HUM); void setup() { DEBUG_SERIAL(9600); // <<<<<<<<<<<<<<<<<<<<<<<<<< Note BAUD_RATE in MySensors.h DEBUG_PRINTLN("Serial started"); DEBUG_PRINT("Voltage: "); DEBUG_PRINT(readVcc()); DEBUG_PRINTLN(" mV"); delay(500); DEBUG_PRINT("Internal temp: "); DEBUG_PRINT(GetInternalTemp()); // Probably not calibrated. Just to print something. DEBUG_PRINTLN(" *C"); delay(500); // Allow time for radio if power useed as reset gw.begin(NULL, NODE_ID); gw.sendSketchInfo("TempHumTest2", "1.0 17052016"); gw.present(CHILD_ID_TEMP, S_TEMP); // Present sensor to controller gw.present(CHILD_ID_HUM, S_HUM); DEBUG_PRINT("Node and "); DEBUG_PRINTLN("2 children presented."); raHum.clear(); humiditySensor.begin(); } void loop() { measureCount ++; batteryReportCounter ++; bool forceTransmit = false; if (measureCount > FORCE_TRANSMIT_CYCLE) { forceTransmit = true; } sendTempHumidityMeasurements(forceTransmit); /* // Read and print internal temp float temperature0 = static_cast<float>(static_cast<int>((GetInternalTemp()+0.5) * 10.)) / 10.; DEBUG_PRINT("Internal Temp: "); DEBUG_PRINT(temperature0); DEBUG_PRINTLN(" *C"); */ // Check battery if (batteryReportCounter >= BATTERY_REPORT_CYCLE) { long batteryVolt = readVcc(); DEBUG_PRINT("Battery voltage: "); DEBUG_PRINT(batteryVolt); DEBUG_PRINTLN(" mV"); uint8_t batteryPcnt = constrain(map(batteryVolt,VMIN,VMAX,0,100),0,255); DEBUG_PRINT("Battery percent: "); DEBUG_PRINT(batteryPcnt); DEBUG_PRINTLN(" %"); gw.sendBatteryLevel(batteryPcnt); batteryReportCounter = 0; } gw.sleep(SLEEP_TIME); } // function for reading Vcc by reading 1.1V reference against AVcc. Based from http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // To calibrate reading replace 1125300L with scale_constant = internal1.1Ref * 1023 * 1000, where internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) long readVcc() { // set the reference to Vcc and the measurement to the internal 1.1V reference ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } // function for reading internal temp. From http://playground.arduino.cc/Main/InternalTemperatureSensor double GetInternalTemp(void) { // (Both double and float are 4 byte in most arduino implementation) unsigned int wADC; double t; // The internal temperature has to be used with the internal reference of 1.1V. Channel 8 can not be selected with the analogRead function yet. ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); // Set the internal reference and mux. ADCSRA |= _BV(ADEN); // enable the ADC delay(20); // wait for voltages to become stable. ADCSRA |= _BV(ADSC); // Start the ADC while (bit_is_set(ADCSRA,ADSC)); // Detect end-of-conversion wADC = ADCW; // Reading register "ADCW" takes care of how to read ADCL and ADCH. t = (wADC - 88.0 ) / 1.0; // The default offset is 324.31. return (t); // The returned temperature in degrees Celcius. } /********************************************* * * Sends temperature and humidity from Si7021 sensor * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; float temperature = humiditySensor.readTemperature(); DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature); float diffTemp = abs(lastTemperature - temperature); DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp); if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) { gw.send(msgTemp.set(temperature,1)); lastTemperature = temperature; measureCount = 0; DEBUG_PRINTLN("T sent!"); } int humidity = humiditySensor.readHumidity(); DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity); raHum.addValue(humidity); humidity = raHum.getAverage(); // MA sample imply reasonable fast sample frequency float diffHum = abs(lastHumidity - humidity); DEBUG_PRINT(F("HumDiff :"));DEBUG_PRINTLN(diffHum); if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) { gw.send(msgHum.set(humidity)); lastHumidity = humidity; measureCount = 0; DEBUG_PRINTLN("H sent!"); } }
-
@LastSamurai thanks, progress, I'm getting this now, which means it's working! Finally, a working node from a complete rookie like me!
Serial started Voltage: 3389 mV Internal temp: 266.00 *C send: 100-100-0-0 s=255,c=3,t=15,pt=2,l=2,sg=0,st=ok:0 send: 100-100-0-0 s=255,c=0,t=17,pt=0,l=5,sg=0,st=ok:1.5.4 send: 100-100-0-0 s=255,c=3,t=6,pt=1,l=1,sg=0,st=ok:0 read: 0-0-100 s=255,c=3,t=15,pt=0,l=2,sg=0: sensor started, id=100, parent=0, distance=1 send: 100-100-0-0 s=255,c=3,t=11,pt=0,l=12,sg=0,st=fail:TempHumTest2 send: 100-100-0-0 s=255,c=3,t=12,pt=0,l=12,sg=0,st=fail:1.0 17052016 send: 100-100-0-0 s=0,c=0,t=6,pt=0,l=0,sg=0,st=fail: send: 100-100-0-0 s=1,c=0,t=7,pt=0,l=0,sg=0,st=fail: Node and 2 children presented. T: 998.00 TempDiff :1098.00 send: 100-100-0-0 s=0,c=1,t=0,pt=7,l=5,sg=0,st=fail:998.0 T sent! H: 118 HumDiff :218.00 send: 100-100-0-0 s=1,c=1,t=1,pt=2,l=2,sg=0,st=ok:118 H sent! Battery voltage: 3359 mV Battery percent: 104 % send: 100-100-0-0 s=255,c=3,t=0,pt=1,l=1,sg=0,st=ok:104
I think that the readings are not accurate though, not sure why, but I'll have a go at figuring our why anyway!
-
@rsachoc
Congrats !!!
-
@GertSanders Thx a lot for your help! I had no clue about the HTU21D lib.
-
This post is deleted!
-
so with the correct library there is no need to solder those 3 spots together!?
-
@siod
The "spots" are there to connect the pullup resistors to the SDA and SCL lines. This is always needed, regardless of the library of the board onto which you connect the sensor board does not provide pullup resistors itself. On a minimal board like the one in this thread, this is not the case, so the pull up resistors are needed.
-
ok, thanks for making it clear for me Gert!!
update:
finally found time to build my sensor and it seems to work fine, will do more testing but for now my results are:
7.5 uA when sleeping, 15,3 mA when working (every 15 minutes for about 2seconds, but I think my cheap multimeter gives bad readings on those spikes, I guess it´s only around 1 mA)
seems to be okay, isn´t it?
edit:
I have 2 reed switches attached. I recognized that I have +0,10 mA for each reed switch when activated. So when reed switches are both touching their counterpart I have a sleeping consumption of 0,20 mA. Why is that??
-
Hello,
I'm trying to convert existing Si7021 sensor code from 1.5 to 2.0.0 library. I change the code and then I was getting an error which said:
Si7021_sensor_MySensors_2.0.0:158: error: 'si7021_env' has no member named 'humidityPercent' int humidity = data.humidityPercent; ^ exit status 1 'si7021_env' has no member named 'humidityPercent'
Then I chech the Si7021 library, and how I saw there wasn't member 'humidityPercent', but there was a member 'humidityBasisPoints'.
So I change line from:
int humidity = data.humidityPercent;
...to:
int humidity = data.humidityBasisPoints;
Then code compiles and I upload it to Slim Node Si7021. I leave sensor and today I checked it log on Domoticz. I have this:
Temperature looks ok, but Humidity value jumping a lot, thats why I don't want to believe it is true.
Could someone, who has a 2.0.0 library and Si7021 sensor chech is it same situation? Becose I have only one Si7021 sensor.
Maybe someone could look also on the code and say if I convert it right?Converted code:
/* Sketch with Si7021 and battery monitoring. by m26872, 20151109 */ #define MY_DEBUG #define MY_RADIO_NRF24 #define MY_NODE_ID 5 // <<<<<<<<<<<<<<<<<<<<<<<<<<< Enter Node_ID #define MY_BAUD_RATE 115200 #include <MySensors.h> #include <Wire.h> #include <SI7021.h> #include <SPI.h> #include <RunningAverage.h> //#define DEBUG #ifdef DEBUG #define DEBUG_SERIAL(x) Serial.begin(x) #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #else #define DEBUG_SERIAL(x) #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #endif #define CHILD_ID_TEMP 0 #define CHILD_ID_HUM 1 // #define SLEEP_TIME 15000 // 15s for DEBUG #define SLEEP_TIME 300000 // 5 min #define FORCE_TRANSMIT_CYCLE 36 // 5min*12=1/hour, 5min*36=1/3hour #define BATTERY_REPORT_CYCLE 2880 // Once per 5min => 12*24*7 = 2016 (one report/week) #define VMIN 1900 #define VMAX 3300 #define HUMI_TRANSMIT_THRESHOLD 3.0 // THRESHOLD tells how much the value should have changed since last time it was transmitted. #define TEMP_TRANSMIT_THRESHOLD 0.5 #define AVERAGES 2 int batteryReportCounter = BATTERY_REPORT_CYCLE - 1; // to make it report the first time. int measureCount = 0; float lastTemperature = -100; int lastHumidity = -100; RunningAverage raHum(AVERAGES); SI7021 humiditySensor; MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message MyMessage msgHum(CHILD_ID_HUM,V_HUM); void presentation() { sendSketchInfo("EgTmpHumBat5min", "1.0 151106"); present(CHILD_ID_TEMP, S_TEMP); // Present sensor to controller present(CHILD_ID_HUM, S_HUM); } void setup() { DEBUG_SERIAL(115200); // <<<<<<<<<<<<<<<<<<<<<<<<<< Note BAUD_RATE in MySensors.h DEBUG_PRINTLN("Serial started"); DEBUG_PRINT("Voltage: "); DEBUG_PRINT(readVcc()); DEBUG_PRINTLN(" mV"); /* delay(500); DEBUG_PRINT("Internal temp: "); DEBUG_PRINT(GetInternalTemp()); // Probably not calibrated. Just to print something. DEBUG_PRINTLN(" *C"); */ delay(500); // Allow time for radio if power useed as reset DEBUG_PRINT("Node and "); DEBUG_PRINTLN("2 children presented."); raHum.clear(); } void loop() { measureCount ++; batteryReportCounter ++; bool forceTransmit = false; if (measureCount > FORCE_TRANSMIT_CYCLE) { forceTransmit = true; } sendTempHumidityMeasurements(forceTransmit); /* // Read and print internal temp float temperature0 = static_cast<float>(static_cast<int>((GetInternalTemp()+0.5) * 10.)) / 10.; DEBUG_PRINT("Internal Temp: "); DEBUG_PRINT(temperature0); DEBUG_PRINTLN(" *C"); */ // Check battery if (batteryReportCounter >= BATTERY_REPORT_CYCLE) { long batteryVolt = readVcc(); DEBUG_PRINT("Battery voltage: "); DEBUG_PRINT(batteryVolt); DEBUG_PRINTLN(" mV"); uint8_t batteryPcnt = constrain(map(batteryVolt,VMIN,VMAX,0,100),0,255); DEBUG_PRINT("Battery percent: "); DEBUG_PRINT(batteryPcnt); DEBUG_PRINTLN(" %"); sendBatteryLevel(batteryPcnt); batteryReportCounter = 0; } sleep(SLEEP_TIME); } // function for reading Vcc by reading 1.1V reference against AVcc. Based from http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // To calibrate reading replace 1125300L with scale_constant = internal1.1Ref * 1023 * 1000, where internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) long readVcc() { // set the reference to Vcc and the measurement to the internal 1.1V reference ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } // function for reading internal temp. From http://playground.arduino.cc/Main/InternalTemperatureSensor double GetInternalTemp(void) { // (Both double and float are 4 byte in most arduino implementation) unsigned int wADC; double t; // The internal temperature has to be used with the internal reference of 1.1V. Channel 8 can not be selected with the analogRead function yet. ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); // Set the internal reference and mux. ADCSRA |= _BV(ADEN); // enable the ADC delay(20); // wait for voltages to become stable. ADCSRA |= _BV(ADSC); // Start the ADC while (bit_is_set(ADCSRA,ADSC)); // Detect end-of-conversion wADC = ADCW; // Reading register "ADCW" takes care of how to read ADCL and ADCH. t = (wADC - 88.0 ) / 1.0; // The default offset is 324.31. return (t); // The returned temperature in degrees Celcius. } /********************************************* * * Sends temperature and humidity from Si7021 sensor * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); float temperature = data.celsiusHundredths / 100.0; DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature); float diffTemp = abs(lastTemperature - temperature); DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp); if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) { send(msgTemp.set(temperature,1)); lastTemperature = temperature; measureCount = 0; DEBUG_PRINTLN("T sent!"); } int humidity = data.humidityPercent; DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity); raHum.addValue(humidity); humidity = raHum.getAverage(); // MA sample imply reasonable fast sample frequency float diffHum = abs(lastHumidity - humidity); DEBUG_PRINT(F("HumDiff :"));DEBUG_PRINTLN(diffHum); if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) { send(msgHum.set(humidity)); lastHumidity = humidity; measureCount = 0; DEBUG_PRINTLN("H sent!"); } }
Thank You!
-
@jacikaas where did you get the si7021 library? Take a look at the sensebender sketch for a good reference.
-
@AWI
I download Si7021 library from here: https://github.com/LowPowerLab/SI7021I was heard about Sensbender node, but never look deeper what is in it. I will look at it and try to understand whats in there. I just learning about all that stuff, so it will be good practice
-
@jacikaas that's the way to go. The sensebender sketch contains some rather nice best practices for low power. You best replace the si library with the one in the MySensors examples on github.
-
@AWI I try to replace library from this one https://github.com/LowPowerLab/SI7021 to this one https://github.com/mysensors/MySensorsArduinoExamples
to work it I need to return variable name from:
int humidity = data.humidityBasisPoints;
to:
int humidity = data.humidityPercent;
I think this library https://github.com/LowPowerLab/SI7021 was updated, so it is not suitable for this one code. Now I test it again and everything looks fine:
Temperature and humidity node unregister or stop working repeatedly for about 2 hours (2h25min, 2.20, 1.50...). But after that it start to send data again, for some time and then goes around again. I will try to understand why it happening too.
-
I am trying to build the code using the HTU21D sensors. This built fine under 1.4 and 1.5 but now under v2 of MySensors I am getting this error:
C:\Users\wergeld\Documents\Arduino\SlimNodeSi7021\SlimNodeSi7021.ino:4:24: fatal error: MySensor.h: No such file or directory #include <MySensor.h> ^ compilation terminated. exit status 1 Error compiling for board APM Optiboot internal 1MHz noBOD 9600baud.
Okay, so I change my reference to:
#include <MySensors.h>
And I get this lovely error:
In file included from C:\Users\wergeld\Documents\Arduino\SlimNodeSi7021\SlimNodeSi7021.ino:4:0: C:\Users\wergeld\Documents\Arduino\libraries\MySensors-master/MySensors.h:287:4: error: #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. #error No forward link or gateway feature activated. This means nowhere to send messages! Pretty pointless. ^ exit status 1 Error compiling for board APM Optiboot internal 1MHz noBOD 9600baud.
So, other than slamming my head against my desk how can I solve this?
-
Well, I solved it by modifying the code to 2.0 spec. Good lord I need sleep.
Working on debugging temp outputs now to Ethernet Gateway running on my Uno. Or I will sleep...
-
Okay, I now have a soldered node and serial gateway setup to my laptop for testing. It presents the sensor node! The name and available sensors is correct. Howevr, it never sends any message payload with temp/hum or battery values. I am using the HTU21D without soldering those 3 pads on it together. I need to get myself a 3.3v FTDI cable so I can serially debug I guess. But, still! Progress.
-
After soldering the 3 pads on the HTU21D I am now reading data and it is being sent to my test serial gateway. Need to measure current usage but at least it is functional.
-
Okay, seeing something odd. The force transmit does not appear to be working.
Here is my current sketch:#define MY_RADIO_NRF24 #include <MyConfig.h> #include <MySensors.h> /* Sketch with Si7021 and battery monitoring. by m26872, 20151109 */ //#include <MySensors.h> #include <Wire.h> #include <SparkFunHTU21D.h> #include <SPI.h> #include <RunningAverage.h> //#define DEBUG #ifdef DEBUG #define DEBUG_SERIAL(x) Serial.begin(x) #define DEBUG_PRINT(x) Serial.print(x) #define DEBUG_PRINTLN(x) Serial.println(x) #else #define DEBUG_SERIAL(x) #define DEBUG_PRINT(x) #define DEBUG_PRINTLN(x) #endif #define NODE_ID 132 // <<<<<<<<<<<<<<<<<<<<<<<<<<< Enter Node_ID #define CHILD_ID_TEMP 0 #define CHILD_ID_HUM 1 // #define SLEEP_TIME 15000 // 15s for DEBUG #define SLEEP_TIME 300000 // 5 min #define FORCE_TRANSMIT_CYCLE 36 // 5min*12=1/hour, 5min*36=1/3hour #define BATTERY_REPORT_CYCLE 2880 // Once per 5min => 12*24*7 = 2016 (one report/week) #define VMIN 1900 #define VMAX 3300 #define HUMI_TRANSMIT_THRESHOLD 3.0 // THRESHOLD tells how much the value should have changed since last time it was transmitted. #define TEMP_TRANSMIT_THRESHOLD 0.5 #define AVERAGES 2 int batteryReportCounter = BATTERY_REPORT_CYCLE - 1; // to make it report the first time. int measureCount = 0; float lastTemperature = -100; int lastHumidity = -100; RunningAverage raHum(AVERAGES); HTU21D humiditySensor; //MySensor gw; MyMessage msgTemp(CHILD_ID_TEMP,V_TEMP); // Initialize temperature message MyMessage msgHum(CHILD_ID_HUM,V_HUM); void presentation() { sendSketchInfo("HTU21D", "1.0"); present(CHILD_ID_TEMP, S_TEMP); // Present sensor to controller present(CHILD_ID_HUM, S_HUM); } void setup() { DEBUG_SERIAL(9600); // <<<<<<<<<<<<<<<<<<<<<<<<<< Note BAUD_RATE in MySensors.h DEBUG_PRINTLN("Serial started"); DEBUG_PRINT("Voltage: "); DEBUG_PRINT(readVcc()); DEBUG_PRINTLN(" mV"); /* delay(500); DEBUG_PRINT("Internal temp: "); DEBUG_PRINT(GetInternalTemp()); // Probably not calibrated. Just to print something. DEBUG_PRINTLN(" *C"); */ delay(500); // Allow time for radio if power useed as reset //gw.begin(NULL,NODE_ID); //sendSketchInfo("HTU21D", "1.0"); //present(CHILD_ID_TEMP, S_TEMP); // Present sensor to controller //present(CHILD_ID_HUM, S_HUM); DEBUG_PRINT("Node and "); DEBUG_PRINTLN("2 children presented."); raHum.clear(); } void loop() { measureCount ++; batteryReportCounter ++; bool forceTransmit = false; if (measureCount > FORCE_TRANSMIT_CYCLE) { forceTransmit = true; } sendTempHumidityMeasurements(forceTransmit); /* // Read and print internal temp float temperature0 = static_cast<float>(static_cast<int>((GetInternalTemp()+0.5) * 10.)) / 10.; DEBUG_PRINT("Internal Temp: "); DEBUG_PRINT(temperature0); DEBUG_PRINTLN(" *C"); */ // Check battery if (batteryReportCounter >= BATTERY_REPORT_CYCLE) { long batteryVolt = readVcc(); DEBUG_PRINT("Battery voltage: "); DEBUG_PRINT(batteryVolt); DEBUG_PRINTLN(" mV"); uint8_t batteryPcnt = constrain(map(batteryVolt,VMIN,VMAX,0,100),0,255); DEBUG_PRINT("Battery percent: "); DEBUG_PRINT(batteryPcnt); DEBUG_PRINTLN(" %"); sendBatteryLevel(batteryPcnt); batteryReportCounter = 0; } sleep(SLEEP_TIME); } // function for reading Vcc by reading 1.1V reference against AVcc. Based from http://provideyourown.com/2012/secret-arduino-voltmeter-measure-battery-voltage/ // To calibrate reading replace 1125300L with scale_constant = internal1.1Ref * 1023 * 1000, where internal1.1Ref = 1.1 * Vcc1 (per voltmeter) / Vcc2 (per readVcc() function) long readVcc() { // set the reference to Vcc and the measurement to the internal 1.1V reference ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA,ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high<<8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts } // function for reading internal temp. From http://playground.arduino.cc/Main/InternalTemperatureSensor double GetInternalTemp(void) { // (Both double and float are 4 byte in most arduino implementation) unsigned int wADC; double t; // The internal temperature has to be used with the internal reference of 1.1V. Channel 8 can not be selected with the analogRead function yet. ADMUX = (_BV(REFS1) | _BV(REFS0) | _BV(MUX3)); // Set the internal reference and mux. ADCSRA |= _BV(ADEN); // enable the ADC delay(20); // wait for voltages to become stable. ADCSRA |= _BV(ADSC); // Start the ADC while (bit_is_set(ADCSRA,ADSC)); // Detect end-of-conversion wADC = ADCW; // Reading register "ADCW" takes care of how to read ADCL and ADCH. t = (wADC - 88.0 ) / 1.0; // The default offset is 324.31. return (t); // The returned temperature in degrees Celcius. } /********************************************* * * Sends temperature and humidity from Si7021 sensor * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; float temperature = humiditySensor.readTemperature(); DEBUG_PRINT("T: ");DEBUG_PRINTLN(temperature); float diffTemp = abs(lastTemperature - temperature); DEBUG_PRINT(F("TempDiff :"));DEBUG_PRINTLN(diffTemp); if (diffTemp > TEMP_TRANSMIT_THRESHOLD || tx) { send(msgTemp.set(temperature,1)); lastTemperature = temperature; measureCount = 0; DEBUG_PRINTLN("T sent!"); } int humidity = humiditySensor.readHumidity(); DEBUG_PRINT("H: ");DEBUG_PRINTLN(humidity); raHum.addValue(humidity); humidity = raHum.getAverage(); // MA sample imply reasonable fast sample frequency float diffHum = abs(lastHumidity - humidity); DEBUG_PRINT(F("HumDiff :"));DEBUG_PRINTLN(diffHum); if (diffHum > HUMI_TRANSMIT_THRESHOLD || tx) { send(msgHum.set(humidity)); lastHumidity = humidity; measureCount = 0; DEBUG_PRINTLN("H sent!"); } }
I am at 1+ hours since last transmission.
-
@wergeld It looks like it's set to 3 hrs.
-
@m26872
Indeed it does. Just was throwing me off with the wording. I read it as "1/2 hour" or "1/3 hour". So far I am prepping up more nodes. Have 4 more 328s to programs and build out. I am thinking at the end I will have:- Gateway (serial or the direct connect nrf+ once it supports v2)
- Temp/Hum node using HTU21D for back porch sending every 5 minutes and force send every 30 minutes.
- Temp/Hum node using HTU21D inside using same send times.
- Parking sensor in garage hardwired to mains.
5 & 6 I am not sure yet.
Lots of fun so far.
-
I am seeing 5.0 μA at sleep and 12.4 mA when transmitting. Seems kind of high. I did the poor man's test as well - put an LED across the HTU21D power pins and it lit up. Same when I did it across the nrf's power pins. Shouldn't the MySensors code turn off the power rails during sleep?
-
No, the powerrails are not turned off, just the devices themselves.
5uA during sleep is about right. The 12.4mA during transmit is also normal, but the transmit time should be very short, so on average the total consumption of power will be low.
-
@GertSanders Excellent! I was hoping I hadn't wired it up wrong. So far the 2 nodes have been flawless for the past 3 days. Next step is to await the direct attached NRF serial gateway to be v2 compatible. Been following along with this thread. Looks like we are getting closer! I have 2 RPis (one a first gen B and the other a Pi2 B ) with this adapter by ceech:
https://www.openhardware.io/view/100/Raspberry-PI-NRF24l01-hat
-
Hi everyone,
First thanks for sharing. I love this slim node. But I am facing some issues I did not success to debug. So I use the code shared here for mysensors 2. I try with the mysensors exemple library (did not work at all). I try with the https://github.com/LowPowerLab/SI7021 which worked (at least for getting separately temperature and humidity and using the example file) on an arduino nano. But when I run this sensor with the slim node (red, boot loader 8mhz) and the code (for 2.0.0) I always get -46.85 for temperature and 118 for humidity. Otherwise the radio work normally.
Winter is coming and I don't know what I could do anymore. Thanks to share you idea on this.
With the example code I use on the nano. I get with the slim node:
T: -46.85 H: 118 device ID: 50
With Arduino nano:
T: 24.34 H: 43 device ID: 50
-
Why actually my device id is 50 ? for what 50 stands !?!?!
-
@clempat Please post your sketch and maybe some hardware photo or diagram too.
-
@m26872 Sure I can do that. So I simplified the code to only focus on the si7021.
Here it is: https://github.com/clempat/example-si7021
And there the photo:
-
@clempat Don't think I can help you. Maybe clock related. What voltages do you use on Nano and Slim respectively? Do you have multiple parts to try with and get the same result? Why do you include and start wire.h, isn't already in Si7021.h ? My guess on "device Id 50" is that it's just a chinese clone reply.
Photos look nice btw.
-
@m26872 Thank you. Yes I wanted to try with a pro mini 8Mhz but I need to prepare the pin 4 and 5. I will keep inform when I do it this week end.
Thanks for the picture but with this nice setup it is difficult to make it bad :)...
I includes wire.h like in the exemple in https://github.com/LowPowerLab/SI7021 but of course after I tried without. The nano was directly connected to usb and the slim through 3,3V USB to serial.
-
Ok with the arduino micro 8Mhz all works good too.
Reading... T: 20.29 H: 54 device ID: 50
-
So sad I still not getting it working with the slim node !!! Always same result either with internal 1mhz or 8mhz...
-
@clempat Make it with external 8MHz then ? Then it should be like a Pro Mini 3.3V.
-
@m26872 I will give a try and let you know... Thanks.
-
Hello
I also have big problems with getting the node to send temp and hum values
It starts up and presents itself to the GW but then nothing happensI have tested the SI721 module with a simple arduino code and then it reads and prints both values just fine
My code is below, in practice its a version of Sensebender Micro code. I have changed the force transmit value to 1
Exactly as @clempat I have tried both 1MHz optiboot and 8MHz internal oscillator without any success/** * The MySensors Arduino library handles the wireless radio link and protocol * between your home built sensors/actuators and HA controller of choice. * The sensors forms a self healing radio network with optional repeaters. Each * repeater and gateway builds a routing tables in EEPROM which keeps track of the * network topology allowing messages to be routed to nodes. * * Created by Henrik Ekblad <henrik.ekblad@mysensors.org> * Copyright (C) 2013-2015 Sensnology AB * Full contributor list: https://github.com/mysensors/Arduino/graphs/contributors * * Documentation: http://www.mysensors.org * Support Forum: http://forum.mysensors.org * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License * version 2 as published by the Free Software Foundation. * ******************************* * * REVISION HISTORY * Version 1.0 - Thomas Bowman MC8rch * * DESCRIPTION * Default sensor sketch for Sensebender Micro module * Act as a temperature / humidity sensor by default. * * If A0 is held low while powering on, it will enter testmode, which verifies all on-board peripherals * * Battery voltage is as battery percentage (Internal message), and optionally as a sensor value (See defines below) * * * Version 1.3 - Thomas Bowman MC8rch * Improved transmission logic, eliminating spurious transmissions (when temperatuere / humidity fluctuates 1 up and down between measurements) * Added OTA boot mode, need to hold A1 low while applying power. (uses slightly more power as it's waiting for bootloader messages) * * Version 1.4 - Thomas Bowman MC8rch * * Corrected division in the code deciding whether to transmit or not, that resulted in generating an integer. Now it's generating floats as expected. * Simplified detection for OTA bootloader, now detecting if MY_OTA_FIRMWARE_FEATURE is defined. If this is defined sensebender automaticly waits 300mS after each transmission * Moved Battery status messages, so they are transmitted together with normal sensor updates (but only every 60th minute) * */ // Enable debug prints to serial monitor #define MY_DEBUG // Define a static node address, remove if you want auto address assignment //#deine MY_NODE_ID 3 // Enable and select radio type attached #define MY_RADIO_NRF24 //#define MY_RADIO_RFM69 #include <SPI.h> #include <MySensors.h> #include <Wire.h> #include <SI7021-master\SI7021.h> #include <RunningAverage.h> // Uncomment the line below, to transmit battery voltage as a normal sensor value #define BATT_SENSOR 199 #define RELEASE "1.4" #define AVERAGES 2 // Child sensor ID's #define CHILD_ID_TEMP 1 #define CHILD_ID_HUM 2 // How many milli seconds between each measurement #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 1 // When MEASURE_INTERVAL is 60000 and FORCE_TRANSMIT_INTERVAL is 30, we force a transmission every 30 minutes. // Between the forced transmissions a tranmission will only occur if the measured value differs from the previous measurement // HUMI_TRANSMIT_THRESHOLD tells how much the humidity should have changed since last time it was transmitted. Likewise with // TEMP_TRANSMIT_THRESHOLD for temperature threshold. #define HUMI_TRANSMIT_THRESHOLD 0.5 #define TEMP_TRANSMIT_THRESHOLD 0.5 SI7021 humiditySensor; // Sensor messages MyMessage msgHum(CHILD_ID_HUM, V_HUM); MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP); #ifdef BATT_SENSOR MyMessage msgBatt(BATT_SENSOR, V_VOLTAGE); #endif // Global settings int measureCount = 0; int sendBattery = 0; boolean isMetric = true; boolean highfreq = true; boolean transmission_occured = false; // Storage of old measurements float lastTemperature = -100; int lastHumidity = -100; long lastBattery = -100; RunningAverage raHum(AVERAGES); /**************************************************** * * Setup code * ****************************************************/ void setup() { Serial.begin(9600); Serial.print(F("Sensebender Micro FW ")); Serial.print(RELEASE); Serial.flush(); humiditySensor.begin(); Serial.flush(); Serial.println(F(" - Online!")); isMetric = getConfig().isMetric; Serial.print(F("isMetric: ")); Serial.println(isMetric); raHum.clear(); sendTempHumidityMeasurements(false); sendBattLevel(false); } void presentation() { sendSketchInfo("TempHum", RELEASE); present(CHILD_ID_TEMP, S_TEMP); present(CHILD_ID_HUM, S_HUM); #ifdef BATT_SENSOR present(BATT_SENSOR, S_POWER); #endif } /*********************************************** * * Main loop function * ***********************************************/ void loop() { measureCount++; sendBattery++; bool forceTransmit = false; transmission_occured = false; if (measureCount > FORCE_TRANSMIT_INTERVAL) { // force a transmission forceTransmit = true; measureCount = 0; } sendTempHumidityMeasurements(forceTransmit); /* if (sendBattery > 60) { sendBattLevel(forceTransmit); // Not needed to send battery info that often sendBattery = 0; }*/ sleep(MEASURE_INTERVAL); } /********************************************* * * Sends temperature and humidity from Si7021 sensor * * Parameters * - force : Forces transmission of a value (even if it's the same as previous measurement) * *********************************************/ void sendTempHumidityMeasurements(bool force) { bool tx = force; si7021_env data = humiditySensor.getHumidityAndTemperature(); raHum.addValue(data.humidityPercent); float diffTemp = abs(lastTemperature - (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0); float diffHum = abs(lastHumidity - raHum.getAverage()); Serial.print(F("TempDiff :"));Serial.println(diffTemp); Serial.print(F("HumDiff :"));Serial.println(diffHum); if (isnan(diffHum)) tx = true; if (diffTemp > TEMP_TRANSMIT_THRESHOLD) tx = true; if (diffHum > HUMI_TRANSMIT_THRESHOLD) tx = true; if (tx) { measureCount = 0; float temperature = (isMetric ? data.celsiusHundredths : data.fahrenheitHundredths) / 100.0; int humidity = data.humidityPercent; Serial.print("T: ");Serial.println(temperature); Serial.print("H: ");Serial.println(humidity); send(msgTemp.set(temperature, 1)); send(msgHum.set(humidity)); lastTemperature = temperature; lastHumidity = humidity; transmission_occured = true; if (sendBattery > 60) { sendBattLevel(true); // Not needed to send battery info that often sendBattery = 0; } } } /******************************************** * * Sends battery information (battery percentage) * * Parameters * - force : Forces transmission of a value * *******************************************/ void sendBattLevel(bool force) { if (force) lastBattery = -1; long vcc = readVcc(); if (vcc != lastBattery) { lastBattery = vcc; #ifdef BATT_SENSOR float send_voltage = float(vcc) / 1000.0f; send(msgBatt.set(send_voltage, 3)); #endif // Calculate percentage vcc = vcc - 1900; // subtract 1.9V from vcc, as this is the lowest voltage we will operate at long percent = vcc / 14.0; sendBatteryLevel(percent); transmission_occured = true; } } /******************************************* * * Internal battery ADC measuring * *******************************************/ long readVcc() { // Read 1.1V reference against AVcc // set the reference to Vcc and the measurement to the internal 1.1V reference #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega1280__) || defined(__AVR_ATmega2560__) ADMUX = _BV(REFS0) | _BV(MUX4) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #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__) ADcdMUX = _BV(MUX3) | _BV(MUX2); #else ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1); #endif delay(2); // Wait for Vref to settle ADCSRA |= _BV(ADSC); // Start conversion while (bit_is_set(ADCSRA, ADSC)); // measuring uint8_t low = ADCL; // must read ADCL first - it then locks ADCH uint8_t high = ADCH; // unlocks both long result = (high << 8) | low; result = 1125300L / result; // Calculate Vcc (in mV); 1125300 = 1.1*1023*1000 return result; // Vcc in millivolts }
-
It would be interesting if someone with issues also tried older versions of libs for Si7021 and/or MySensors.
-
So, after a few months of 2 nodes up and running using the HTU21D sensor I have come the conclusion that the HTU21D is no good for where I live. Lately it has been getting cooler outside (down to mid 50s F) but humidity is still high. As the evening progresses the humidity gets to 100% and the node no longer sends data. This happens around 6pm every day (about half and hour after sunset). It then comes back online at about 10 am the next day. The node that I have inside does not have this issue (same shipment of arduino, pcb, and HTU21D sensors and the same arduino code). Both running off of fresh AAs. May need to upgrade to the SI7021 for outside node.
Here is the graph showing last 7 days. As you can see it flatlines (literally!) at 100% humidity!
All good times with the learning!
-
@wergeld Relative humidity at 100% during night sounds very realistic to me. Are you confusing it with the "absolute humidity"? Or is your concern that the "force transmit" isn't working?
-
Mine does the same, but it's also very humid at night - I think this is normal behavoir
-
@m26872 & @bjacobse - Yes, 100% humidity is normal here. Good old Florida! My concern is that the node stops reporting. Possibly due to condensation shorting out something. During the summer here we also hit 100% humidity but it is also a lot hotter (high 90s). Now, I think that the cooler temps are forcing a dew point that is allowing water to condense on the node. Then during the morning it drys out and resumes transmitting. I would like to find a way to stop this.
-
-
@m26872 I have looked at a lot of those links. I am leaning towards covering my node in non-reactive glue. This will seal all contacts. The only part that would be difficult would be the actual teeny tiny sensor chip on the HTU21D. Hopefully any condensation there can be minimal. The next step would be to make sure the battery case is sealed as well (although I do not think this will be much of an issue).
-
Do you have some battery saving stuff in your code, so you maybe wakeup check temp + humidity, and if they are same value as previous, then go back to sleep - no need to use battery usage to send same values again, this can cause your sensor to not report values
-
@bjacobse Yes, I am checking the values and if the same as last transmission I abort and go back to sleep. If, however, it has been 3 hours since last transmission I force it to send.
-
I've done 6 nodes off this sensor. Do I have to change something else then node id? Also I'm using the 1mhz bootloader with bud rate 9200 should I change that in the sketch?
Seems like I only get the temprature and humidity once on first start up...
Edit:
I think my problem is that I haven't changed the bud rate in mysensors.h file. I've just reinstalled everything now and I don't know how to get si7021 installed the right way. I installed the package inside arduino but it doesn't work.
I such a noob sorry guys
-
I have problem to get my sensors to work. Thay start up and shows a not so accurate value sometimes and thay report once or twice but then never again. I thought it was because buad rate was wrong in the MyConfig.H file. Now i changed that and i tried a few different codes and librarys. Nothing seems to work.
So my question is which code and library should i use?
I got the slim node and sensor as in the first post.
Im running 1mhz optiboot bootloader from the slim node thread
And i updated mysensors to 2.1.
-
@Eawo Sorry for a late reply. Please post your sketch to begin with.
Do you have v2.1 for both gateway and sensors?
"#define MY_BAUD_RATE 9600" should be before the "include MySensors.h" and that should be all regarding baud rate setting. No need to mess with MyConfig.h in v2.x.
A lot of the SlimNode example codes are still in v1.x unfortunately. So please look at more recent post above in this thread instead for v2.x.To verify the Si7021 you should use a clean Arduino+Si7021 setup with the only hw/sw needed for that, i.e. no radio or MySensors-library. Si7021-example sketches generally comes with the lib.
-
Ok i redid everything from skratch and now i got it working atleast with 1 node havnt tried the other yet.
I used the code miljume did link the only line i changed was
#include <SI7021-master\SI7021.h>
to
#include <SI7021.h>
It is working but it shows up as 2 nodes in domoticz
1401 0 TempHum Temp + Humidity WTGR800 20.9 C, 35 % 2017-01-19 17:59:05
1400 0 TempHum Temp + Humidity WTGR800 20.7 C, 34 % 2017-01-19 17:59:05
anyone know why?
also this does report every 60sec will this be short battery life?
-
@Eawo Domoticz groups sensors after the order you present them in, see: https://forum.mysensors.org/topic/5132/ds18b20-ans-sht31-d-show-up-as-combined-sensors-on-domoticz/15
I send every 5 minutes and check the value before so that I only send if the value has changed
I have been running my sensor for nearly 2 months now and battery level has only decreased 1-2%
Make sure you use 1 MHz bootloader