import neopixel
The neopixel module drives WS2812/SK6812-style addressable LEDs from one GPIO using the ESP32 RMT peripheral. Use it for status lights, indicators, simple animations, progress bars, alerts, and small decorative LED strips.
Quick example
import neopixel
import system
strip = neopixel.Strip(pin=18, count=8)
strip.set_pixel(0, 255, 0, 0)
strip.show()
def pulse():
strip.fill(0, 24, 80)
strip.show()
system.schedule("led_pulse", 1000, 1000, -1, pulse)
rgbw = neopixel.Strip(pin=19, count=16, order="grbw", brightness=0.35)
rgbw.rainbow()
importneopixel
Addressable RGB/RGBW LED strip module.
The neopixel module drives WS2812/SK6812-style addressable LEDs from one GPIO using the ESP32 RMT peripheral. Use it for status lights, indicators, simple animations, progress bars, alerts, and small decorative LED strips.
neopixel.Strip(pin: int, count: int, order: any = None, brightness: int = None, reset_us: int = None) -> str
neopixel.Strip(pin: int, count: int, order: any = None, brightness: int = None, reset_us: int = None) -> strCreate an independent addressable LED strip.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pin |
int |
positional or keyword | Yes | GPIO output pin connected to the strip data input. |
count |
int |
positional or keyword | Yes | Number of LEDs in the strip. |
order |
any |
positional or keyword | No | Optional color byte order. Defaults to "grb". Use "rgb", "grb", "brg", or a four-channel order such as "grbw" for RGBW. |
brightness |
int |
positional or keyword | No | Optional global brightness multiplier from 0.0 through 1.0. Defaults to 1.0. |
reset_us |
int |
positional or keyword | No | Optional reset latch time in microseconds. Defaults to 80. |
str neopixel_strip object. Each strip owns its own native RMT resources, so multiple strips can be used at the same time on different pins.
neopixel.Strip().set_pixel(index: int, r: int, g: int, b: int, w: int = 0) -> bool
neopixel.Strip().set_pixel(index: int, r: int, g: int, b: int, w: int = 0) -> boolSet one pixel in the local strip buffer.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
index |
int |
positional or keyword | Yes | Required value. |
r |
int |
positional or keyword | Yes | Required value. |
g |
int |
positional or keyword | Yes | Required value. |
b |
int |
positional or keyword | Yes | Required value. |
w |
int |
positional or keyword | No | Optional value. Defaults to 0. |
neopixel.Strip().get_pixel(index: int) -> dict
neopixel.Strip().get_pixel(index: int) -> dictReturn index, r, g, b, w, and channel for one buffered pixel.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
index |
int |
positional or keyword | Yes | Required value. |
neopixel.Strip().fill(r: int, g: int, b: int, w: int = 0) -> bool
neopixel.Strip().fill(r: int, g: int, b: int, w: int = 0) -> boolSet every pixel in the local strip buffer to one color.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
r |
int |
positional or keyword | Yes | Required value. |
g |
int |
positional or keyword | Yes | Required value. |
b |
int |
positional or keyword | Yes | Required value. |
w |
int |
positional or keyword | No | Optional value. Defaults to 0. |
neopixel.Strip().clear() -> bool
neopixel.Strip().clear() -> boolTurn all LEDs off and write the cleared buffer to the strip.
neopixel.Strip().show() -> bool
neopixel.Strip().show() -> boolWrite the current pixel buffer to the strip.
neopixel.Strip().set_brightness(value: float) -> bool
neopixel.Strip().set_brightness(value: float) -> boolSet the global brightness multiplier from 0.0 through 1.0.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
float |
positional or keyword | Yes | Required value. |
neopixel.Strip().brightness() -> float
neopixel.Strip().brightness() -> floatReturn the current global brightness multiplier.
neopixel.Strip().count() -> int
neopixel.Strip().count() -> intReturn the number of LEDs in the strip.
neopixel.Strip().info() -> dict
neopixel.Strip().info() -> dictReturn strip configuration and native channel information.
neopixel.Strip().rainbow(offset: int = 0) -> bool
neopixel.Strip().rainbow(offset: int = 0) -> boolFill the strip with a rainbow frame and write it immediately.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
offset |
int |
positional or keyword | No | Optional value. Defaults to 0. |
neopixel.Strip().deinit() -> bool
neopixel.Strip().deinit() -> boolRelease the strip and its native resources.
neopixel.Strip().close() -> bool
neopixel.Strip().close() -> boolAlias for deinit().
neopixel.Strip().Example
neopixel.Strip().Exampleimport neopixel strip = neopixel.Strip(pin=18, count=8, brightness=0.4) strip.fill(0, 0, 255) strip.show()
neopixel.begin(pin: int, count: int, channel: int = None, order: any = None, brightness: int = None, reset_us: int = None) -> bool
neopixel.begin(pin: int, count: int, channel: int = None, order: any = None, brightness: int = None, reset_us: int = None) -> boolInitialize the default addressable LED strip.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pin |
int |
positional or keyword | Yes | GPIO output pin connected to the strip data input. |
count |
int |
positional or keyword | Yes | Number of LEDs in the strip. |
channel |
int |
positional or keyword | No | Optional native strip channel. Defaults to 0. Supported channels are 0 through 3. |
order |
any |
positional or keyword | No | Optional color byte order. Defaults to "grb". Use "rgb", "grb", "brg", or a four-channel order such as "grbw" for RGBW. |
brightness |
int |
positional or keyword | No | Optional global brightness multiplier from 0.0 through 1.0. Defaults to 1.0. |
reset_us |
int |
positional or keyword | No | Optional reset latch time in microseconds. Defaults to 80. |
bool True when the RMT channel and pixel buffers are ready. New code should prefer neopixel.Strip(...) for multiple independent strips.
neopixel.set_pixel(index: any, r: any, g: any, b: any, w: any = None, channel: int = None) -> bool
neopixel.set_pixel(index: any, r: any, g: any, b: any, w: any = None, channel: int = None) -> boolSet one pixel in the local strip buffer.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
index |
any |
positional or keyword | Yes | Zero-based LED index. |
r |
any |
positional or keyword | Yes | Red intensity from 0 through 255. |
g |
any |
positional or keyword | Yes | Green intensity from 0 through 255. |
b |
any |
positional or keyword | Yes | Blue intensity from 0 through 255. |
w |
any |
positional or keyword | No | Optional white intensity for RGBW strips. Defaults to 0. |
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the buffer was updated. Call show() to write it to the strip.
neopixel.get_pixel(index: any, channel: int = None) -> dict
neopixel.get_pixel(index: any, channel: int = None) -> dictRead one pixel from the local strip buffer.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
index |
any |
positional or keyword | Yes | Zero-based LED index. |
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
dict Dict with index, r, g, b, w, and channel fields.
neopixel.fill(r: any, g: any, b: any, w: any = None, channel: int = None) -> bool
neopixel.fill(r: any, g: any, b: any, w: any = None, channel: int = None) -> boolSet every pixel in the local strip buffer to one color.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
r |
any |
positional or keyword | Yes | Red intensity from 0 through 255. |
g |
any |
positional or keyword | Yes | Green intensity from 0 through 255. |
b |
any |
positional or keyword | Yes | Blue intensity from 0 through 255. |
w |
any |
positional or keyword | No | Optional white intensity for RGBW strips. Defaults to 0. |
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the buffer was updated. Call show() to write it to the strip.
neopixel.clear(channel: int = None) -> bool
neopixel.clear(channel: int = None) -> boolTurn all LEDs off and write the cleared buffer to the strip.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the off frame was transmitted.
neopixel.show(channel: int = None) -> bool
neopixel.show(channel: int = None) -> boolWrite the current pixel buffer to the strip.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the frame was transmitted.
neopixel.set_brightness(value: any, channel: int = None) -> bool
neopixel.set_brightness(value: any, channel: int = None) -> boolSet global strip brightness.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
value |
any |
positional or keyword | Yes | Brightness multiplier from 0.0 through 1.0. |
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the brightness value was accepted. Call show() to apply it to visible LEDs.
neopixel.brightness(channel: int = None) -> float
neopixel.brightness(channel: int = None) -> floatRead global strip brightness.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
float Float brightness multiplier.
neopixel.count(channel: int = None) -> int
neopixel.count(channel: int = None) -> intRead the number of LEDs in a strip.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
int Integer LED count.
neopixel.info(channel: int = None) -> dict
neopixel.info(channel: int = None) -> dictReturn strip configuration.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
dict Dict with initialized, channel, pin, count, order, bytes_per_pixel, brightness, and reset_us fields.
neopixel.deinit(channel: int = None) -> bool
neopixel.deinit(channel: int = None) -> boolRelease a strip channel and its RMT resources.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when an initialized strip was released.
neopixel.wheel(pos: any) -> dict
neopixel.wheel(pos: any) -> dictReturn a rainbow color for a 0-255 wheel position.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
pos |
any |
positional or keyword | Yes | Color wheel position. Values wrap at 255. |
dict Dict with r, g, b, and w fields.
neopixel.rainbow(offset: float = None, channel: int = None) -> bool
neopixel.rainbow(offset: float = None, channel: int = None) -> boolFill the strip with a rainbow frame and write it immediately.
| Name | Type | Pass as | Required | Description |
|---|---|---|---|---|
offset |
float |
positional or keyword | No | Optional color wheel offset. Defaults to 0. |
channel |
int |
positional or keyword | No | Optional strip channel. Defaults to 0. |
bool True when the rainbow frame was transmitted.