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.

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

WS2812B Without SPI

Posted by Avatar for Gustav @Gustav

Actions