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. My Slim 2AA Battery Node

My Slim 2AA Battery Node

Scheduled Pinned Locked Moved My Project
498 Posts 71 Posters 342.6k Views 69 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.
  • Tim AbelsT Tim Abels

    @AWI: I am down to 1,3 µA :+1:

    my code:

    //#define MY_DEBUG
    #define MY_RADIO_NRF24
    #define MY_NODE_ID 66
    #define MY_PARENT_NODE_ID 0
    #define MY_PARENT_NODE_IS_STATIC
    
    #include <MySensors.h>
    #include "Vcc.h"
    
    #define SKETCH_NAME "MySlim2aaBatteryNode"
    
    #define PRIMARY_CHILD_ID 3
    #define PRIMARY_BUTTON_PIN 3
    
    MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
    
    const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
    const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
    const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
    
    const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
    
    Vcc vcc(VccCorrection);
    
    #ifdef MY_DEBUG
    void before(){
        Serial.begin(9600);
    }
    #endif
    
    void setup()
    {
        pinMode(PRIMARY_BUTTON_PIN, INPUT);
    }
    
    void presentation()
    {
        sendSketchInfo(SKETCH_NAME, __DATE__);
        present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
    }
    
    void loop()
    {
        int32_t timestamp = millis();
    
        uint8_t reedState;
        static uint8_t lastReedState = 2;
        static int32_t lastBatteryReport = -report_interval; // for inital report
        sleep(5); // Short delay to allow buttons to properly settle
    
        reedState = digitalRead(PRIMARY_BUTTON_PIN);
    
        if ( (timestamp-lastBatteryReport) >= report_interval ) {
          uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
          sendBatteryLevel(batteryPercent);
          lastBatteryReport = timestamp;
        }
    
        if (reedState != lastReedState) {
            // Value has changed from last transmission, send the updated reedState
            send(msg.set(reedState==HIGH));
            lastReedState = reedState;
        }
    
        sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
    }
    
    
    AWIA Offline
    AWIA Offline
    AWI
    Hero Member
    wrote on last edited by AWI
    #398

    @Tim-Abels :+1: that is how you do it

    Be aware that the timer (millis()) is not running during sleep.

    rollercontainerR 1 Reply Last reply
    1
    • Tim AbelsT Tim Abels

      @AWI: I am down to 1,3 µA :+1:

      my code:

      //#define MY_DEBUG
      #define MY_RADIO_NRF24
      #define MY_NODE_ID 66
      #define MY_PARENT_NODE_ID 0
      #define MY_PARENT_NODE_IS_STATIC
      
      #include <MySensors.h>
      #include "Vcc.h"
      
      #define SKETCH_NAME "MySlim2aaBatteryNode"
      
      #define PRIMARY_CHILD_ID 3
      #define PRIMARY_BUTTON_PIN 3
      
      MyMessage msg(PRIMARY_CHILD_ID, V_TRIPPED);
      
      const float VccMin   = 1.7;           // Minimum expected Vcc level, in Volts.
      const float VccMax   = 3.3;           // Maximum expected Vcc level, in Volts.
      const float VccCorrection = 3.496 / 3.572;  // Measured Vcc by multimeter divided by reported Vcc
      
      const int32_t report_interval = 8640000; // 1day -> h * m * s * ms NOTICE: milliseconds, not microseconds!
      
      Vcc vcc(VccCorrection);
      
      #ifdef MY_DEBUG
      void before(){
          Serial.begin(9600);
      }
      #endif
      
      void setup()
      {
          pinMode(PRIMARY_BUTTON_PIN, INPUT);
      }
      
      void presentation()
      {
          sendSketchInfo(SKETCH_NAME, __DATE__);
          present(PRIMARY_CHILD_ID, S_DOOR, "Reed Contact");
      }
      
      void loop()
      {
          int32_t timestamp = millis();
      
          uint8_t reedState;
          static uint8_t lastReedState = 2;
          static int32_t lastBatteryReport = -report_interval; // for inital report
          sleep(5); // Short delay to allow buttons to properly settle
      
          reedState = digitalRead(PRIMARY_BUTTON_PIN);
      
          if ( (timestamp-lastBatteryReport) >= report_interval ) {
            uint8_t batteryPercent = (uint8_t)vcc.Read_Perc(VccMin, VccMax);
            sendBatteryLevel(batteryPercent);
            lastBatteryReport = timestamp;
          }
      
          if (reedState != lastReedState) {
              // Value has changed from last transmission, send the updated reedState
              send(msg.set(reedState==HIGH));
              lastReedState = reedState;
          }
      
          sleep(PRIMARY_BUTTON_PIN-2, CHANGE, 0);
      }
      
      
      m26872M Offline
      m26872M Offline
      m26872
      Hardware Contributor
      wrote on last edited by m26872
      #399

      @Tim-Abels
      1.3uA is nice!
      A question about your sketch: Is millis() working because it's an interrupt-only sleep() or have I missed something else? As I recall it millis() stops working when using sleep().
      Edit: Haha. @AWI got it before me! :smile:

      1 Reply Last reply
      1
      • AWIA AWI

        @Tim-Abels :+1: that is how you do it

        Be aware that the timer (millis()) is not running during sleep.

        rollercontainerR Offline
        rollercontainerR Offline
        rollercontainer
        wrote on last edited by
        #400

        @AWI one step forward, two steps back... Thanks for the hint.

        I guess, I should send battery percentage every 10 interrupts or so. Even if the contact doesn't trigger for a while, I can force it by showing my neighbours my ocd on doors ^^ (knock, knock, knock - Penny!)

        What do you think?

        AWIA 1 Reply Last reply
        1
        • rollercontainerR Offline
          rollercontainerR Offline
          rollercontainer
          wrote on last edited by
          #401

          Just noticed, that I use another login at home. So, the Tim-Abels is the rollercontainer... Sorry for that.

          1 Reply Last reply
          0
          • rollercontainerR rollercontainer

            @AWI one step forward, two steps back... Thanks for the hint.

            I guess, I should send battery percentage every 10 interrupts or so. Even if the contact doesn't trigger for a while, I can force it by showing my neighbours my ocd on doors ^^ (knock, knock, knock - Penny!)

            What do you think?

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

            @rollercontainer alias @Tim-Abels ;-) Sounds good, although with 1.3uA the battery won't show much variation..

            This is a similar on running on a coin cell (not calibrated). The voltage drop is caused mainly by the bad radio connection (many retries for sending > 10 mA)

            0_1487319381911_upload-02a06ce9-126d-49f2-bbcb-dd01c3cea3d4

            1 Reply Last reply
            0
            • rollercontainerR Offline
              rollercontainerR Offline
              rollercontainer
              wrote on last edited by rollercontainer
              #403

              Maybe its better to measure the voltage every 10 or 100 loops and only send one custom message/alert when its dropped below a threshold. I am using the MQTTClientGateway and Node-Red. In case of a battery-low message, node-red could send me an email with the node name. I will give it a try...

              From https://www.mysensors.org/download/serial_api_20:

              V_TEXT          47 	Text message to display on LCD or controller device 	S_INFO
              V_CUSTOM 	48 	Custom messages used for controller/inter node specific commands, preferably using S_CUSTOM device type. 	S_CUSTOM```
              1 Reply Last reply
              0
              • rollercontainerR Offline
                rollercontainerR Offline
                rollercontainer
                wrote on last edited by
                #404

                Did you considered a tiny solar cell like enocean does?
                https://www.enocean.com/en/enocean_modules/stm-320/
                That would be perfect...

                1 Reply Last reply
                1
                • rollercontainerR Offline
                  rollercontainerR Offline
                  rollercontainer
                  wrote on last edited by
                  #405

                  searched a bit and found that @ceech already made a harvester with a coin cell.

                  http://www.ebay.de/itm/BQ25570-thermal-solar-energy-harvester-/332071662285

                  still too big and too expensive in comparison with dozens of alkaline batteries which will run for years, but that is the way to go sometime.

                  1 Reply Last reply
                  0
                  • m26872M m26872

                    @siod
                    Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                    What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                    siodS Offline
                    siodS Offline
                    siod
                    wrote on last edited by
                    #406

                    @m26872 said in My Slim 2AA Battery Node:

                    @siod
                    Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                    What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                    @m26872
                    Gateway seems to work fine as the 3rd and still working sensor is still communicating. Also the freezed sensors start communicating after I restarted the sensor, not the GW. So I don´t see a problem with the GW.
                    "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?
                    I have not attached a heartbeat LED yet, but that´s sth. I could do as a next step...
                    The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...
                    You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                    Thanks so far!!

                    still learning...

                    m26872M 1 Reply Last reply
                    0
                    • siodS siod

                      @m26872 said in My Slim 2AA Battery Node:

                      @siod
                      Gateway issue? Other sensors working or all down at same time? Do you have a sniffer or listen-only gateway, or heartbeat LED attached to each sensor?

                      What's the purpose of the delay(1000)? It usually safer to use wait() or sleep() and perhaps also to deal with the interrupt results first. You could also try level interrupt instead of "change". You're not using indefinite sleep so it shouldn't be a problem, but try anyway..

                      @m26872
                      Gateway seems to work fine as the 3rd and still working sensor is still communicating. Also the freezed sensors start communicating after I restarted the sensor, not the GW. So I don´t see a problem with the GW.
                      "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?
                      I have not attached a heartbeat LED yet, but that´s sth. I could do as a next step...
                      The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...
                      You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                      Thanks so far!!

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

                      @siod said in My Slim 2AA Battery Node:

                      "Do you have a sniffer or listen-only gateway" -sorry, don´t know what this is o0 !?

                      I meant the https://www.mysensors.org/controller/sniffer, but I think it's easier to equip sensors with Radio Traffic LEDs and/or your own heartbeat/error LEDs.

                      The delay (1000) was initially planned to settle the sensors a bit and gie me abetter Battery reading, but as it is not working as it was intended I will delete it in a future update...

                      I suggest you start with deleting or replacing this delay. It could be it.

                      You could also try level interrupt instead of "change" -again, I don´t know what you are talking about here, hope you can help me out.

                      I think you had pull-up inputs. Then it's just to replace the CHANGE with LOW in your call to sleep().

                      Thanks so far!!

                      My personal troubleshooting method in cases like these (and too many others) is just exhaustive use of the good old substitution method. Hw, Sw, entire systems or whatever you can do. :grimacing:

                      1 Reply Last reply
                      0
                      • siodS Offline
                        siodS Offline
                        siod
                        wrote on last edited by siod
                        #408

                        deleted - it´s working now, I must have made a mistake... :blush:

                        edit:

                        one strange thing: The sensor should report every 15 minutes (900000 milisecs), but it reports only every 18 minutes. Don´t know why.

                        still learning...

                        1 Reply Last reply
                        0
                        • K Offline
                          K Offline
                          Komaandy
                          wrote on last edited by
                          #409

                          Hello everybody,

                          I´m struggeling with getting the https://forum.mysensors.org/topic/2715/slim-node-as-a-mini-2aa-battery-pir-motion-sensor
                          to work.
                          The node registers with the GW, but doesnt submit the tripped reading.
                          Not even a permanent on or something. Just nothing. So i dont know how to troubleshoot here.
                          The PIR HC-SR505 is functional. I tested it with a testscript on a UNO.
                          And the 2AA Slimnode is functional as well. When using the node as a binary switch it works perfectly fine,
                          Just the combination 2AA Slimnode and HC-SR505 doesnt work.

                          Anybody has an idea ?

                          Thanks in advance Komaandy

                          AWIA 1 Reply Last reply
                          0
                          • gohanG Offline
                            gohanG Offline
                            gohan
                            Mod
                            wrote on last edited by
                            #410

                            Did you check the serial output if you get debug messages?

                            1 Reply Last reply
                            0
                            • K Komaandy

                              Hello everybody,

                              I´m struggeling with getting the https://forum.mysensors.org/topic/2715/slim-node-as-a-mini-2aa-battery-pir-motion-sensor
                              to work.
                              The node registers with the GW, but doesnt submit the tripped reading.
                              Not even a permanent on or something. Just nothing. So i dont know how to troubleshoot here.
                              The PIR HC-SR505 is functional. I tested it with a testscript on a UNO.
                              And the 2AA Slimnode is functional as well. When using the node as a binary switch it works perfectly fine,
                              Just the combination 2AA Slimnode and HC-SR505 doesnt work.

                              Anybody has an idea ?

                              Thanks in advance Komaandy

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

                              @Komaandy please don't double post. Please continue in the other thread

                              m26872M 1 Reply Last reply
                              0
                              • K Offline
                                K Offline
                                Komaandy
                                wrote on last edited by
                                #412

                                Does anybody has a idea why my nodes keep freezing ?
                                I build like 5 identical nodes with a PIR and after working fine for a couple of hours at least half of them freeze.
                                There is one particular node that is working for 4 days now straight, but all the others are frozen meanwhile.
                                I have no idea where to start troubleshooting, as they are all the same ( capacitory, resistors,radios,Atmega328p,batteries,solder,radio,sketch)
                                and are all basically within the same radius placed around the gateway. I have other "not battery Slim Nodes" and they never freeze, though running the same sketch.

                                Please i need some tips

                                Regards

                                Komaandy

                                sundberg84S 1 Reply Last reply
                                0
                                • K Komaandy

                                  Does anybody has a idea why my nodes keep freezing ?
                                  I build like 5 identical nodes with a PIR and after working fine for a couple of hours at least half of them freeze.
                                  There is one particular node that is working for 4 days now straight, but all the others are frozen meanwhile.
                                  I have no idea where to start troubleshooting, as they are all the same ( capacitory, resistors,radios,Atmega328p,batteries,solder,radio,sketch)
                                  and are all basically within the same radius placed around the gateway. I have other "not battery Slim Nodes" and they never freeze, though running the same sketch.

                                  Please i need some tips

                                  Regards

                                  Komaandy

                                  sundberg84S Offline
                                  sundberg84S Offline
                                  sundberg84
                                  Hardware Contributor
                                  wrote on last edited by
                                  #413

                                  @Komaandy - did you try the hardware without the PIR?

                                  Controller: Proxmox VM - Home Assistant
                                  MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                  MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                  RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                  1 Reply Last reply
                                  0
                                  • K Offline
                                    K Offline
                                    Komaandy
                                    wrote on last edited by
                                    #414

                                    Do you mean running the node without the PIR ?
                                    I thought about, I guess i will test it.
                                    You think the PIR freezes the node ?

                                    sundberg84S 1 Reply Last reply
                                    0
                                    • K Komaandy

                                      Do you mean running the node without the PIR ?
                                      I thought about, I guess i will test it.
                                      You think the PIR freezes the node ?

                                      sundberg84S Offline
                                      sundberg84S Offline
                                      sundberg84
                                      Hardware Contributor
                                      wrote on last edited by
                                      #415

                                      @Komaandy - Yes and Yes :)
                                      Its a good way to debug, remove not crucial stuff to see if it works... one by one and you will figure it out.
                                      The PIR (depending on which one and what kind of power you are using) might be the problem but hard to say without knowing your setup.

                                      Controller: Proxmox VM - Home Assistant
                                      MySensors GW: Arduino Uno - W5100 Ethernet, Gw Shield Nrf24l01+ 2,4Ghz
                                      MySensors GW: Arduino Uno - Gw Shield RFM69, 433mhz
                                      RFLink GW - Arduino Mega + RFLink Shield, 433mhz

                                      1 Reply Last reply
                                      0
                                      • AWIA AWI

                                        @Komaandy please don't double post. Please continue in the other thread

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

                                        @AWI said in My Slim 2AA Battery Node:

                                        @Komaandy please don't double post. Please continue in the other thread

                                        @Komaandy and @sundberg84 Once again; Please continue in the other thread! Especially since @Komaandy now confirmed that it is this far NOT a generic Slim Node issue. Also, I haven't got any feedback on my reply there, but I assume it didn't work?

                                        1 Reply Last reply
                                        1
                                        • siodS Offline
                                          siodS Offline
                                          siod
                                          wrote on last edited by
                                          #417

                                          Hi @Komaandy ,

                                          unfortunately I must report that I made the same expiriences you made. I am running 5 "My SLim 2AA Battery Node" Sensors from which only 2 really work. The others keep freezing after an hour, a day, are sometimes after a few days. I have still no idea why this is happening, but because of this I stopped building more of the "My SLim 2AA Battery Node" sensors, which is very sad, because it´s an ingeniuous design.

                                          I am using MQTT and therefore I installed NRF24L01 modules. Some of them are really weak, so I thought that´s the problem: The node does not freeze, it´s just the NRF24L01 that is not sending any info anymore. So I attached a LED to my node to see if it is still alive. Whenever I opened a window the LED must lid. So when I did not got any info from the node I checked if the node is still operational by opening a window and there I noticed when the LED did not lid, that the node was completely frozen. So It was not a wireless connection problem, but the NRF24L01 of course could still be the problem.
                                          A lot of my investigastions was about figuring out what is happening when entering the sleep mode, because I thought (and still believe) the node is just not waking up from sleep anymore. Unluckily I still did not find a solution.
                                          Anywhere you said that the none battery driven nodes are working flawlessly, that´s another point I was thinking about. I have one MQTT Arduino Nano device in the basement which is directly powered over USB and I never had problems with it, also the MQTT / NRF24L01 range is awesome.
                                          But I have no oscillator or anything to check if it a power problem with the "My Slim 2AA Battery Node".
                                          Maybe you´ll find a solution for your problems which could help me, too. I´m looking forward hearing from you.

                                          still learning...

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


                                          21

                                          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