Home Code RGB LED examples in Micropython with an ESP8266

RGB LED examples in Micropython with an ESP8266

by shedboy71

In this example we look at some WS2812B RGB LEDs example in Micropython for an ESP8266.

The 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
WS2812 shield – intelligent control RGB (16777216 colors) LED light source shield.
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 Wemos Mini to the dual base and then put the RGB LED shield along side this, you can connect the Wemos RGB LED shield directly to the Wemos Mini if you want.

Name Link
Wemos Mini D1 mini – Mini NodeMcu 4M bytes Lua WIFI Internet of Things development board based ESP8266 by WeMos
Wemos Base Tripler Base V1.0.0 Shield for WeMos D1 Mini
Wemos RGB LED shield For WeMos D1 MINI WS2812B RGB Full Color Shield Board

Code

Example 1

[codesyntax lang=”python”]

from machine import Pin
import neopixel

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

[/codesyntax]

Example 2

[codesyntax lang=”python”]

from machine import Pin
import neopixel
import time

pixels = neopixel.NeoPixel(Pin(4, 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(4, 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]

 

You may also like

Leave a Comment