WS2812 RGB LEDs (aka Adafruit Neopixel) on ESP32 and ESP8266 using Python


#1

Hi Guys,

with our new last release (r2.0.11), WS2812 RGB LEDs - Neopixels in Adafruit parlance - are supported for all Esp32 and Esp8266 Zerynth devices (here more details).
Now the library has changed the name in worldsemi.ws2812 and adafruit.neopixel (if it is still present in your installation you can delete it) is deprecated.

Here you can find the complete documentation of this new library and here below some lines of code working on an ESP32 DevKitC with a strip of 10 LEDs connected to pin D5:

``import streams
from worldsemi.ws2812 import ledstrips as pixel
streams.serial()

num_leds = 10 # adjust this to match the number of LEDs on your strip
led_pin = D5 # this should match the data pin of the LED strip

leds = pixel.LedStrip(led_pin, num_leds) # create a new WS2812 RGB LED strip composed of <num_leds> LEDs and connected to pin led_pin
pos=0 # position of the LED

while True:
leds.set(pos,0,0,0)
leds.on() # refresh the LEDs colour
sleep(100)

leds.set(pos,0,0,255)
leds.on()       
sleep(100)

leds.set(pos,0,255,0)
leds.on()       
sleep(100)

leds.set(pos,255,0,0)
leds.on()       
sleep(100)

leds.set(pos,0,255,255)
leds.on()       
sleep(100)

leds.set(pos,255,255,0)
leds.on()       
sleep(100)

leds.set(pos,255,0,255)
leds.on()       
sleep(100)    

leds.set(pos,255,255,255)
leds.on()       
sleep(100)

pos = (pos+1) % num_leds
sleep(500)
<div><a href="https://docs.zerynth.com/latest/official/lib.worldsemi.ws2812/examples/examples.html" title="Link: https://docs.zerynth.com/latest/official/lib.worldsemi.ws2812/examples/examples.html">Here</a>, or from Example view of Zerynth&nbsp;Studio, you can find more example of usage.<br>Happy coding!!!</div><br>