ESP32-S3-DevKitC-1/CircuitPython to drive NeoPixel, onboard and offboard.
This exercise show how
ESP32-S3-DevKitC-1
(running CircuitPython 7.3.2) to drive NeoPixel, onboard RGB and offboard 16 x
WS2812 5050 RGB LED Square with Integrated Drivers.
Please note
that ESP32-S3-DevKitC-1 have two version, ver 1.0 and ver 1.1, The main
difference lies in that the RGB LED is connected to different pins.
On
ver 1.0, my board, it's driven by GPIO48.
On ver 1.1, driven by
GPIO38.
Adafruit CircuitPython NeoPixel library
is needed. To install library, read last post "Download and install CircuitPython Library to CIRCUITPY drive's lib
folder".
cpyS3_NEOPIXEL.py, drive onboard RGB.
import time
import neopixel
import board
def cycleNeopixel(wait):
for r in range(255):
pixel[0] = (r, 0, 0)
time.sleep(wait)
for r in range(255, 0, -1):
pixel[0] = (r, 0, 0)
time.sleep(wait)
for g in range(255):
pixel[0] = (0, g, 0)
time.sleep(wait)
for g in range(255, 0, -1):
pixel[0] = (0, g, 0)
time.sleep(wait)
for b in range(255):
pixel[0] = (0, 0, b)
time.sleep(wait)
for b in range(255, 0, -1):
pixel[0] = (0, 0, b)
time.sleep(wait)
print("==============================")
print("ESP32-S3-DevKitC-1/CircuitPython NeoPixel exercise")
print("to control onboard RGB NeoPixel")
print("neopixel version: " + neopixel.__version__)
print("board.NEOPIXEL: ", board.NEOPIXEL)
print()
# Create the NeoPixel object
pixel = neopixel.NeoPixel(board.NEOPIXEL,
1,
pixel_order=neopixel.GRB)
pixel[0] = (0, 0, 0)
time.sleep(2.0)
cycleNeopixel(0.005)
pixel[0] = (0, 0, 0)
time.sleep(2.0)
print("- bye -\n")
cpyS3_extNEOPIXEL_walking.py, walking on external 16X NeoPixel.
import time
import neopixel
import board
num_of_pix = 16
def offAllPix():
pixel[0] = (0, 0, 0)
for i in range(num_of_pix):
extPixel[i] = (0, 0, 0)
extNeoPixel = board.IO47
print("==============================")
print("ESP32-S3-DevKitC-1/CircuitPython NeoPixel exercise")
print("to control external NeoPixel on GPIO47")
print("neopixel version: " + neopixel.__version__)
print("board.NEOPIXEL: ", board.NEOPIXEL)
print("extNeoPixel: ", extNeoPixel)
print()
# Create NeoPixel objects
pixel = neopixel.NeoPixel(board.NEOPIXEL,
1,
pixel_order=neopixel.GRB)
extPixel = neopixel.NeoPixel(extNeoPixel,
num_of_pix,
pixel_order=neopixel.GRB)
offAllPix()
time.sleep(2.0)
def shiftMask():
for i in range(num_of_pix-1, 0, -1):
enableMask[i] = enableMask[i-1]
enableMask[0] = 0
def setPix(col):
pixel[0] = col
for i in range(num_of_pix):
if enableMask[i] == 1:
extPixel[i] = col
else:
extPixel[i] = (0, 0, 0)
enableMask = [0]*num_of_pix
for color in ((50, 0, 0), (0, 50, 0), (0, 0, 50)):
print("color: ", color)
enableMask[0] = 1
for c in range(num_of_pix):
setPix(color)
shiftMask()
time.sleep(0.5)
offAllPix()
time.sleep(2.0)
print("- bye -\n")
cpyS3_extNEOPIXEL_random.py, display random pixel on external 16X NeoPixel.
import time
import neopixel
import board
import random
num_of_pix = 16
pixBuffer = [(0, 0, 0)]*num_of_pix
def offAllPix():
pixel[0] = (0, 0, 0)
for i in range(num_of_pix):
extPixel[i] = (0, 0, 0)
extNeoPixel = board.IO47
print("==============================")
print("ESP32-S3-DevKitC-1/CircuitPython NeoPixel exercise")
print("display random color on external NeoPixel")
print("neopixel version: " + neopixel.__version__)
print("board.NEOPIXEL: ", board.NEOPIXEL)
print("extNeoPixel: ", extNeoPixel)
print()
# Create NeoPixel objects
pixel = neopixel.NeoPixel(board.NEOPIXEL,
1,
pixel_order=neopixel.GRB)
extPixel = neopixel.NeoPixel(extNeoPixel,
num_of_pix,
pixel_order=neopixel.GRB)
offAllPix()
time.sleep(2.0)
def displayPix():
for i in range(num_of_pix):
extPixel[i] = pixBuffer[i]
enableMask = [0]*num_of_pix
while True:
pixBuffer[random.randint(0, num_of_pix-1)] =(
random.randint(0, 30),
random.randint(0, 30),
random.randint(0, 30))
displayPix()
time.sleep(0.01)
offAllPix()
time.sleep(2.0)
print("- bye -\n")
Comments
Post a Comment