Skip to content

Instantly share code, notes, and snippets.

@tstellanova
Last active January 2, 2023 16:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tstellanova/d7dd23f85c98dec7f9a475d69c4b8fdc to your computer and use it in GitHub Desktop.
Save tstellanova/d7dd23f85c98dec7f9a475d69c4b8fdc to your computer and use it in GitHub Desktop.
Notes on driving onboard RGB LEDs on various ESP32 S2 dev boards with micropython or circuitpython

Setup

Starting with development boards:

Micropython RGB LED driver references:

Examples that work:

WS2812 on Saola (with micropython)

import machine, time, neopixel, random
rgb_pin = machine.Pin(18)
np = neopixel.NeoPixel(rgb_pin, 1)

while True:
    red = random.randint(0, 129)
    green = random.randint(0, 129)
    blue = random.randint(0, 129)
    np[0] = (red, green, blue)
    np.write()
    time.sleep_ms(50)

APA102 on FeatherS2 (with CircuitPython)

You'll first need to download the dotstar library adafruit_dotstar.py file into /lib (assuming CircuitPython is already installed on the FeatherS2).

import board, time, random
# import apa102
import adafruit_dotstar
# IO45 clock and MTDO data
clock_pin = board.APA102_SCK
data_pin = board.APA102_MOSI
loop_count = 0

led_strip = adafruit_dotstar.DotStar(clock_pin, data_pin, 1)

while True:
    red = random.randint(0, 129)
    green = random.randint(0, 129)
    blue = random.randint(0, 129)
    brightness = 16
    led_strip[0] = (red, green, blue, brightness)
    print(loop_count)
    loop_count = loop_count + 1
    time.sleep(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment