Adsense HTML/JavaScript

Monday, January 25, 2021

STM32F411/CircuitPython drive NeoPixel

With CircuitPython installed on STM32F411 dev. board, it cab be programmed to drive NeoPixel using Adafruit CircuitPython Library. This post show how to drive 8X NeoPixel Ring.



Basically the steps to install library is same as in nanoESP32-S2/CircuitPython control on-board NeoPixel, using Adafruit CircuitPython Library Bundle and nanoESP32-S2/CircuitPython exercise: to control external NeoPixel. Visit CircuitPython Libraries to download the matched Bundle Version. Unzip the file, open the resulting folder and find the lib folder. Copy the library neopixel.mpy file you need to the lib folder on your CIRCUITPY drive.



CircuitPython code to test the 8X NeoPixel Ring, F411_testNeopixel.py
import time
import os
import microcontroller
import neopixel
import board
import random

NumOfPixel_ring = 8

def offAllPixel():
    fillAllPixel(0, 0, 0)
    
def fillAllPixel(r, g, b):
    pixel_ring.fill((r, g, b))


print("==============================")
print(os.uname())
print("STM32F411/CircuitPython NeoPixel example")
print("Test on:")
print("8X NeoPixel Ring")
print("cpu.temperature: " + str(microcontroller.cpu.temperature))
print()
print("neopixel version: " + neopixel.__version__)
print()

# Create the NeoPixel object
pixel_ring = neopixel.NeoPixel(board.A7, NumOfPixel_ring, 
                    brightness=0.1,
                    pixel_order=neopixel.GRB)

offAllPixel()

while True:
    
    for i in range(NumOfPixel_ring):
        pixel_ring.fill((0, 0, 0))
        pixel_ring[i] = (255, 255, 255)
        time.sleep(0.5)
    pixel_ring.fill((0, 0, 0))

    fillAllPixel(255, 0, 0)
    time.sleep(1.0)
    fillAllPixel(0, 255, 0)
    time.sleep(1.0)
    fillAllPixel(0, 0, 255)
    time.sleep(1.0)

    offAllPixel()
    time.sleep(2.0)

#print("- bye -\n")`
My 8X NeoPixel Ring is work on 5V, connect 5V of STM32F411 board to 5V of NeoPixel.
Connect GND of STM32F411 to GND of NeoPixel.
Connect A7 of STM32F411 to DIN of NeoPixel, to match with board.A7 assigned in thte code.

No comments:

Post a Comment