Avatar for AdaMan82

AdaMan82

Member since Aug 2018 • Last active Apr 2020
  • 3 conversations
  • 19 comments

Most recent activity

    • 12 comments
    • 774 views
  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    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!

  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    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?

  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    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();
    
  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    Yeah I considered adding animations to the randomizer function. It's just flair really so not worth the effort right now, but I'm going to make it so I can connect a cable to the prototype so if I want to mess with the code I can.

    There's not really any value to adding a screen as the game keeps track of all the stuff itself, but if we really wanted to go crazy at some point you could load a thing that keeps track of the expansions so you can manually select/deselect them (or random decks) and make it fully customizeable.

    I thought about making it sellable at some point (have to make one first), but I've kinda missed the boat. The game peaked years ago, so its more of a niche thing, mainly for myself, because card storage and selection is REALLY inefficient as a whole and takes up about 25% of playtime I would say.

    • 22 comments
    • 2,570 views
  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    Sorry for the disappearing act, I was otherwise engaged.

    So I'm using 3x AAs which provide 4.5 volts, more than enough to do the job. The way I have it configured now, 10x LEDs light up for 1 minute in their random configuration. When increasing or decreasing the total number of LEDs, one LED illuminates for 500ms.

    The big picture project is to build a modular deck holder for the Dominion game to hold all the cards for all the random expansions, and based on the number of decks, (which is changed by adjusting the "max" number of leds using +/- buttons in the diagram below) randomly select 10 decks and display those lights on for 60 seconds, allowing you to pull the decks out of the box.

    So now I have the electronics but, I actually need to build the holder. With even as little as 3 hours of functional power, that means over 180 randoms +/-. I doubt I will play 180 games in a year, so it meets my needs. Also, I am only outputting at 20 out of 255, so I'm assuming the reduced brightness will also prolong the battery. I'm fairly confident that 3AA should last me one or more years assuming the batteries are not hot garbage. With rechargeable, the brightness may be lower but still good.

    And to answer questions, ref: limitations, obviously has to be portable, and I want the batteries to be easily replaceable.

    I'm fairly confident that the current setup and code work to my requirements.

    Cross posted from my other thread:
    Imagine the black bars being full slots in a holder, and the white bars being empty slots, that could be filled.

    [+] increases the length of the strip flashing the next light in the strip to show where the "max" is at for the random (green dot in this case).

    [-] decreases the length of the strip as per above.

    [rnd] lights up 10x random "full" slots (cyan dots as an example) for 1 minute. If you press the button again, it lights up a new random 10 lights for 1 minute.

  • in Pico / Wifi / Original Espruino
    Avatar for AdaMan82

    Good point on the data sheet. I guess that makes the most sense. The issue applied on both with USB + battery and just battery pack. The working version does not use pinMode(B15,"af_opendrain").

    My programming background is basically VB in HS, some random C/C++/C# and excel macros, so hardly a pro. Just a baseline knowledge to make things happen.

    Either way, after overcoming the issue above, I have actually completely finished (the electronics part anyways) my project, and a aside from a brief flash at startup as it conducts onInit() and blacks everything out, which ultimately confirms that its turning on, it works perfectly.

    Now for the frigging 100 hours of 3d printing the pieces its going into.

  • Avatar for AdaMan82

    Alright I've got it all figured out. For whatever reason, (either by design or by fluke) my strip defaults to on, so on init I need to turn everything off before doing things off the battery pack. The reason is the draw is too high which makes the lights appear to be out or red when on. I anticipated this, but I did not anticipate the lights to be on by default. Here is how I executed the code to turn everything off, so I could then start turning what I want on:

    var rgb = new Uint8ClampedArray(300*3);
    
    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);
    }
    function onInit() {
    doOff();
    }
    
    onInit();
    

    Wiring as per below. Moving the resistor also had an effect on how strong the lights that I wanted to turn on would be when I wanted them on.

    I can now turn the lights on at will. Big success.

    Thanks again for everyone's help.

  • Avatar for AdaMan82

    That's right. It is one whole strip. zig zagging through the assembly.

    Ultimately 3 functions. One to increase the number (ideally illuminating the light its at), one to reduce the number (illuminating the spot its at) and one to generate a random 10 numbers up to and including where its at and leave them on for 3 mins.

    Its pretty straightforward (I think)

Actions