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.

Friday, January 22, 2021

Flash CircuitPython to STM32F411, and install Thonny IDE on Ubuntu 20.10

This post show the steps to flash CircuitPython 6.1.0 to STM32F411 dev. board, and install Thonny IDE on Ubuntu 20.10. Tested on VirtualBox 6.1/Windows 10.

The target board is a STM32F411CEU6 minimum development board, it should be compatible with STM32F411CE Black Pill, I guess.

Visit CircuitPython Download page to download CircuitPython match your board. It's "STM32F411CE Black Pill" in my case.

Install dfu-util:
dfu-util is a program that implements the host (computer) side of the USB DFU (Universal Serial Bus Device Firmware Upgrade) protocol. DFU is intended to download and upload firmware to/from devices connected over USB. It ranges from small devices like micro-controller boards to mobile phones. Using dfu-util you can download firmware to your DFU-enabled device or upload firmware from it.

$ sudo apt install dfu-util

You can list the currently attached DFU capable USB devices with -l option:

$ sudo dfu-util -l

Flash downloaded CircuitPython bin to STM32F411:

$ sudo dfu-util -d 0483:df11 -a 0 -s 0x08000000:leave -D <circuitpython bin file>

After flashed, in my try, have to un-plug and re-plug the USB of the STM32F411 Dev.board, to make it recognized. A new driver "CIRCUITPY" appear.

Install Thonny IDE:

$ sudo apt-get install python3-pip
$ sudo pip3 install thonny
$ sudo apt install python3-tk

And add yourself to the 'dialout' group:

$ sudo usermod -a -G dialout <user>

After installed, you can run thonny by enter "thonny" in Terminal.

cpyHelloSTM32F411.py, the testing circuitpython code run in the video.
import os
import microcontroller
import board
import digitalio
import time

print(os.uname())
print()
print("microcontroller.cpu.frequency:\t\t" + str(microcontroller.cpu.frequency))
print("microcontroller.cpu.temperature:\t" + str(microcontroller.cpu.temperature))
print("microcontroller.cpu.voltage:\t\t" + str(microcontroller.cpu.voltage))

print("\ndir(board):")
print(dir(board))

led = digitalio.DigitalInOut(board.LED)
led.direction = digitalio.Direction.OUTPUT

while True:
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(0.3)
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(0.3)
    led.value = True   #LED Off
    time.sleep(0.3)
    led.value = False  #LED On
    time.sleep(1.5)


Extra remark about using USB Device Filters for VirtualBox:

You can create filters for specified USB devices. Matched USB devices will be automatically passed to the guest once they are attached to the host. Such that you need not manually pass to guest everytime the USB device attached.





Example of STM32F411/CircuitPython: 

More Exercise of STM32F411/CircuitPython 7:

Thursday, January 21, 2021

CircuitPython 6.1.0 released

 CircuitPython 6.1.0 released, check the Release Notes for 6.1.0 HERE.

Screenshot of Thonny with STM32F411 dev. board running CircuitPython 6.1.0, on Ubuntu 20.10/VirtualBox.


Related:


Fix the error "This system is currently not set up to build kernel modules" when Install Guest Additions CD images on VirtualBox/Ubuntu

Just install fresh-new Ubuntu 20.10 on VirtualBox 6.1, it's reported with error:

This system is currently not set up to build kernel modules.
Please install the gcc make perl packages from your distribution.

To fix it, open Terminal and enter the command:

$ sudo apt install virtualbox-guest-utils virtualbox-guest-dkms
Then Reject and Install Guest Additions CD images again.