Driver for WS2812 RGB LEDs (NeoPixels, ...)

Showroom for MicroPython related hardware projects.
Target audience: Users wanting to show off their project!
Damien
Site Admin
Posts: 496
Joined: Mon Dec 09, 2013 5:02 pm

Re: Driver for WS2812 RGB LEDs (NeoPixels, ...)

Postby Damien » Wed Dec 10, 2014 11:49 pm

fma wrote:Great! But as I understand from your post on the other thread, the call to send() is still blocking during transfert, so CPU is not availabe for other tasks. Am I right?

Right. First step was to get DMA working, and main reason for that was to get uninterrupted transfers with interrupts enabled. Previously send() was disabling interrupts during a transfer, and this can lead to lost interrupts. Now it's much better with DMA, even if you have to wait for it to finish.

Next step will be to have an option to return before transfer is compete. And some function to check completion, as well as a callback.

MattMatic
Posts: 13
Joined: Wed Apr 22, 2015 1:44 pm

Re: Driver for WS2812 RGB LEDs (NeoPixels, ...)

Postby MattMatic » Wed Apr 22, 2015 2:17 pm

Really appreciate the WS2812 library :)

Got me going in under 5 minutes.

However, I ran into a couple of minor issues.

First, the "buf_bytes" are not correct. Since SPI shifts the MSB first, the assignment should be (0x88, 0x8e, 0xe8, 0xee).
Having sorted that out my first NeoPixel worked properly.

And, a little extra tweak was to add the RST period of 50µs+ after sending the pixel information. I just added 3 to the self.buf_length ;)
All seems good!

...I will probably take this library a bit further with 'corrections' for linear/log brightness and other animation functions that I need.

jszsj
Posts: 2
Joined: Tue Jul 07, 2015 9:05 am

Re: Driver for WS2812 RGB LEDs (NeoPixels, ...)

Postby jszsj » Tue Jul 07, 2015 9:08 am

there is a issue with the drive:
I have a 16 leds chain and a 2 leds chain,I used example_advanced.py to test, the first led in both chain does not light, other leds works fine, someone can help me with this?Thanks
(ps: Sorry for my poor Engilsh)

taylorl123
Posts: 1
Joined: Sun Sep 11, 2016 5:09 am

RBGW NeoPixle support

Postby taylorl123 » Sun Sep 11, 2016 5:15 am

I have a strip of 30 rbgw neopixels and it doesn't seem to work properly with this driver. I was just wondering if it was something i did or if the new rbgw LEDs are not supported in this driver.
Thanks!
taylor

ricblue
Posts: 4
Joined: Mon Sep 26, 2016 1:45 am

Re: Driver for WS2812 RGB LEDs (NeoPixels, ...)

Postby ricblue » Tue Sep 27, 2016 7:43 pm

Have you seen the Adafruit MicroPython + NeoPixel video

https://www.youtube.com/watch?v=QcyuYvyvOEI

The author has created an rgbw version of the MicroPython Neopixel drivers. see here:
https://gist.github.com/tdicola/6fe1fbc173dcd49de3a95be5fd9594f6

Electra
Posts: 4
Joined: Thu Sep 29, 2016 9:01 am

Re: Driver for WS2812 RGB LEDs (NeoPixels, ...)

Postby Electra » Tue Oct 25, 2016 12:58 am

Not sure where else to put this, but maybe someone playing with neopixels will find it handy.
Wanted to change colours randomly without the 'next' colour being close to the previous.
A bit limited in some way, but someone might have fun.

rndhue.py

Code: Select all

# Random colour methods for NeoPixel, does use more bytes to store random states
# Based heavly on http://martin.ankerl.com/2009/12/09/how-to-create-random-colors-programmatically/
# Ported to Python by Electra

import neopixel

class NeoPixel(neopixel.NeoPixel):

  def __init__(self,pin, n):
    neopixel.NeoPixel.__init__(self,pin, n)  # Pass on the __init__
    from uos import urandom
    self.hrnd = [0] * self.n
    tmprnd=urandom(self.n)
    for i in range(0,self.n):
      self.hrnd[i] = tmprnd[i]*0.0039

  # HSV values in [0..1]  returns (r, g, b) values from 0 to 255
  def hsv_to_rgb(self,h, s, v):
    h_i = int((h*6))
    f = h*6 - h_i
    p = v * (1 - s)
    q = v * (1 - f*s)
    t = v * (1 - (1 - f) * s)
    if h_i==0: r, g, b = v, t, p
    if h_i==1: r, g, b = q, v, p
    if h_i==2: r, g, b = p, v, t
    if h_i==3: r, g, b = p, q, v
    if h_i==4: r, g, b = t, p, v
    if h_i==5: r, g, b = v, p, q
    return (int(r*256), int(g*256), int(b*256))

  # Move through semi random hue sequence, random saturation
  # Optional parameter selected pixel otherwise all are affected
  def rndhue(self,pix=-1):
    from uos import urandom
    for i in range(0,self.n):
      if pix != -1:
        i = pix 
      # Uncomment next line and indent two after for random skips
#      for t in range(int(urandom(1)[0]/50)+1):   
      self.hrnd[i] += 0.618033988749895  # Golden ratio
      self.hrnd[i] %= 1
      self[i]=self.hsv_to_rgb(self.hrnd[i],(urandom(1)[0]/510)+0.5, 0.50)
      if pix != -1:
        return


import rgbled
import machine
import time
np = rgbled.NeoPixel(machine.Pin(4), 2)
while True: np.rndhue() ; np.write() ; time.sleep(1)


Return to “Hardware Projects”

Who is online

Users browsing this forum: No registered users and 3 guests