Power Loss/Drain problems

Posted on
  • I am using an Espruino to run a project with 3 buttons and an LED light strip. One of the buttons increases an led light position by flashing the next light on the strip. The other decreases an led light position by flashing the next light on the strip in an opposite direction, and the last button randomly illuminates 10 lights between the first light and the current position for a minute or two. Unless a button was recently pressed all lights should be off. The project is powered by 4x AA batteries.

    And everything works great, except for some reason, the battery dies after an hour or two even if the lights are off. I'm guessing I'm failing to implement deep sleep properly. As far as I can guess I am not violating any of the 5 conditions in any way that deep sleep should not execute eventually.

    So why is this happening? I've included my code below. Also deepest apologies for my shitty code. I'm not a coder or anything, I just made it work.

    Goes without saying a simple on/off switch would solve the problem but I have one, and I keep forgetting to turn it off so I'd love a software solution.

    var rgb = new Uint8ClampedArray(300*3);
    var rando = new Uint8ClampedArray(10); //array to store 10 random numbers
    var position = 200;
    var k = 0;
    var pos = 0;
    
    //Add function
    digitalWrite(B7,1);
    pinMode(A8, "input_pulldown");
    setWatch(function() {
    doAdd();
    }, A8, { repeat: true, debounce : 100, edge: "rising" });
    
    //Subtract function
    digitalWrite(B3,1);
    pinMode(B3, "input_pulldown");
    setWatch(function() {
    doSub();
    }, B3, { repeat: true, debounce : 100, edge: "rising" });
    
    //Random function
    digitalWrite(B4,1);
    pinMode(B5, "input_pulldown");
    setWatch(function() {
    doRand();
    }, B5, { repeat: true, debounce : 100, edge: "rising" });
    
    function setPosition() {
         pos = (position*3)+2;
         rgb[pos] = 10;
    }
    
    function doAdd() {
      position++;
      doPosition();
      setDeepSleep(1);
    }
    
    function doSub() {
      if (position > 20) {
        position--;
      }
      doPosition();
      setDeepSleep(1);
    }
    
    function doPosition() {
    setPosition();
    require("neopixel").write(B15, rgb);
    k = setTimeout (doOff,300);
    }
    
    function onInit() {
    doOff();
    }
    
    function setOff() {
      for (var i=0;i<rgb.length;i+=3) {
         rgb[i  ] = 0;
         rgb[i+1] = 0;
         rgb[i+2] = 0;
      }
    }
    
    function doOff() {
      setOff();
      require("neopixel").write(B15, rgb);
      setDeepSleep(1);
    }
    
    function setRand() {
    setOff();
    var colourio = 0;
      for (var i=0;i<rando.length;i++) { //puts data into rando array
        rando[i] = parseInt(Math.random()*(position+1)); //put a random number into one of the array positions
          if (i>0){
            for (var t=0; t<i; t++) { //checks to see if the LED has been selected randomly
              if (rando[i] == rando[t]){
                  i=i-1;
              }
            }
          }
      }
    rando.sort(function(a, b) {
      return a - b;
      });
    console.log(rando);
    console.log(position);
      for (var w=0;w<rando.length;w++) {
         pos = (rando[w]*3);
         rgb[pos] = 10;
      }
    setDeepSleep(1);
    }
    
    function doRand() {
      clearTimeout();
      k = 0;
      setRand();
      require("neopixel").write(B15, rgb);
      k = setTimeout (doOff,120000);
    }
    
    onInit();
    
  • @AdaMan82,

    did you save() the code for running it? - if yes, remove the onInit(); invocation in line 104.

    Then you have a lot of console log statements... these may put data into the serial out buffer... remove them or run them conditioned only when developing / testing and you are connected.

    You have 300 neopixels - assuming the 300 from your var rgb = new Uint8ClampedArray(300*3); declaration. Each of them has a chip on it that controls the RGB leds and conditions the signal on write... Even if the LEDs are off, each of these chips draws about 1mA. So your 300 LEDs strip draws 300 mA even in off state... and that empties your AA quite quickly...

    You may get some bistable relay that need only a pulse to toggle between on and off (or in one or the other direction to turn on and off).

    Furthermore: Your pull downs consume some power as well... not much, since they are weak - 30..50k. Compared though to the 300mA as discussed before, it does not really make a difference. When you then though go for switching all off, you may rethink that and use even weaker (external) pull-ups.

  • Wed 2020.02.26

    'Also deepest apologies for my --expletive-- code'

    Is that a new Javascript language term I haven't heard of? ;-)


    'The project is powered by 4x AA batteries'

    @AdaMan82, taking @allObjects observations into account, what type of batteries are in use and what is their ampacity? How old are they should they be rechargeables? I've had a few NiMH go bad after three years of near daily use - that might be to spec however, would have to check

    I recently purchased some off brand rechargeable NiCd's only to learn they only have a 600mAHr rating, when most are around 1800mAHr and I've seen some other chemical makeups with a bragging value approaching (still needs to be researched) ~3000-5000mAHr !!

    I'm working on an all purpose battery pack currently considering the 18650 rather than AA

    Post some parameters and the math calculations for battery longevity - a bit stymied? Both allObjects, AkosLukacs and I would love to battle that out to arrive at how your project is actually performing.

    For the sleep option, which board is in the project? Post process.env results please.

    A simple FET switch might be all thats needed to turn off the juice to the Neopixel hogs or a relay as indicated in post #2 What about using a pin on the Espruino to control a Buck step-up converter that would supply the 5V? hummmmmm . . . .


    EDIT: Circuit to disconnect Neopixel VCC pin using an FET
    https://www.electronics-tutorials.ws/transistor/tran_7.html

  • the battery dies after an hour or two even if the lights are off.

    Something is really off. 4*AA good quality alkaline battery should have ~3000mAh capacity at low current, decent AA NiMh should have ~2000mAh capacity at even high drain. (Ikea's white made in Japan Ladda are recommended by a lots of people as those are assumed to be rebranded Eneloop Pros, and pretty cheap for that)
    The EspruinoBoard (do you use that?) shouldn't draw a huge amount of power even when idling. So even if that is running at max power, that's not even close to draining your battery

    Assuming @allObjects's 300mA idle drain that should still run for 6-8 hours. Can you check the power drain with a multimeter?
    But 300 neopixels can draw a lot of current (300 * 60mA on all LED's full brightness = 18 Ampers!) Not even the best AA batteries can supply that amount of current. That's the power range of decent 18650 LiIon's designed for power-tool use.

    What kind of battery do you use?
    Do you really have 300 neopixels? If you do, and want to turn on all of them, definitely need a lot beafier battery! You can check battery tests by HKJ to figure out what kind of battery you need for the runtime you want.

  • Even if the LEDs are off, each of these chips draws about 1mA. So your 300 LEDs strip draws 300 mA even in off state... and that empties your AA quite quickly...

    I imagine it may be something to do with that... Also depending on your batteries, the final voltage may be higher than the Neopixels are meant for (it seems WS2812B are 5.3v max). While they may work at that (not recommended) the power draw when idle may be significantly higher.

    Definitely having some way to turn the power to them off when not in use would be the way to go. A simple relay module would probably be ok, since when you're lighting the LEDs the power drawn by the relay will be insignificant :)

  • I did save it, and thanks for that, will remove the onInit();

    And yes i am using neopixels. I was suspecting the LEDs were drawing power despite being off. Is there a way to get the espruino to cut power to them without a relay, or is that the only option?

  • Is there a way to get the espruino to cut power to them without a relay

    Disconnecting the Neopixels' VCC pin from power is the only option I'm afraid - it can't be done in software.

  • According to the first post the battery dies after one hour. Then illuminating 10 LEDs for a minute will work for 60 times (that is again 60 minutes) until the battery dies. Is this enough?
    What do you actually build, with 300 LEDs and portable (I guess, as it is battery powered)?

  • Sorry, been out of town for a bit. I will clarify the situation here and in the OP. The power is fine for I would say somewhere in the 24 hour range. I tested it friday eve, then Sat aft it didn't work anymore. I had been having ongoing issues with power drain for a while, so I figured it must be the LEDs. The main issue is that when I leave things on the power drained even though there was no real appearance of activity.

    As allObjects indicated above this would be consistent with the LEDs draining it at 300mah. Past certain point it doesn't work anymore.

    I don't need to turn more than 10 on at any time, so I don't need more than 4xAAs. Because I'm using garbage batteries, voltage output is about 5v, so its fine for the WS2812Bs. I prefer AAs vs. custom battery pack because I don't want to charge the thing all the time, I want to be able to swap out AAs and drive on. (its for a game).

    It seems like the relay is the answer at this point.

    I'll post process.env to satisfy your curiosity tomorrow night!

  • Sun 2020.03.01

    ' I'm using garbage batteries'

    Rechargeables I hope?



    Was the edit update in post #3 noticed? Although the concept of a relay is easy to understand, the relay coil itself with an audible click will most likely be drawing several milliamps to stay engaged, while the quiet FET solution will be in the microamp range.

  • I second Robin, buy a couple sets of decent rechargeables, would be more more economical (unless by garbage you mean you use already drained batteries) and environment friendly than throwing away all those batteries. And you could always have charged up sets if you buy 2-3 sets.

  • A simple FET switch might be all thats needed to turn off the juice to the Neopixel hogs or a relay as indicated in post #2 What about using a pin on the Espruino to control a Buck step-up converter that would supply the 5V? hummmmmm . . . .

    Neopixel shall be connected with ground first, i.e. a simple FET wouldn't be a good solution. Get a high rail FET, e.g. MIC94060 or something else with an internal charge pump.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

Power Loss/Drain problems

Posted by Avatar for AdaMan82 @AdaMan82

Actions