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. Control of step down

Control of step down

Scheduled Pinned Locked Moved My Project
20 Posts 3 Posters 5.1k Views 3 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.
  • F flopp

    @AWI
    Yes and no, I am running on batteries and trying to save battery.

    With TLV disable my hardware draw 2uA(tested by pulling out Enable cable)with TLV enabled it draws 35uA

    NRF draws almost nothing but the TLV itself draw 30uA when enabled.

    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by
    #9

    @flopp Just a suggestion: XC6206 (662k) takes only 1uA...

    F 1 Reply Last reply
    0
    • AWIA AWI

      @flopp Just a suggestion: XC6206 (662k) takes only 1uA...

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

      @AWI
      Thanks, looks good.

      Will order and test.

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

        I now have another problem.
        Same sketch but different problem.

        If a use a digital output, I do not have any resistor connected to the digital pin, to enable/disable TLV.

        My problem is when I connect pins for I2C(sda and scl) current for whole project goes up to ~300uA if I disconnect SDA it goes down to ~150uA and disconnect SCL it goes down to ~10uA. 10uA is what I have on other project without I2C

        Very strange for me. It tried to put a 10k between GND and Enable pin on TLV, same current.

        Any ideas.

        Can it help with internal pull-up? I am not home right now so I can't try that right now

        AWIA 1 Reply Last reply
        0
        • F flopp

          I now have another problem.
          Same sketch but different problem.

          If a use a digital output, I do not have any resistor connected to the digital pin, to enable/disable TLV.

          My problem is when I connect pins for I2C(sda and scl) current for whole project goes up to ~300uA if I disconnect SDA it goes down to ~150uA and disconnect SCL it goes down to ~10uA. 10uA is what I have on other project without I2C

          Very strange for me. It tried to put a 10k between GND and Enable pin on TLV, same current.

          Any ideas.

          Can it help with internal pull-up? I am not home right now so I can't try that right now

          AWIA Offline
          AWIA Offline
          AWI
          Hero Member
          wrote on last edited by
          #12

          @flopp Sounds like problems with (internal) pull-ups and signal levels. Can you post the sketch and your design?

          F 1 Reply Last reply
          0
          • AWIA AWI

            @flopp Sounds like problems with (internal) pull-ups and signal levels. Can you post the sketch and your design?

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

            @AWI
            Lots of code that I don't use, I have not clean up yet.

            /**
            * 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 - Henrik Ekblad
            * 
            * DESCRIPTION
            * Pressure sensor example using BMP085 module 
            * http://www.mysensors.org/build/pressure
            *
            */
            
            #include <SPI.h>
            #include <MySensor.h> 
            #include <Wire.h>
            #include <Adafruit_BMP085.h>
            #include <SI7021.h>
            
            #define NODE_ID 3 
            #define BARO_CHILD 0
            #define TEMP_CHILD 1
            #define BATT_CHILD 2
            #define HUM_CHILD 3
            
            const float ALTITUDE = 8; // <-- adapt this value to your own location's altitude.
            
            // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute.
            const unsigned long SLEEP_TIME = 1795000;//1795000=30 min
            
            /*const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
            enum FORECAST
            {
            STABLE = 0,	// "Stable Weather Pattern"
            SUNNY = 1,	// "Slowly rising Good Weather", "Clear/Sunny "
            CLOUDY = 2,	// "Slowly falling L-Pressure ", "Cloudy/Rain "
            UNSTABLE = 3,	// "Quickly rising H-Press", "Not Stable"
            THUNDERSTORM = 4,	// "Quickly falling L-Press", "Thunderstorm"
            UNKNOWN = 5	// "Unknown (More Time needed)
            };
            */
            
            Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor 
            
            //int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
            //int oldBatteryPcnt = 0;
            long result;
            
            MySensor gw;
            
            SI7021 sensor;
            
            int humidity;
            
            //float lastPressure = -1;
            //float lastTemp = -1;
            //int lastForecast = -1;
            
            //const int LAST_SAMPLES_COUNT = 5;
            //float lastPressureSamples[LAST_SAMPLES_COUNT];
            
            float batteryPcnt;
            float batteryVolt;
            //int cycle=6;
            
            // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm
            // get kPa/h be dividing hPa by 10 
            //#define CONVERSION_FACTOR (1.0/10.0)
            
            //int minuteCount = 0;
            //bool firstRound = true;
            // average value is used in forecast algorithm.
            //float pressureAvg;
            // average after 2 hours is used as reference value for the next iteration.
            //float pressureAvg2;
            
            float dP_dt;
            float temperature;
            boolean metric;
            MyMessage tempMsg(TEMP_CHILD, V_TEMP);
            MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
            //MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
            MyMessage battMsg(BATT_CHILD, V_VOLTAGE);
            MyMessage humMsg(HUM_CHILD, V_HUM);
            
            void setup() 
            {
            pinMode(6,OUTPUT);
            digitalWrite(6,HIGH);
            /*
            // use the 1.1 V internal reference
            #if defined(__AVR_ATmega2560__)
            analogReference(INTERNAL1V1);
            #else
            analogReference(INTERNAL);
            #endif
            */
            sensor.begin();
            gw.begin(NULL,NODE_ID);
            
            // Send the sketch version information to the gateway and Controller
            gw.sendSketchInfo("Mini Weather", "1.0");
            
            if (!bmp.begin()) 
            {
            Serial.println("Could not find a valid BMP085 sensor, check wiring!");
            //while (1) {}
            }
            
            // Register sensors to gw (they will be created as child devices)
            gw.present(BARO_CHILD, S_BARO);
            gw.present(TEMP_CHILD, S_TEMP);
            gw.present(BATT_CHILD, S_MULTIMETER);
            gw.present(HUM_CHILD, S_HUM);
            metric = gw.getConfig().isMetric;
            
            
            }
            
            void loop() 
            {
            Serial.println("start");
            digitalWrite(6,HIGH);
            delay(1000);
            gw.begin(NULL,NODE_ID);
            /*
            // get the battery Voltage
            int sensorValue = analogRead(BATTERY_SENSE_PIN);
            #ifdef DEBUG
            Serial.println(sensorValue);
            #endif
            
            // 1M, 470K divider across battery and using internal ADC ref of 1.1V
            // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
            // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
            // ((305400+100000)/100000)*1.1 = Vmax = 4.46 Volts
            // 3.44/1023 = Volts per bit = 0.003363075
            // 4.46/1023 = Volts per bit = 0.0043591398
            //float batteryV = sensorValue * 0.004359140;
            float batteryV = sensorValue * 4.2 / 1023;
            int batteryPcnt = sensorValue / 10;
            
            #ifdef DEBUG
            Serial.print("Battery Voltage: ");
            Serial.print(batteryV);
            Serial.println(" V");
            
            Serial.print("Battery percent: ");
            Serial.print(batteryPcnt);
            Serial.println(" %");
            #endif
            */ 
            int pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
            //	float temperature = bmp.readTemperature();
            
            
            
            //	int forecast = sample(pressure);
            
            //	Serial.print("Temperature = ");
            //	Serial.print(temperature);
            //	Serial.println(metric ? " *C" : " *F");
            
            //Serial.print("Forecast = ");
            //Serial.println(weather[forecast]);
            
            si7021_thc data = sensor.getTempAndRH();
            
            temperature = data.celsiusHundredths/100.0;
            
            humidity = data.humidityPercent;
            
            Serial.print("humidity:");
            Serial.print(humidity);
            Serial.println("%");
            Serial.print("Pressure = ");
            Serial.print(pressure);
            Serial.println(" hPa");
            Serial.print("temperature:");
            Serial.print(temperature);
            Serial.println("°");
            
            
            /*if (temperature != lastTemp) 
            {
            gw.send(tempMsg.set(temperature, 1));
            lastTemp = temperature;
            delay(100);
            }
            
            if (pressure != lastPressure) 
            {
            gw.send(pressureMsg.set(pressure, 0));
            lastPressure = pressure;
            delay(100);
            }
            
            /*if (forecast != lastForecast)
            {
            gw.send(forecastMsg.set(weather[forecast]));
            lastForecast = forecast;
            delay(100);
            }
            */
            readVcc();
            gw.sendBatteryLevel(batteryPcnt);
            gw.send(battMsg.set(batteryVolt, 3));
            
            gw.send(tempMsg.set(temperature, 1));
            //lastTemp = temperature;
            
            gw.send(pressureMsg.set(pressure, 0));
            //lastPressure = pressure;
            
            //gw.send(forecastMsg.set(weather[forecast]));
            //lastForecast = forecast;
            
            gw.send(humMsg.set(humidity, 0));
            
            delay(100);
            //cycle=0;
            
            digitalWrite(6,LOW);
            Serial.println("sleep");
            delay(1000);
            //cycle++;
            gw.sleep(SLEEP_TIME);
            }
            
            /*float getLastPressureSamplesAverage()
            {
            float lastPressureSamplesAverage = 0;
            for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
            {
            lastPressureSamplesAverage += lastPressureSamples[i];
            }
            lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
            
            return lastPressureSamplesAverage;
            }
            
            
            
            // Algorithm found here
            // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
            // Pressure in hPa --> forecast done by calculating kPa/h
            int sample(float pressure)
            {
            // Calculate the average of the last n minutes.
            int index = minuteCount % LAST_SAMPLES_COUNT;
            lastPressureSamples[index] = pressure;
            
            minuteCount++;
            if (minuteCount > 185)
            {
            minuteCount = 6;
            }
            
            if (minuteCount == 5)
            {
            pressureAvg = getLastPressureSamplesAverage();
            }
            else if (minuteCount == 35)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) // first time initial 3 hour
            {
            dP_dt = change * 2; // note this is for t = 0.5hour
            }
            else
            {
            dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
            }
            }
            else if (minuteCount == 65)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) //first time initial 3 hour
            {
            dP_dt = change; //note this is for t = 1 hour
            }
            else
            {
            dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
            }
            }
            else if (minuteCount == 95)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) // first time initial 3 hour
            {
            dP_dt = change / 1.5; // note this is for t = 1.5 hour
            }
            else
            {
            dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
            }
            }
            else if (minuteCount == 125)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            pressureAvg2 = lastPressureAvg; // store for later use.
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) // first time initial 3 hour
            {
            dP_dt = change / 2; // note this is for t = 2 hour
            }
            else
            {
            dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
            }
            }
            else if (minuteCount == 155)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) // first time initial 3 hour
            {
            dP_dt = change / 2.5; // note this is for t = 2.5 hour
            }
            else
            {
            dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
            }
            }
            else if (minuteCount == 185)
            {
            float lastPressureAvg = getLastPressureSamplesAverage();
            float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
            if (firstRound) // first time initial 3 hour
            {
            dP_dt = change / 3; // note this is for t = 3 hour
            }
            else
            {
            dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
            }
            pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
            firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
            }
            
            int forecast = UNKNOWN;
            if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
            {
            forecast = UNKNOWN;
            }
            else if (dP_dt < (-0.25))
            {
            forecast = THUNDERSTORM;
            }
            else if (dP_dt > 0.25)
            {
            forecast = UNSTABLE;
            }
            else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
            {
            forecast = CLOUDY;
            }
            else if ((dP_dt > 0.05) && (dP_dt < 0.25))
            {
            forecast = SUNNY;
            }
            else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
            {
            forecast = STABLE;
            }
            else
            {
            forecast = UNKNOWN;
            }
            
            // uncomment when debugging
            //Serial.print(F("Forecast at minute "));
            //Serial.print(minuteCount);
            //Serial.print(F(" dP/dt = "));
            //Serial.print(dP_dt);
            //Serial.print(F("kPa/h --> "));
            //Serial.println(weather[forecast]);
            
            return forecast;
            }
            */
            long 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;
            batteryPcnt = (result - 3300) * 0.111111;
            batteryVolt = result/1000.000;
            /*Serial.print("battery volt:");
            Serial.println(batteryVolt, 3);
            Serial.print("battery percent:");
            Serial.println(batteryPcnt);
            */
            }```
            AWIA 1 Reply Last reply
            0
            • F flopp

              @AWI
              Lots of code that I don't use, I have not clean up yet.

              /**
              * 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 - Henrik Ekblad
              * 
              * DESCRIPTION
              * Pressure sensor example using BMP085 module 
              * http://www.mysensors.org/build/pressure
              *
              */
              
              #include <SPI.h>
              #include <MySensor.h> 
              #include <Wire.h>
              #include <Adafruit_BMP085.h>
              #include <SI7021.h>
              
              #define NODE_ID 3 
              #define BARO_CHILD 0
              #define TEMP_CHILD 1
              #define BATT_CHILD 2
              #define HUM_CHILD 3
              
              const float ALTITUDE = 8; // <-- adapt this value to your own location's altitude.
              
              // Sleep time between reads (in seconds). Do not change this value as the forecast algorithm needs a sample every minute.
              const unsigned long SLEEP_TIME = 1795000;//1795000=30 min
              
              /*const char *weather[] = { "stable", "sunny", "cloudy", "unstable", "thunderstorm", "unknown" };
              enum FORECAST
              {
              STABLE = 0,	// "Stable Weather Pattern"
              SUNNY = 1,	// "Slowly rising Good Weather", "Clear/Sunny "
              CLOUDY = 2,	// "Slowly falling L-Pressure ", "Cloudy/Rain "
              UNSTABLE = 3,	// "Quickly rising H-Press", "Not Stable"
              THUNDERSTORM = 4,	// "Quickly falling L-Press", "Thunderstorm"
              UNKNOWN = 5	// "Unknown (More Time needed)
              };
              */
              
              Adafruit_BMP085 bmp = Adafruit_BMP085(); // Digital Pressure Sensor 
              
              //int BATTERY_SENSE_PIN = A0; // select the input pin for the battery sense point
              //int oldBatteryPcnt = 0;
              long result;
              
              MySensor gw;
              
              SI7021 sensor;
              
              int humidity;
              
              //float lastPressure = -1;
              //float lastTemp = -1;
              //int lastForecast = -1;
              
              //const int LAST_SAMPLES_COUNT = 5;
              //float lastPressureSamples[LAST_SAMPLES_COUNT];
              
              float batteryPcnt;
              float batteryVolt;
              //int cycle=6;
              
              // this CONVERSION_FACTOR is used to convert from Pa to kPa in forecast algorithm
              // get kPa/h be dividing hPa by 10 
              //#define CONVERSION_FACTOR (1.0/10.0)
              
              //int minuteCount = 0;
              //bool firstRound = true;
              // average value is used in forecast algorithm.
              //float pressureAvg;
              // average after 2 hours is used as reference value for the next iteration.
              //float pressureAvg2;
              
              float dP_dt;
              float temperature;
              boolean metric;
              MyMessage tempMsg(TEMP_CHILD, V_TEMP);
              MyMessage pressureMsg(BARO_CHILD, V_PRESSURE);
              //MyMessage forecastMsg(BARO_CHILD, V_FORECAST);
              MyMessage battMsg(BATT_CHILD, V_VOLTAGE);
              MyMessage humMsg(HUM_CHILD, V_HUM);
              
              void setup() 
              {
              pinMode(6,OUTPUT);
              digitalWrite(6,HIGH);
              /*
              // use the 1.1 V internal reference
              #if defined(__AVR_ATmega2560__)
              analogReference(INTERNAL1V1);
              #else
              analogReference(INTERNAL);
              #endif
              */
              sensor.begin();
              gw.begin(NULL,NODE_ID);
              
              // Send the sketch version information to the gateway and Controller
              gw.sendSketchInfo("Mini Weather", "1.0");
              
              if (!bmp.begin()) 
              {
              Serial.println("Could not find a valid BMP085 sensor, check wiring!");
              //while (1) {}
              }
              
              // Register sensors to gw (they will be created as child devices)
              gw.present(BARO_CHILD, S_BARO);
              gw.present(TEMP_CHILD, S_TEMP);
              gw.present(BATT_CHILD, S_MULTIMETER);
              gw.present(HUM_CHILD, S_HUM);
              metric = gw.getConfig().isMetric;
              
              
              }
              
              void loop() 
              {
              Serial.println("start");
              digitalWrite(6,HIGH);
              delay(1000);
              gw.begin(NULL,NODE_ID);
              /*
              // get the battery Voltage
              int sensorValue = analogRead(BATTERY_SENSE_PIN);
              #ifdef DEBUG
              Serial.println(sensorValue);
              #endif
              
              // 1M, 470K divider across battery and using internal ADC ref of 1.1V
              // Sense point is bypassed with 0.1 uF cap to reduce noise at that point
              // ((1e6+470e3)/470e3)*1.1 = Vmax = 3.44 Volts
              // ((305400+100000)/100000)*1.1 = Vmax = 4.46 Volts
              // 3.44/1023 = Volts per bit = 0.003363075
              // 4.46/1023 = Volts per bit = 0.0043591398
              //float batteryV = sensorValue * 0.004359140;
              float batteryV = sensorValue * 4.2 / 1023;
              int batteryPcnt = sensorValue / 10;
              
              #ifdef DEBUG
              Serial.print("Battery Voltage: ");
              Serial.print(batteryV);
              Serial.println(" V");
              
              Serial.print("Battery percent: ");
              Serial.print(batteryPcnt);
              Serial.println(" %");
              #endif
              */ 
              int pressure = bmp.readSealevelPressure(ALTITUDE) / 100.0;
              //	float temperature = bmp.readTemperature();
              
              
              
              //	int forecast = sample(pressure);
              
              //	Serial.print("Temperature = ");
              //	Serial.print(temperature);
              //	Serial.println(metric ? " *C" : " *F");
              
              //Serial.print("Forecast = ");
              //Serial.println(weather[forecast]);
              
              si7021_thc data = sensor.getTempAndRH();
              
              temperature = data.celsiusHundredths/100.0;
              
              humidity = data.humidityPercent;
              
              Serial.print("humidity:");
              Serial.print(humidity);
              Serial.println("%");
              Serial.print("Pressure = ");
              Serial.print(pressure);
              Serial.println(" hPa");
              Serial.print("temperature:");
              Serial.print(temperature);
              Serial.println("°");
              
              
              /*if (temperature != lastTemp) 
              {
              gw.send(tempMsg.set(temperature, 1));
              lastTemp = temperature;
              delay(100);
              }
              
              if (pressure != lastPressure) 
              {
              gw.send(pressureMsg.set(pressure, 0));
              lastPressure = pressure;
              delay(100);
              }
              
              /*if (forecast != lastForecast)
              {
              gw.send(forecastMsg.set(weather[forecast]));
              lastForecast = forecast;
              delay(100);
              }
              */
              readVcc();
              gw.sendBatteryLevel(batteryPcnt);
              gw.send(battMsg.set(batteryVolt, 3));
              
              gw.send(tempMsg.set(temperature, 1));
              //lastTemp = temperature;
              
              gw.send(pressureMsg.set(pressure, 0));
              //lastPressure = pressure;
              
              //gw.send(forecastMsg.set(weather[forecast]));
              //lastForecast = forecast;
              
              gw.send(humMsg.set(humidity, 0));
              
              delay(100);
              //cycle=0;
              
              digitalWrite(6,LOW);
              Serial.println("sleep");
              delay(1000);
              //cycle++;
              gw.sleep(SLEEP_TIME);
              }
              
              /*float getLastPressureSamplesAverage()
              {
              float lastPressureSamplesAverage = 0;
              for (int i = 0; i < LAST_SAMPLES_COUNT; i++)
              {
              lastPressureSamplesAverage += lastPressureSamples[i];
              }
              lastPressureSamplesAverage /= LAST_SAMPLES_COUNT;
              
              return lastPressureSamplesAverage;
              }
              
              
              
              // Algorithm found here
              // http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
              // Pressure in hPa --> forecast done by calculating kPa/h
              int sample(float pressure)
              {
              // Calculate the average of the last n minutes.
              int index = minuteCount % LAST_SAMPLES_COUNT;
              lastPressureSamples[index] = pressure;
              
              minuteCount++;
              if (minuteCount > 185)
              {
              minuteCount = 6;
              }
              
              if (minuteCount == 5)
              {
              pressureAvg = getLastPressureSamplesAverage();
              }
              else if (minuteCount == 35)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) // first time initial 3 hour
              {
              dP_dt = change * 2; // note this is for t = 0.5hour
              }
              else
              {
              dP_dt = change / 1.5; // divide by 1.5 as this is the difference in time from 0 value.
              }
              }
              else if (minuteCount == 65)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) //first time initial 3 hour
              {
              dP_dt = change; //note this is for t = 1 hour
              }
              else
              {
              dP_dt = change / 2; //divide by 2 as this is the difference in time from 0 value
              }
              }
              else if (minuteCount == 95)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) // first time initial 3 hour
              {
              dP_dt = change / 1.5; // note this is for t = 1.5 hour
              }
              else
              {
              dP_dt = change / 2.5; // divide by 2.5 as this is the difference in time from 0 value
              }
              }
              else if (minuteCount == 125)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              pressureAvg2 = lastPressureAvg; // store for later use.
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) // first time initial 3 hour
              {
              dP_dt = change / 2; // note this is for t = 2 hour
              }
              else
              {
              dP_dt = change / 3; // divide by 3 as this is the difference in time from 0 value
              }
              }
              else if (minuteCount == 155)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) // first time initial 3 hour
              {
              dP_dt = change / 2.5; // note this is for t = 2.5 hour
              }
              else
              {
              dP_dt = change / 3.5; // divide by 3.5 as this is the difference in time from 0 value
              }
              }
              else if (minuteCount == 185)
              {
              float lastPressureAvg = getLastPressureSamplesAverage();
              float change = (lastPressureAvg - pressureAvg) * CONVERSION_FACTOR;
              if (firstRound) // first time initial 3 hour
              {
              dP_dt = change / 3; // note this is for t = 3 hour
              }
              else
              {
              dP_dt = change / 4; // divide by 4 as this is the difference in time from 0 value
              }
              pressureAvg = pressureAvg2; // Equating the pressure at 0 to the pressure at 2 hour after 3 hours have past.
              firstRound = false; // flag to let you know that this is on the past 3 hour mark. Initialized to 0 outside main loop.
              }
              
              int forecast = UNKNOWN;
              if (minuteCount < 35 && firstRound) //if time is less than 35 min on the first 3 hour interval.
              {
              forecast = UNKNOWN;
              }
              else if (dP_dt < (-0.25))
              {
              forecast = THUNDERSTORM;
              }
              else if (dP_dt > 0.25)
              {
              forecast = UNSTABLE;
              }
              else if ((dP_dt > (-0.25)) && (dP_dt < (-0.05)))
              {
              forecast = CLOUDY;
              }
              else if ((dP_dt > 0.05) && (dP_dt < 0.25))
              {
              forecast = SUNNY;
              }
              else if ((dP_dt >(-0.05)) && (dP_dt < 0.05))
              {
              forecast = STABLE;
              }
              else
              {
              forecast = UNKNOWN;
              }
              
              // uncomment when debugging
              //Serial.print(F("Forecast at minute "));
              //Serial.print(minuteCount);
              //Serial.print(F(" dP/dt = "));
              //Serial.print(dP_dt);
              //Serial.print(F("kPa/h --> "));
              //Serial.println(weather[forecast]);
              
              return forecast;
              }
              */
              long 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;
              batteryPcnt = (result - 3300) * 0.111111;
              batteryVolt = result/1000.000;
              /*Serial.print("battery volt:");
              Serial.println(batteryVolt, 3);
              Serial.print("battery percent:");
              Serial.println(batteryPcnt);
              */
              }```
              AWIA Offline
              AWIA Offline
              AWI
              Hero Member
              wrote on last edited by
              #14

              @flopp and your circuit? Which are your I2C devices and do you power them down while sleeping?

              F 1 Reply Last reply
              0
              • AWIA AWI

                @flopp and your circuit? Which are your I2C devices and do you power them down while sleeping?

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

                @AWI

                mysensorsboard_nocharge.pdf

                BMP180 and Si7021. Yes, I set LOW on digital 6, so TLV is powered down, right before SLEEP

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

                  @AWI
                  Added PDF

                  AWIA 1 Reply Last reply
                  0
                  • F flopp

                    @AWI
                    Added PDF

                    AWIA Offline
                    AWIA Offline
                    AWI
                    Hero Member
                    wrote on last edited by
                    #17

                    @flopp I cannot find it in the datasheets but I can imagine that the BMP180 and/or si7021 kind of "short" their inputs to ground when power drops to down to Grnd. This would connect the pullups to grn explaining the rise in consumption. Both these sensors take around 0.1 uA in standby so I don't see a need to power them down.

                    F 1 Reply Last reply
                    0
                    • AWIA AWI

                      @flopp I cannot find it in the datasheets but I can imagine that the BMP180 and/or si7021 kind of "short" their inputs to ground when power drops to down to Grnd. This would connect the pullups to grn explaining the rise in consumption. Both these sensors take around 0.1 uA in standby so I don't see a need to power them down.

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

                      @AWI

                      Thanks for you time.
                      I have also NRF connected to TLV, so I power down that one also.

                      If I don't power down my project draw ~60 uA, which I can live with but when power down it will be ~10 uA, that is 1/6.
                      I run on battery so that is something I want to be able to do.

                      I will try to have only BMP180 and also test to only have Si7021.

                      AWIA 1 Reply Last reply
                      0
                      • F flopp

                        @AWI

                        Thanks for you time.
                        I have also NRF connected to TLV, so I power down that one also.

                        If I don't power down my project draw ~60 uA, which I can live with but when power down it will be ~10 uA, that is 1/6.
                        I run on battery so that is something I want to be able to do.

                        I will try to have only BMP180 and also test to only have Si7021.

                        AWIA Offline
                        AWIA Offline
                        AWI
                        Hero Member
                        wrote on last edited by
                        #19

                        @flopp One of my nodes, equipped with the same sensors (si7021/ bmp180 and nrf) including the electronics (LDO level conversion etc.) on the sensor boards is consuming around 12uA during sleep. The sensors are all powered from the same LDO (662k).

                        F 1 Reply Last reply
                        0
                        • AWIA AWI

                          @flopp One of my nodes, equipped with the same sensors (si7021/ bmp180 and nrf) including the electronics (LDO level conversion etc.) on the sensor boards is consuming around 12uA during sleep. The sensors are all powered from the same LDO (662k).

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

                          @AWI
                          Thank again.

                          I found one 662K at home.

                          Now it draws ~19uA with everything connected: arduino pro mini(clone), NRF, si7021 and bmp180(without 662k) This is good enough.

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


                          18

                          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