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. Troubleshooting
  3. Sleep mode/Read Vcc issue

Sleep mode/Read Vcc issue

Scheduled Pinned Locked Moved Troubleshooting
12 Posts 5 Posters 3.3k Views 5 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.
  • engyE Offline
    engyE Offline
    engy
    wrote on last edited by
    #1

    Hello,

    I'm made temp/hum sensor with slim node and DHT22.
    When Mysensors/HumiditySensor sketch is loaded, the sensor in sleep mode consumes 25uA.

    I also would like to report battery level.
    But when read vcc function is included in the sketch, the power consumtions after transmission remains ~ 0.1 - 0.2mA.

    Any ideas why sleep mode is not functioning correctly with sendBatteryReport()?
    Thank you in advance.

    Please see my updated sketch:

    #include <SPI.h>
    #include <MySensor.h>  
    #include <DHT.h>
    #include <Vcc.h>
    
    #define VCC_MIN 2.8
    #define VCC_MAX 3.3
    Vcc vcc;
    #define NODE_ID 2
    
    #define CHILD_ID_HUM 0
    #define CHILD_ID_TEMP 1
    #define HUMIDITY_SENSOR_DIGITAL_PIN 3
    unsigned long SLEEP_TIME = 120000; // Sleep time between reads (in milliseconds)
    
    MySensor gw;
    DHT dht;
    float lastTemp;
    float lastHum;
    boolean metric = true; 
    MyMessage msgHum(CHILD_ID_HUM, V_HUM);
    MyMessage msgTemp(CHILD_ID_TEMP, V_TEMP);
    
    
    void setup()  
    { 
      gw.begin(NULL, NODE_ID);
      dht.setup(HUMIDITY_SENSOR_DIGITAL_PIN); 
    
      // Send the Sketch Version Information to the Gateway
      gw.sendSketchInfo("Humidity", "1.0");
    
      // Register all sensors to gw (they will be created as child devices)
      gw.present(CHILD_ID_HUM, S_HUM);
      gw.present(CHILD_ID_TEMP, S_TEMP);
      
      metric = gw.getConfig().isMetric;
    }
    
    void loop()      
    {  
      sendBatteryReport();
      delay(dht.getMinimumSamplingPeriod());
    
      float temperature = dht.getTemperature();
      if (isnan(temperature)) {
          Serial.println("Failed reading temperature from DHT");
      } else if (temperature != lastTemp) {
        lastTemp = temperature;
        if (!metric) {
          temperature = dht.toFahrenheit(temperature);
        }
        gw.send(msgTemp.set(temperature, 1));
        Serial.print("T: ");
        Serial.println(temperature);
      }
      
      float humidity = dht.getHumidity();
      if (isnan(humidity)) {
          Serial.println("Failed reading humidity from DHT");
      } else if (humidity != lastHum) {
          lastHum = humidity;
          gw.send(msgHum.set(humidity, 1));
    
          Serial.print("H: ");
          Serial.println(humidity);
      }
    
      gw.sleep(SLEEP_TIME); //sleep a bit
    }
    
    void sendBatteryReport() {
              float p = vcc.Read_Perc(VCC_MIN, VCC_MAX, true);
              int batteryPcnt = static_cast<int>(p);
              gw.sendBatteryLevel(batteryPcnt);
    }
    
    
    1 Reply Last reply
    0
    • AWIA Offline
      AWIA Offline
      AWI
      Hero Member
      wrote on last edited by AWI
      #2

      To give you at least a response. I have no clue... ;-) I use a lot of low power nodes and the vcc library. My only guess is that it could have something to do with the supply voltage begin insufficient to get readings from the DHT sensor.

      1 Reply Last reply
      0
      • engyE Offline
        engyE Offline
        engy
        wrote on last edited by
        #3

        I'm not sure if it's related to DHT22, because sleep mode works fine when Vcc function is commented in the sketch.

        1 Reply Last reply
        0
        • mfalkviddM Offline
          mfalkviddM Offline
          mfalkvidd
          Mod
          wrote on last edited by
          #4

          Maybe you could try to move sendBatteryReport(); from loop to setup and see if it makes a difference if vcc is only called once.

          1 Reply Last reply
          0
          • F Offline
            F Offline
            flopp
            wrote on last edited by flopp
            #5

            I dont use vcc.h i use this code at the bottom of my sketch

            long readVcc() {
            Serial.println("readVcc");
            // Read 1.1V reference against AVcc
            ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
            delay(2); // Wait for Vref to settle
            ADCSRA |= _BV(ADSC); // Convert
            while (bit_is_set(ADCSRA,ADSC));
            result = ADCL;
            result |= ADCH<<8;
            result = 1126400L / result; // Back-calculate AVcc in mV
            //return result;
            //gw.begin(incomingMessage,node_id, false)
            batteryPcnt = (result - 3300) * 0.111111;
            batteryVolt = result/1000.000;
            gw.sendBatteryLevel(batteryPcnt);
            gw.send(battMsg.set(batteryVolt, 3));
            /*Serial.print("battery volt:");
            Serial.println(batteryVolt, 3);
            Serial.print("battery percent:");
            Serial.println(batteryPcnt);
            */
            }
            

            how does you vcc.h look like

            m26872M 1 Reply Last reply
            0
            • F flopp

              I dont use vcc.h i use this code at the bottom of my sketch

              long readVcc() {
              Serial.println("readVcc");
              // Read 1.1V reference against AVcc
              ADMUX = _BV(REFS0) | _BV(MUX3) | _BV(MUX2) | _BV(MUX1);
              delay(2); // Wait for Vref to settle
              ADCSRA |= _BV(ADSC); // Convert
              while (bit_is_set(ADCSRA,ADSC));
              result = ADCL;
              result |= ADCH<<8;
              result = 1126400L / result; // Back-calculate AVcc in mV
              //return result;
              //gw.begin(incomingMessage,node_id, false)
              batteryPcnt = (result - 3300) * 0.111111;
              batteryVolt = result/1000.000;
              gw.sendBatteryLevel(batteryPcnt);
              gw.send(battMsg.set(batteryVolt, 3));
              /*Serial.print("battery volt:");
              Serial.println(batteryVolt, 3);
              Serial.print("battery percent:");
              Serial.println(batteryPcnt);
              */
              }
              

              how does you vcc.h look like

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

              @flopp
              You shouldn't need your own readVcc() code like that since you're including the Vcc library in the beginning of the sketch. Make sure you have the vcc-lib in your Arduino folder:
              https://github.com/Yveaux/Arduino_Vcc

              F 1 Reply Last reply
              0
              • mfalkviddM Offline
                mfalkviddM Offline
                mfalkvidd
                Mod
                wrote on last edited by mfalkvidd
                #7

                If you use the readVcc function in flopp's sketch, remove gw.begin(incomingMessage, NODE_ID, false);
                Calling gw.begin several times seems strange.

                F 1 Reply Last reply
                0
                • mfalkviddM mfalkvidd

                  If you use the readVcc function in flopp's sketch, remove gw.begin(incomingMessage, NODE_ID, false);
                  Calling gw.begin several times seems strange.

                  F Offline
                  F Offline
                  flopp
                  wrote on last edited by
                  #8

                  @mfalkvidd
                  Sorry that line I don't use anymore. Code must be copied from an old sketch where I was using an LDO that I disabled and when power was back I have to run gw.begin again otherwise I could send anything.
                  I have now comment that row out.
                  Thanks for noticing

                  1 Reply Last reply
                  0
                  • m26872M m26872

                    @flopp
                    You shouldn't need your own readVcc() code like that since you're including the Vcc library in the beginning of the sketch. Make sure you have the vcc-lib in your Arduino folder:
                    https://github.com/Yveaux/Arduino_Vcc

                    F Offline
                    F Offline
                    flopp
                    wrote on last edited by
                    #9

                    @m26872
                    I don't use vcc.h I like to have it in the bottom of the sketch.
                    Is it better to have it in a seperate file?
                    Except that it looks cleaner?

                    1 Reply Last reply
                    0
                    • mfalkviddM Offline
                      mfalkviddM Offline
                      mfalkvidd
                      Mod
                      wrote on last edited by mfalkvidd
                      #10

                      @engy: just a note: the sketch you posted has #include <Vcc.h>

                      You should either include Vcc.h OR include readVcc() in your sketch. Not both.

                      F 1 Reply Last reply
                      0
                      • mfalkviddM mfalkvidd

                        @engy: just a note: the sketch you posted has #include <Vcc.h>

                        You should either include Vcc.h OR include readVcc() in your sketch. Not both.

                        F Offline
                        F Offline
                        flopp
                        wrote on last edited by
                        #11
                        This post is deleted!
                        1 Reply Last reply
                        0
                        • engyE Offline
                          engyE Offline
                          engy
                          wrote on last edited by
                          #12

                          The problem was faulty NRF24... another batch :(
                          Just powered sensor in sleep mode is consuming as expected - a few uA.
                          But later, after while, power consumption is increasing.
                          Commenting Vcc was just coincidence.

                          Received new NRFs batch from mysensors shop, and all the problems gone.
                          Thanks!

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


                          19

                          Online

                          11.7k

                          Users

                          11.2k

                          Topics

                          113.1k

                          Posts


                          Copyright 2025 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