WS2812B issues

Posted on
  • So I wired the WS2812B to the Espruino. up to the WS2812B strip, but I can't get it to do anything other light up completely.

    I used the first line of test code which is:
    require("neopixel").write(B15, [255,0,0]);

    But the code doesn't even to take effect.

    Wiring diagram as per below. Note that the power source is a 4xAA battery pack which is delivering 5.3v. I get that 4xAAs can't power a whole strip, but they should power one LED.

    What am I doing wrong?


    1 Attachment

    • Circuit.jpg
  • ...LGTM... But how is your wiring? If you do require("neopixel").write(B15, [255,0,0]);, what happens? ...should go dark, should it? Did you try another pin but B15?

  • (see below)

  • If I plug it in as above, all LEDs light up (decreasingly bright due to the 4xAA). A7 also produces the same results.

  • Can you try adding a 1k pullup resistor from B15 to BAT_IN, and calling pinMode(B15,"af_opendrain") before the neopixel write?

    There's some explanation on http://www.espruino.com/Reference#l_neop­ixel_write but basically Neopixels expect a data input voltage that's proportional to the voltage they are powered from. By default Espruinos output 3.3v, and if you power the LEDs from a 3.7v LiPo you're sorted.

    However if you power them from 5v then 3.3v isn't enough for them to read the data signal. While STM32s can't directly output 5v signals, you can use the opendrain mode and a pullup to get what you need.

  • I tried using pinMode(B15,"af_opendrain") with the following setup (see attached image). Does that make sense? It doesn't work which just leads me to believe that I've used the resistor wrong.

    The whole thing still lights up. I tried also with 3xAA which outputs 4.5v but no dice.


    1 Attachment

    • res.png
  • Sat 2018.08.11
    Hello @AdaMan82,

    From #6 above

    re: 'I've used the resistor wrong' 'Does that make sense?'

    If your wiring matches your diagram, you have connected as @Gordon indicated in #5

    Are you programming the Pico using power from a USB cable, then removing that cable then connecting the auxiliary battery supply?



    per #2

    I disagree with the output that @allObjects indicates, but agree with the tactic. Try:

    require("neopixel").write(B15, [0,0,0]);
    

    which should be no color or off instead of

    require("neopixel").write(B15, [255,0,0]); // turn first LED Red
    

    which should be Red on

    ref below 'Software' heading: http://www.espruino.com/WS2811

    Then maybe try a different pin as allObjects suggested, both in software and hardware pin and pullup change

    ref image: http://www.espruino.com/Pico
    SPI2 B15
    SPI1 A7
    SPI3 B3

    Note to check with Gordon to see if just changing the pin designation
    for MOSI SPIn is sufficient with new 'neopixel' module as the work I
    did two years ago used old documentation e.g. SPI2.setup({baud:3200000, mosi:B15});



    But, I'm puzzled.

    re #1: 'but they should power one LED'

    re #6: 'The whole thing still lights up'
    re #4: 'all LEDs light up'
    re #1: 'but I can't get it to do anything other light up completely.'

    Are you using just one Neopixel segment physically separated from the rest, rather than the entire strip as the image provided suggests? and, . . . . How many Neopixels are in the strip?

    I'm sure you were aware that with the strip, the data line is daisy-chained between each individual Neopixel and that a data stream need be sent to that strip.

    Have you tried 3 x RGB triplets:

    require("neopixel").write(B15, [255,0,0, 0,255,0, 0,0,255]); // turn first 3 LEDs, Red, Green, and Blue
    

    ref below 'Software' heading: http://www.espruino.com/WS2811



    Other things to try:

    1. Which tutorial are you using? Please include link and heading
      reference so that we may follow your thoughts
    2. Include the entire code block you are sending the Pico as a code section (see 'Formatting Help' in link below reply dialog next to
      cancel or 'code' button next to 'preview' before submitting)
    3. Provide a snap shot of the hardware so others may triple check the wiring



  • @Robin, ddddohhh!..
    copy-pasted w/o changing the 255 to 0...

    Now:

    1st, I wonder if code was saved before disconnect from IDE and before reconnect w/ bat in batIn. I'm not sure if that matters or not... powering conflict. 2nd, the write should be in the onInit() function that fires on power up. write() is a dynamic thing... pulses of different length over a particular time.

    If you want test it connected to the IDE, do NOT connect the Bat+ to Espruino; just connect it to the LED strip; BUT note that the Bat- HAS to be connected to GND of Espruino AND neg- of LED strip at all times.

    ...and btw., a pic of your setup and bit amore about the steps you did / do, would be of great help to support you.

  • Ok, so I've made some interesting progress.

    I have discovered that the whole strip lights up, but when connecting the 5v line from the strip to the 3.3v out on the Pico, and execute the following code:

    require("neopixel").write(B15, [255,0,0, 0,255,0, 0,0,255]);
    

    Those pixels go very dim but turn the required colour. The remainder of the lights stay on in a redish colour (which I assume is due to voltage drop but would otherwise I assume, be white).

    Its almost like its wired in revers but I have checked the hell out of things so I am fairly confident.

    In response to your questions:
    1) Tutorial: http://www.espruino.com/Individually+Add­ressable+LEDs
    2) Literally: just working with the line above

  • I made a huge step. So all the lights go on by default, but I can turn them off manually with require("neopixel").write(B15, [0,0,0]); I can also turn specific ones on in correct colour combos. ALSO, the reddish colour is definitely due to voltage drop.

    I just don't know why it all defaults to but hey that's a start. The resistor and using the 3.3v output was the issue.

  • 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.


    1 Attachment

    • res.png
  • Sat 2018.08.11

    AdaMan82,

    re: 'my strip defaults to on'

    Not sure of this comment in the Neopixel datasheet, but it might explain why, . . . if taken literally.

    SK6812
    https://cdn-shop.adafruit.com/product-fi­les/1138/SK6812+LED+datasheet+.pdf

    2nd to last page: "Note: high starting, in order to send data"

    Maybe by design as data pin is tied high, quick stream of 1111....1111 pulses, or maybe a quick self test to assure that each Neopixel can work, perhaps.

    In any event, although you haven't specified the extent of your programming background, it is always a good practice to initialize data to a known state before using it, as you have demonstrated in your code snippet. Then there shouldn't be any surprises, as you also found out.


    I'm still puzzled at the wiring and don't have many ideas here. Need Electronics Engineering knowledge assistance here.

    Did you remove line @Gordon's suggestion:

    pinMode(B15,"af_opendrain")

    Since the 1K is now in series on the data line, it shouldn't hurt, maybe round the edges or shorten the amplitude of the data pulses a bit, but am puzzled as to why the LED's intensify once on the data line. Sounds like the Pico is trying to source current and there is an upper limit of 25ma

    See: http://www.espruino.com/datasheets/STM32­F401xD.pdf
    p.59
    Each GPIO pin can source or sink only 25ma
    Total max all pins is 120ma


    Is it possible you are powering with both the USB connector and the battery at the same time?

    I remembered there was a comment on this, but unable to locate on the current page

    http://www.espruino.com/Pico

    See comments near schematic.

  • 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.

  • As @Robin points out, wiring the resistor in series and pinMode(B15,"af_opendrain") are contradictory not just in itself, but also from the point of driving an input...

    Anyway, I'm glad you sorted things out.

    Yes, LEDs - even though very efficient in turning electricity into light - they are very power hungry... just for your calculation:

    1 single LED draws 20mA... 1 single RGB LED is three LEDs and on white - [255,255,255] - this is 60mA. Driving a few LEDs - when connected w/ IDE - works, but it is just for testing some logic. To go real, you really need to feed the string what it needs. Feeding them via 4 AA batteries and showing 5.3V tells me that the AA cells are already pretty stressed... For all your strips, look for a PC power supply and use its 5V to do what need ('google' something like 'DIY 5V power supply w/ PC'). Since such supplies deliver beyond what you need (for single strip), adding a fuse can never hurt... and with 60mA / RGB and number of RGBs you can calculate the required fuse rating... and add tens of percent for a regular (fast) fuse or less for a slow fuse.

    NOTE: when developing - being connected to the IDE over USB - have Espruino's BatIn DISCONNECTED from you external 5V supply.

    Looking forward to see code and pics of your project while it's coming along.

  • Glad it's working - although now I think you could safely remove that resistor if you wanted. Your first diagram was definitely correct.

    All I can think is that your 4xAA wasn't outputting the 5.3v you thought... If you had 4 fresh AA then you'd expect 6v - and the Pico probably wouldn't be able to supply a high enough voltage for the data input of the LEDs (it tops out at 5v)... Also the LEDs are only meant for a 5.3v max input, so you could risk some damage to those as well.

    NOTE: when developing - being connected to the IDE over USB - have Espruino's BatIn DISCONNECTED from you external 5V supply.

    It should be fine to have BatIn connected to a battery while on USB with the Pico. It's different with the Espruino WiFi though as there's no BatIn pin.

  • Mon 2018.08.13

    @AdaMan82 to add to what @allObjects points out in above #14, and before your foray into 100+ hours of 3d printing, have you considered the following for the power supply. As you haven't indicated the number of pixels in the strip length, I'm making the following observation based on the following 1 meter strip - Total pixels, 32:

    https://www.adafruit.com/product/3851

    to @Gordon 's point in #15
    in link 2nd pp:

    "You must use a 5V DC power supply to power these strips; do not use
    higher than 6V
    , or you will destroy the entire strip. Yikes!"


    Using four Alkaline batteries might be a bit much (4 x 1.5V =6V), but rechargebles are lesser capacity (4 x 1.2V = 4.8V)

    References:
    https://en.wikipedia.org/wiki/AA_battery­

    https://sciencing.com/energizer-watthour­-battery-specs-7425932.html

    http://www.techlib.com/reference/batteri­es.html

    E = I x R
    volt = current x resistance
    P = I x E
    watt = amp x volt



    So, how many LED's can we safely handle with 4 AA's? How long will those batteries last?

    We'll be conservative, pick an easy math value and use 2000mAh at 3.0W
    We then may calculate the current at 3.0W / 1.5V = 2A This checks with the datasheet then

    We also note that capacity drops as immediate power demands increase.
    http://data.energizer.com/pdfs/e91.pdf
    I'm seeking a maximum discharge continuous rating suggested, . . . not 'infinite' as some will suggest ;-)

    Insert:
    Did find this:

    Max Discharge Rate 2.0A continuous, 3.0A pulse (2sec on / 8 sec off)

    https://www.batteryspace.com/primary-lit­hium-battery-energizer-aa-1-5v-3000mah-u­ltra-capacity-l91vp-non-rechargeable-4-5­wh-2-0a-rate---un-38-3-passed.aspx

    A discharge rate of 500mA would provide 4 hrs at 0.75W, which could power 25 LEDs

    500mA / 20mA(eaLED) = 25 LEDs

    Check: If max cap is 3W then how many 3/4W for how long?

    3W / 0.75W/hr = 4hr

    Could a battery supply 2A continuous?

    2A x 1.5V = 3W

    That would be a drain for 100 LEDs at 3W Getting warm, aren't we!

    2000mA / 20mA(eaLED) = 100 LEDs

    Under ideal conditions at room temperature a single AA cell could power 25 LEDs for four hours.
    Note that at least two cells are needed in series to exceed forward voltage drop

    This means that, when the LEDs are full on, a four AA cell battery pack could supply 100 LEDs for four hours.

    2000mA x 4 x 1.5V = 12W max output

    Check: 4 AA x 3W = 12W
    Easy analysis shows that this is also 40 LEDs for 10 hr



    Then for the Neopixel strip above,
    Demand 32 x 20mA = 640mA

    2000mA / 640mA = 3.125hr

    4 cells x 3.125 = 12.5hr

    Check: This is close to our 40 LEDs for 10 hr calculation

    The Pico usage is negligible at 32mA/hr
    https://www.espruino.com/Power+Consumpti­on



    Make sure your conceptual project guidelines allow for this battery holder design before firing up the 3D printer. :-0
    Otherwise as allObjects suggests a 5V Regulated supply would be the best alternative. . . .





    EDIT:
    Thr 2018.08.16
    Clarification - The Neopixel calculation above is for a single LED color. When displaying pure white however,

    require("neopixel").write(B15, [255,255,255]);
    

    all three LED diodes are on, thus trippling the current demand.
    Demand 32 x (3 x 20mA) = 1920mA

    2000mA / 1920mA = 1.04hr

    4 cells x 1.04 = 4.17hr

  • @AdaMan82, get yourself one of these USB power banks/packs and off you go... if 10Ah is not good enough, go for 20Ah... I have one running my phone when gone dead and I'm off grid... My bank (20Ah) can charge the phone about 3 times... with the speed as the wall power supply that came with the phone... (just know that you cannot run the power through Espruino's USB plug... because you do not want to burn the diode or PCB traces... 'sacrifice' an extra USB cable and feed as your schema displays.

    PS: there are other good places for power banks than amazon...

  • Tue 2018.08.14

    I like the sleek and simple USB Power Bank design solution that @allObjects suggested. On a hunch, I wanted to see how well the EasyAcc-10000mAh
    USB Power Bank faired in comparrison to AA batteries.

    https://www.techadvisor.co.uk/review/pow­er-banks/easyacc-powerbank-review-easily­-one-of-best-value-power-banks-3624761/

    Listed under 'Specs'

    10,000mAh

    2x 12W (5V, 2.4A) USB outputs



    Even though the spec indicates there are two USB port outputs, there is a maximum discharge rate to be aware of.

    4th pp
    "the power bank's max output is only 12W (meaning it can support only one of its two outputs at full-speed at a time)"

    This restriction means that this type of supply can't deliver the current that much better than the four AA cell solution described in #16 above.

    The only difference is that while 4 AA batteries have a capacity of 8000mAh, the EasyAcc-10000mAh has 20% more capacity.

    That would mean you would be able to power 100 LEDs max for one hour longer, that's it.

    Does have the ability to be easily recharged through a micro USB adapter however.

    @AdaMan82 Any chance you could provide us with your LED design requirements?
    Number of LEDs in a strip?
    Number of strips?
    How long the project is always on?
    Limitations for the supply, size, space, portable or wall plug etc?

  • 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.


    1 Attachment

    • project.png
  • Wed 2018.08.15

    From what you have described, your expectations for battery consumption and ease of replacement are on target. I wouldn't change the design.

    Have you tried some of the pattern functions towards the end of the tutorial at:

    https://www.espruino.com/Individually+Ad­dressable+LEDs

    The varying of colors has a somewhat dimming-brightening effect that I felt was really cool for the Neopixel. Worth spending an evening tying the different getPattern() functions.

    Please post some pics when project complete or even as you go along perhaps.

  • Although out of my domain, I do get the gist of game play.

    https://en.wikipedia.org/wiki/Dominion_(­card_game)

    Could the Pixl be used as a visual aid to track coins and points or provide some other feedback to the player?

    You might be on to a salable product . . . .

  • 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.

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

WS2812B issues

Posted by Avatar for AdaMan82 @AdaMan82

Actions