WS2812B Without SPI

Posted on
  • Is there anyway i can use a very short strip of WS2812B (9 leds) with the MDBT42Q module i see it doesn't have SPI, but can i send a signal any other way ?

  • Sat 2019.07.06

    ' i see it doesn't have SPI'

    Hi @Gustav, a little puzzled by your comment,

    as 7/8 down the page, "Note: The nRF52 port has one available I2C, SPI and USART (and infinite software SPI and I2C). Unlike other Espruino boards, these peripherals can be used on any pin."

    http://www.espruino.com/MDBT42Q

    On the MDBT42Q breakout board, I use the code from:

    http://www.espruino.com/WS2811



    Note that you will need a separate supply for the WS2812B strip as the onboard regulator won't be able to drive that many, 9 x ~60ma or roughly half an amp at full on white.

    Although it doesn't appear to be stated on that page, I believe the regulator is the same as the one used on the Pixl:

    the 5v pin will be connected to regulated 3.3v power (note: max power draw is 150mA)
    http://www.espruino.com/Pixl.js#-vin-pin­s

    Also note that pinMode has given some bewildering pondering.

    http://forum.espruino.com/conversations/­324269/

  • You may build an array of pulses... you should have enough memory to do that: 9 x 24 x 2 pulses... For the timing see http://forum.espruino.com/comments/14612­306/ using https://www.espruino.com/Reference#l__gl­obal_digitalPulse . Composing the array may be a bit nifty... but it is all just a matter of 'thinking - bit-banging - it thru'. You make yourself a function that can put the pulses for a byte out and you append for each byte to an array... with arry.push(). Times in digitalPulse() are [ms], and you have to do [us]... like 0.003, 0.006 and 0.009.... I do not know if digitalPulse() can get them out fast enough... you may need to look at the signal with a scope and adjust - shorten - the times to take into account the time of the code that has to run on every transition. - It is though easier to make a custom build that includes neopixel module.

  • The build for MDBT42Q does include Neopixel

    You can follow the sample from API reference

  • Oooops, took @Gustav 's

    i see it doesn't have SPI

    at face value...

    @MaBe, absolutely, since MDBT42Q build includes neopixel... then there is to go with...

  • Thanks for the responses, I don't seem to get it working, I know the ws2812b is rated for 5v but it should work with 3.3 as signal and 5v for vcc. I wired it to pin D30 and tested

    require('neopixel').write(D30, [255,0,0])
    

    .

  • Sun 2019.07.07

    For level shifting the reason why and solutions, See discussions at:

    PinMode af_opendrain

    http://forum.espruino.com/comments/14589­186/

    Use of diode or pullup for level shifting

    http://forum.espruino.com/comments/14506­218/

    I prefer the use of a $0.01 transistor while using these high current demand Neopixels. Get it wrong, and the transistor fuse should go first, hopefully protecting the $35 Espruino microcontroller.

    http://forum.espruino.com/comments/14506­524/

    I highlighted the references above, but read the entire blog post.



    Also check out the datasheet to see and understand why:

    REFERENCE table of RGB Led datasheets Neopixel

    Second table on page 3
    Look for 'Input Voltage Level' V ih - the minimum for a logic HI for input into the Neopixel.
    I'm afraid 3.3V ain't gonna cut it . . . .

  • Yes, some work with 3.3v but make sure you have enough current, to drive them 😉

    Set D30 as output and than try again.

  • First of all, MDBT42Q module and breakout board ** ARE NOT 5V COMPATIBLE*** - see all the pink 3.3 boxes next to each pin at https://www.espruino.com/MDBT42Q#pinout - nor are Pixle and Puck.

    It though may still work when MDBT42Q output is high enough to be detected as high by WS2812B input. Put WS2812B on power and measure voltage over GND and input (IN). If it floats or shows 0V and for sure equal or less than 3.3V (3.6V is absolute max), you are ok to direct connect MDBT42Q output to WS2812B input... ***Make sure you do connect not just INput but also GND,... with separate power supplies this is often missed, and then there is no definitive current flowing in/out of IN (and GND) between MDBT42Q and WS2812B.

    If above does not help, you may need to add some switching transistors... see conversation about Logically invert a pin?, where Espruino is driving WSB2812B 'string' to lighten a Nixie Tube Clock. There are multiple options as you will notice.

  • I know the ws2812b is rated for 5v but it should work with 3.3 as signal and 5v for vcc.

    This hasn't been the case in my experience. There's some info about this in the neopixel docs: http://www.espruino.com/Reference#l_neop­ixel_write

    As a starter I'd try running your neopixels off a LiPo battery (so 3.8v-ish). That lowers their input voltage requirements and tends to make them work great off 3.3v IO. If you then decide you need 5v you can look at level shifting and at least you'll know the hardware is working.

    As @allObjects says, you can't do the simple input_pulldown and resistor hack on nRF52 though as it's not 5v tolerant :(

  • I'm not sure about mentioning

    simple resistor hack

    because as @Gordon points out it is not 3.3V safe.

    I did talk about a simple Tran sistor hack as discussed in linked conversation.

    While writing this I though see an option to get away with just resistors... and to play safe adding a zener. The trick is to shift / offset the low up to just below low detection by the neopixel input so that the high is up as well.

    In my recent neopixel project I used Pico directly connected and had no issuewhat so ever. Pico is 3.3V driven (but its pins are 5V tolerant). The difference of 3.3V vs 3V on MDBT42Q makes obviously a big difference.

    The additional issue is that max input is (usualy) defined as supply voltage plus (usually) 0.3V... see 5.1 Absolute Maximum Ratings at http://www.espruino.com/datasheets/MDBT4­2Q-E.pdf . Based on that a level shifter either as dedicated chip or RYO with transistors is the only real safe way.

  • Alright, great stuff. Will go with a dedicated logic level shift circuit.

  • My favorite logic level shifter is the BSS138. With two resistors it works bi-directional, if you use only one resistor it's unidirectional. It doesn't invert the signal.
    "bi-directional-logic-level-converter-ho­okup-guide" will find relevant documentation.

  • Hey so i got it to work thanks to the logic level shifter. But 2 other problem arose. I can't write to 2 different pins, which drives 2 different neopixel strips. Both are 9 leds long. Also cant seem to get the first LED lit up on either of the strips.

    So once i write to 2 the API freezes and i need to reset the board before i can write to any again.

    Im using pin D16 and D18

  • I'd say it's an electrical problem, most likely you didn't connect ground, data or 5V properly (not getting pin 1 to work).
    Do you have enough power, each LED takes 60mA with R, G and B at 100%, a total of 1.1A for 18 LEDs.

  • Wed 2019.08.07

    Hi @Gustav, I'm surprised at the frustration you must be going through as this shouldn't be that difficult. I have successfully driven three rows, two of those strings containing 60 Neopixels each. Rest assured, the MDBT42Q can handle what you are attempting.

    'Im using pin D16 and D18'

    Any of the GPIO pins will work. D16 and D18 are fine.

    'Also cant seem to get the first LED lit up on either of the strips'

    What is the result of using the code line in your #6 post? Replace the referenced pin with either of the above, and please explain what is seen.

    'So once i write to 2 the API freezes'

    Might be electrical noise on the data line, could be in the way code is sent to the pin. Bad data, Null data. Endless loop. Poorly constructed setInterval(). Could be if arrays are accessed that element zero is missed. Post some code here please.

    Things to check:
    Are the Neopixels and the MDBT42Q sharing a common ground?
    What is the pin mode on each pin? getPinMode()
    What is powering the MDBT42Q breakout board?
    What is powering the Neopixels?
    Do you 'actually' have Neopixels and not LED's as constantly referenced?
    Logic Shifter could be an issue. Please post an image of it, datasheet and the wiring.

    Has the datasheet been reviewed. There are many variants of Neopixel. If they were purchased from an offshore discount site, be aware that many claim to be selling WS2812B and in reality have one of these variants: Post an image of the Neopixel please.

    REFERENCE table of RGB Led datasheets

    Here is an example even using software SPI

    WS2812b Neopixel and nRF52 chips

    The onboard regulator is rated between 80-150ma. Attempting to power more than two individual Neopixels as @maze1980, points out, will most likely fry the regulator and possibly rendering the MDBT42Q a smoke detector tester.

  • ...weird that you do not get the 1st LED lit... I recall something similar... I did set the pin mode and may be something else... see [](http://forum.espruino.com/conversations/­329232/) Post #2, code lines #23, #383 ff and #125. I know that you use different board / pin, but code should work the same way. Btw, you can always send more than 9 x 3 bytes / LEDs, the last 9 will lite your 9-LEDs string.

    Btw, what is the reason to do 2 string rather than just 1 with 18 x 3 bytes? --- Check out my game setup / change / update of buffer and pushing buffer out... It is all mapping... In a different setup I use the Graphics object which allows me nice addressing - see post #26 in same thread. Yours will be 9 cols and 2 rows...

  • Just to add, on a recent version of Espruino on MDBT42 I did:

    require("neopixel").write(D16, new Uint8Array(15))
    require("neopixel").write(D18, new Uint8Array(15))
    

    And it works fine - so as others have said this could well be an electrical issue. Those LED strings can draw a bunch of power when on.

  • Thanks for your replies ! I did some investigation based on your answers and then it hit me.. I was driving the 3.3v side of the logic level shifter from Pin D25 with pinMode as 'input_pullup'.. bad idea. Moved it to normal 3.3 v pin. Now everything works smooth, first led works, dual strips.
    Do you know why that was not working ?

  • Fri 2019.08.08

    Glad it's now working, easy isn't it!!

    'Moved it to normal 3.3 v pin'

    What was the mode of that ('normal') pin?   'auto' maybe?

    getPinMode()

    Any GPIO pin will work. So no real need to move away from D25


    'driving the 3.3v side of the logic level shifter'

    Would you please post a link to the level shifter pinout and schematic, so that we may answer that accurately for you.



    Now that everything is working, what are the plans for the visual output. Running tracer, sparkles, random, train sequencer, meteor, color changer? I may have some code snippets I can dig up.

  • I would love some code snippets ;)

    They dont seem to provide the schematic directly but i bought this one

    What i mean with the normal 3.3v pin is the pin that always just supplies 3.3v, i dont know how to target that pin through code. I will upload some videos of the application.

  • Tue 2019.08.13

    Too cool!!

    Congratulations on a successful project solution!

    The ingenuity of the human mind to apply ideas never ceases to amaze.

    I think this application on a 'hover' board ;-) is a first. Might want to add your solution to the Projects forum.


    re: the code snippets, my implementation probably wouldn't help here, as I imagined (incorrectly) your project to include sequencing a single Neopixel and a possible sparkle effect. If I had an idea of what might likely to be desired, I could pluck a few. . . .


    'They don't seem to provide the schematic directly'

    Thanks for the purchase site link. Was able to grab the BSS138 datasheet using Google:

    BSS138   Bi-directional level shifter for I²C-bus

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

WS2812B Without SPI

Posted by Avatar for Gustav @Gustav

Actions