Skip to content
  • MySensors
  • OpenHardware.io
  • Categories
  • Recent
  • Tags
  • Popular
Skins
  • Light
  • Brite
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Brand Logo
  1. Home
  2. My Project
  3. Slim Node Si7021 sensor example

Slim Node Si7021 sensor example

Scheduled Pinned Locked Moved My Project
137 Posts 18 Posters 64.8k Views 20 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wergeld
    wrote on last edited by
    #106

    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.

    1 Reply Last reply
    0
    • W Offline
      W Offline
      wergeld
      wrote on last edited by
      #107

      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.

      m26872M 1 Reply Last reply
      0
      • W wergeld

        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.

        m26872M Offline
        m26872M Offline
        m26872
        Hardware Contributor
        wrote on last edited by
        #108

        @wergeld It looks like it's set to 3 hrs.

        W 1 Reply Last reply
        0
        • m26872M m26872

          @wergeld It looks like it's set to 3 hrs.

          W Offline
          W Offline
          wergeld
          wrote on last edited by
          #109

          @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:

          1. Gateway (serial or the direct connect nrf+ once it supports v2)
          2. Temp/Hum node using HTU21D for back porch sending every 5 minutes and force send every 30 minutes.
          3. Temp/Hum node using HTU21D inside using same send times.
          4. Parking sensor in garage hardwired to mains.
            5 & 6 I am not sure yet.

          Lots of fun so far.

          1 Reply Last reply
          0
          • W Offline
            W Offline
            wergeld
            wrote on last edited by
            #110

            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?

            GertSandersG 1 Reply Last reply
            0
            • W wergeld

              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?

              GertSandersG Offline
              GertSandersG Offline
              GertSanders
              Hardware Contributor
              wrote on last edited by
              #111

              @wergeld

              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.

              W 1 Reply Last reply
              0
              • GertSandersG GertSanders

                @wergeld

                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.

                W Offline
                W Offline
                wergeld
                wrote on last edited by
                #112

                @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

                1 Reply Last reply
                0
                • clempatC Offline
                  clempatC Offline
                  clempat
                  wrote on last edited by clempat
                  #113

                  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
                  
                  clempatC 1 Reply Last reply
                  0
                  • clempatC clempat

                    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
                    
                    clempatC Offline
                    clempatC Offline
                    clempat
                    wrote on last edited by
                    #114

                    Why actually my device id is 50 ? for what 50 stands !?!?!

                    m26872M 1 Reply Last reply
                    0
                    • clempatC clempat

                      Why actually my device id is 50 ? for what 50 stands !?!?!

                      m26872M Offline
                      m26872M Offline
                      m26872
                      Hardware Contributor
                      wrote on last edited by
                      #115

                      @clempat Please post your sketch and maybe some hardware photo or diagram too.

                      clempatC 1 Reply Last reply
                      0
                      • m26872M m26872

                        @clempat Please post your sketch and maybe some hardware photo or diagram too.

                        clempatC Offline
                        clempatC Offline
                        clempat
                        wrote on last edited by
                        #116

                        @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:

                        0_1476384593511_IMG_2599.JPG

                        0_1476384602827_IMG_2600.JPG

                        0_1476384624213_IMG_2601.JPG

                        0_1476384641766_IMG_2602.JPG

                        m26872M 1 Reply Last reply
                        0
                        • clempatC clempat

                          @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:

                          0_1476384593511_IMG_2599.JPG

                          0_1476384602827_IMG_2600.JPG

                          0_1476384624213_IMG_2601.JPG

                          0_1476384641766_IMG_2602.JPG

                          m26872M Offline
                          m26872M Offline
                          m26872
                          Hardware Contributor
                          wrote on last edited by
                          #117

                          @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. :thumbsup:

                          clempatC 1 Reply Last reply
                          1
                          • m26872M m26872

                            @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. :thumbsup:

                            clempatC Offline
                            clempatC Offline
                            clempat
                            wrote on last edited by
                            #118

                            @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.

                            1 Reply Last reply
                            0
                            • clempatC Offline
                              clempatC Offline
                              clempat
                              wrote on last edited by
                              #119

                              Ok with the arduino micro 8Mhz all works good too.

                              Reading...
                              T: 20.29
                              H: 54
                              device ID: 50
                              
                              1 Reply Last reply
                              0
                              • clempatC Offline
                                clempatC Offline
                                clempat
                                wrote on last edited by
                                #120

                                So sad I still not getting it working with the slim node :( !!! Always same result either with internal 1mhz or 8mhz...

                                m26872M 1 Reply Last reply
                                0
                                • clempatC clempat

                                  So sad I still not getting it working with the slim node :( !!! Always same result either with internal 1mhz or 8mhz...

                                  m26872M Offline
                                  m26872M Offline
                                  m26872
                                  Hardware Contributor
                                  wrote on last edited by
                                  #121

                                  @clempat Make it with external 8MHz then ? Then it should be like a Pro Mini 3.3V.

                                  clempatC 1 Reply Last reply
                                  0
                                  • m26872M m26872

                                    @clempat Make it with external 8MHz then ? Then it should be like a Pro Mini 3.3V.

                                    clempatC Offline
                                    clempatC Offline
                                    clempat
                                    wrote on last edited by
                                    #122

                                    @m26872 I will give a try and let you know... Thanks.

                                    1 Reply Last reply
                                    0
                                    • miljumeM Offline
                                      miljumeM Offline
                                      miljume
                                      wrote on last edited by
                                      #123

                                      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 happens

                                      I 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
                                      
                                      }
                                      
                                      
                                      
                                      1 Reply Last reply
                                      0
                                      • m26872M Offline
                                        m26872M Offline
                                        m26872
                                        Hardware Contributor
                                        wrote on last edited by
                                        #124

                                        It would be interesting if someone with issues also tried older versions of libs for Si7021 and/or MySensors.

                                        1 Reply Last reply
                                        0
                                        • W Offline
                                          W Offline
                                          wergeld
                                          wrote on last edited by
                                          #125

                                          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!

                                          0_1482948446815_outsideHTU21D.jpeg

                                          All good times with the learning!

                                          m26872M 1 Reply Last reply
                                          0
                                          Reply
                                          • Reply as topic
                                          Log in to reply
                                          • Oldest to Newest
                                          • Newest to Oldest
                                          • Most Votes


                                          14

                                          Online

                                          11.7k

                                          Users

                                          11.2k

                                          Topics

                                          113.0k

                                          Posts


                                          Copyright 2019 TBD   |   Forum Guidelines   |   Privacy Policy   |   Terms of Service
                                          • Login

                                          • Don't have an account? Register

                                          • Login or register to search.
                                          • First post
                                            Last post
                                          0
                                          • MySensors
                                          • OpenHardware.io
                                          • Categories
                                          • Recent
                                          • Tags
                                          • Popular