• Well, this thread was originally going to be a question - but I seem to have figured out how to make it work, but since I can't delete the thread, I might as well post what worked.

    I got my Kickstarter Espruinos today - my first microcontrolers , and decided trying to use them with the RGB-123 LED arrays that I also got on kickstarter. I used the 8x1 model, so I didn't have to hook up an external powersupply (see my question below) , and could run the whole thing off USB. Wired it up as was done in the example, using B15/SPI2.

    Copying the example from the video did not work - the first call to the flip() function turned all the LEDs on white at full brightness. All subsequent calls did the same. The baud rate given appears to be the problem - doubling it fixed it.

    I had success with this block of code:

    Note that all colors are BRG, not RGB!

    SPI2.setup({baud:3200000, mosi:B15});  
    var leds= Graphics.createArrayBuffer(8,1,24);
    leds.flip = function () { SPI2.send4bit(leds.buffer, 0b0001, 0b0011); } ;
    //at this point, you can do things like
    //leds.setColor(B,R,G) to set foreground color and the draw* methods to draw shapes. 
    //Curiously, Graphics.setPixel(x,y) won't set that pixel to foreground color. 
    //Likewise, there aren't functions to draw shapes in a specified color - only the one set by setColor()
    //Set colors with a single function call:
    leds.lightPixel = function (x,y,col) {this.setPixel(x,y,col); this.flip();};

    At this point, I have a question about working with the Espruino, since I've never worked with microcontrolers before - can I safely have it connected to an external powersupply while it's connected to USB?

  • Hi - thanks for posting! Where did you find the baud rate of 1600000? I've tried to update everything but I might have missed one of the tutorials?

    I know about BGR/RGB - I'll have to update the graphics driver so it has it as an option. It seems to be one of the other random differences between WS2811 and WS2812.

    The graphics library is loosely modelled on Java's. I found when writing code (drawing to LCDs) that I spent a lot of time drawing stuff using the same colour - so setColor actually makes a lot of sense. I guess I could try and detect when setPixel was called without an argument and use the foreground colour as you say - it might make a lot of sense.

    Also, if you're planning on just changing pixels (and not using any of the draw functions) you might be better off modifying and sending the raw arraybuffer...

    There's a bit of info on powering the board here: http://www.espruino.com/EspruinoBoard

    But basically: the 'Bat' pins on the header are connected to USB via a diode, so you can power Espruino from them while USB is plugged in. However if you power it with less than 5v then the diode will mean that USB ends up powering the pins anyway.

    Just don't plug a battery into the battery connector while powering from the pin headers, as you'll end up charging the battery from them :)

  • I got the 1600000 from the video, http://www.youtube.com/watch?v=RBHP4xDCR­k4

    that was shown during the kickstarter . I wish I'd found the tutorial when I was doing this (so I could have copy-pasted the code), but I'd have still thought I needed 1600000, since the video was using the same arrays I'm using, while the tutorial that stated 3200000 used the WS2811's not WS2812's.

  • Ahh. Thanks. Yes, it's a bit of a pain to change the videos.

    There was actually a bug in Espruino that meant that it chose slightly the wrong baud rate - now that is fixed I think al modules work with 32.

  • Hi, using the v1.53 Firmware i got a curious issue:
    With just one WS2812 this
    SPI2.send4bit([a,b,c], 0b0001, 0b0011);
    works only, if a!=b!=c, otherwise the WS2812 get's off.
    I had not try it with earlier Firmware, therefore this may be an issue only since v1.53 ?

  • Do you have an example?

    SPI2.send4bit([15,15,15], 0b0001, 0b0011);


    SPI2.send4bit([255,255,255], 0b0001, 0b0011);

    both work fine for me...

  • My WS2812's seem to be working okay too on new firmware.

    Are you using a bare WS2812, as opposed to one included as part of a matrix or on a breakout board? If you're using a bare WS2812, did you remember the 0.1uf bypass capacitor? Without that, the WS2812 will turn itself off if you try to light it with a bright color (the exact point at which this happens depends on the physical parameters of your setup).

  • No firmware issue. Changed the wiring and it works. DrAzzy might got the cause (but brightness was meaningless, therefore i hadn't guessed a hardware concern).
    I was using a bare WS2812 (6pin 5050) without cap. The curious issue occurs having
    WS2812.VCC and WS2812.VDD wired to the voltage Espruino.Bat .
    Now i had changed only WS2812.VCC to Espruino.3.3 and the issue has gone.
    Thank you and sorry guys.

  • No problem! By the way, 3.3v can supply only around 150mA, so if you use a few WS2812s you'll soon run out of current :)

  • +Kalus - have you studied the datasheet (or what passes for one) for the WS2812? http://www.adafruit.com/datasheets/WS281­2.pdf

    Note particularly the app notes at the end, where we see the critical bypass capacitor (and resistor - though you may not need this), cryptically marked "104", ie, 0.1uf. The point here is to ensure that a high enough voltage remains on VCC to keep the control circuitry alive when it turns on the LEDs, and VDD momentarily drops in response to the sudden increase in current (due to the inductance of the wires). So they put a bypass cap between VCC and ground to filter this effect out, and charge it through a resistor for good measure.

    On the WS2812B, they did away with the separate pins for VCC and VDD, and simply put the capacitor between the VCC and Gnd. This makes me think that one could probably get away with omitting the resistor between VDD and VCC on the WS2812 as well.

    Maybe in your case the LEDs, running at a lower voltage than intended (I think - there's no spec in the datasheet for VCC/VDD, other than the absolute maximum), are thus drawing less current - enough that the momentary voltage drop isn't resetting it - and that's why it's working at 3.3 - although it's not going to glow as brightly. Do the blues look okay running at 3.3v? That should be the first color to suffer at low voltage. Also, as +Gordon said, you can only run like 2 WS2812's off of the Espruino's +3.3v supply (they're rated at 60ma each full brightness).

    That bypass cap IS a real pain if you're hand-wiring up naked WS2812's (which I'm doing as well...)

  • +DrAzzy Yes, i have. The VDD pin sources only the current for the light, the VCC pin sources only the control circuit of the WS2812, which draws less current and at the 3.3 of Espruino therefore no Problem, because it's bypassed by capacitor. I go this way after magnifying the sample circuit on page 5 showing a series resistance of 150 ohms making it impossible to draw more then 33ma. I have tested it with 2 pieces on a breadboard and they are burning my eyes (at 255,255,255). This is just a test-setup, real projects get a seperate bypass-capacitor.

  • OH! I missed the part about powering only VCC off the +3.3 - I thought you had connected both the VCC and VDD to +3.3. That all makes sense then - and the separate powersupply obviates the need for the bypass cap.

    That actually gives the WS2812 a benefit over WS2812B, since you can run a separate VCC line for the WS2812 and skip the individual caps, and just put one big one at the end of the string to keep VCC in general up...

  • can this work with the combineable diy ws2812b matrix? the circuit is designed vertically. here is the manual.

    1 Attachment

  • @user50035 yes, it'll work perfectly. The only thing I'd say is that when you start combining the matrices it'll be more difficult if you combine them in more than one direction. To do that you'd just want to add one connection to Espruino for each row of modules. Either that or if it became a real problem I could modify the firmware.

  • You many find some informations in following website:

  • Not sure if this is related, but working with neopixel leds, which require array arguments to be 'splatted' is odd.
    Just wondering if you have any functional array handling, e.g. lodash?


  • I'm not sure I really understand the question... If you want to use arrays of arrays, you could just write a small bit of code to convert them into one single array before sending.

    You might also be able to use lodash directly - I haven't looked at it (it's possible it's too big though).

  • Lodash is 14000+ LOC.
    Back when I helped fix Function.length it was actually because I wrote a few functional snippets for basic functional concepts. Sad thing is, it was on a disc that crashed... :/
    If you have access to "JavaScript: The Good Parts" by Douglas Crockford then that is a good resource for a collection of small snippets that enable functional concepts such as map, currying etc.

    Good luck @user59024

  • Just to add, you could also use E.toUint8Array() to prepare the array. You can do things like:

    =new Uint8Array([1, 2, 3, 4, 5, 6, 7, 8, 9])
    >E.toUint8Array([{data:[1,2,3], count:4},[7,8,9]])
    =new Uint8Array([1, 2, 3, 1, 2, 3, 1, 2, 3, 1, 2, 3, 7, 8, 9])
  • Thanks Gordon, somehow i lost track of this thread, that's exactly what I need.

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

How to use Espruino with WS2812 arrays? (Like RGB-123)

Posted by Avatar for DrAzzy @DrAzzy