Home » ESP32 and WS2812b LED Micropython examples

ESP32 and WS2812b LED Micropython examples

by shedboy71

In this example we look at some WS2812B RGB LEDs example in Micropython for an ESP8266. Once again we use uPyCraft and this time I use a WS2812b module as I couldn't get the Wemos sensor example

WS2812B is a intelligent control LED light source that the control circuit and RGB chip are integrated in a package of 5050 components. It internal include intelligent digital port data latch and signal reshaping amplification drive circuit. Also include a precision internal oscillator and a 12V voltage programmable constant current control part, effectively ensuring the pixel point light color height consistent.

The data transfer protocol use single NZR communication mode. After the pixel power-on reset, the DIN port receive data from controller, the first pixel collect initial 24bit data then sent to the internal data latch, the other data which reshaping by the internal signal reshaping amplification circuit sent to the next cascade pixel through the DO port. After transmission for each pixel,the signal to reduce 24bit. pixel adopt auto reshaping transmit technology, making the pixel cascade number is not limited the signal transmission, only depend on the speed of signal transmission.

LED with low driving voltage, environmental protection and energy saving, high brightness, scattering angle is large, good consistency, low power, long life and other advantages. The control chip integrated in LED above becoming more simple circuit, small volume, convenient installation

Requirements

Lets take a look a the shields and boards that are required for this example

 

Image Summary
The Wemos mini – ESP8266 based board, it comes with various headers. This is the beauty of it you can create stackable projects with the board and pin compatible shields
This is the breakout I used – I could not get the Wemos shield to work correctly
This is simply a base, you plug the Wemos Mini into one side and you can plug a shield or shields into the other side

 

Parts List

I connect the MH-ET LIVE ESP32 MINI KIT to the dual base and then connect the WS2812 breakout to this

Name Link
MH-ET LIVE ESP32 MINI KIT MH-ET LIVE ESP32 MINI KIT WiFi+Bluetooth Internet of Things development board based ESP8266 Fully functional D1 MINI Upgraded
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
WS2812 RGB LED Breakout Module New WS2812 RGB LED Breakout Module for Arduino

Connection

WS2812 breakout MH-ET LIVE ESP32 MINI KIT
5v 3v3

 

DI IO16
Gnd Gnd

Code

Example 1

[codesyntax lang=”python”]

from machine import Pin
import neopixel

pixels = neopixel.NeoPixel(Pin(16, Pin.OUT), 1)
pixels[0] = (0xff, 0x00, 0x00)
pixels.write()

[/codesyntax]

Example 2

[codesyntax lang=”python”]

from machine import Pin
import neopixel
import time

pixels = neopixel.NeoPixel(Pin(16, Pin.OUT), 1)

while True:
	pixels[0] = (0xff, 0x00, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0x00, 0xff)
	pixels.write()
	time.sleep(1)

[/codesyntax]

Example 3

[codesyntax lang=”python”]

from machine import Pin
import neopixel
import time

pixels = neopixel.NeoPixel(Pin(16, Pin.OUT), 1)

while True:
	pixels[0] = (0xff, 0x00, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0x00, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0xff, 0x00)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0x00, 0xff, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0x00, 0xff)
	pixels.write()
	time.sleep(1)
	pixels[0] = (0xff, 0xff, 0xff)
	pixels.write()
	time.sleep(1)

[/codesyntax]

Links

 

You may also like

Leave a Comment

Adblock Detected

Please support us by disabling your AdBlocker extension from your browsers for our website.