Posts

Showing posts from 2025

Control onboard LED of Raspberry Pi Pico 2/2W using MicroPython/CircuitPython

Image
The onboard LED on Raspberry Pi Pico and Pico 2 is connected to GPIO25. On Pico W and Pico 2 W, it's connected to the wireless chip. Following are exercise to control the onboard LED using MicroPython/CircuitPython, tested on Pico 2 and Pico 2 W. mpy_rp2_led.py """ MicroPython on Raspberry Pi Pico 2/2W to control onboard LED """ import os, sys import time #import board #from digitalio import DigitalInOut, Direction sys_info_text = sys.implementation[0] + " " + os.uname()[3] +\ "\nrun on " + os.uname()[4] print("=======================================") print(sys_info_text) print("=======================================") led = machine.Pin("LED", machine.Pin.OUT) print("led:", led) # Control onboard led using led.on() and led.off() while True: led.on() time.sleep(0.5) led.off() time.sleep(0.5) """ # Toggle onboard led using led.togg...

Use ST7796 SPI LCD on CircuitPython/Raspberry Pi Pico 2, by instancing BusDisplay object using custom init_sequence.

Image
Currently, it's no ST7796 driver for CircuitPython. So I create ST7796 display by instancing object of busdisplay.BusDisplay with custom init_sequence(ST7796_INIT_SEQUENCE). Tested on WaveShare "3.5 inch 320×480 Capacitive Touch LCD", embedded with ST7796S driver chip and FT6336U capacitive touch control chip , with Raspberry Pi Pico 2 running CircuitPython 9.2.4. For the init_sequence, I reference the MicroPython demo of Working with Raspberry Pi Pico in WaveShare wiki , with a little bit modification. Exactly  ONE bit: (D6 MX/Column Address Order) on MADCTL (36h), to flip left/right. (refer ST7796S Datasheet ) In following exercises, various various function of the ST7796 display module was tested, include: - Display area, color test. (cpy_pico2_st7796_BusDisplay.py) - Touch function of FT6336U capacitive touch drive.(cpy_pico2_st7796_BusDisplay_FT6336.py). - display bmp image (from CIRCUITPY device/SD) using adafruit_imageload. (cpy_pi...

Face detection using Python/OpenCV on Raspberry Pi, display on ST7789 LCD using Luma.LCD.

Image
Last exercise ILI9488 SPI LCD on Raspberry Pi/Python using Luma.LCD  display images on 3.5 inch 480x320 ILI9488 SPI LCD , run on Raspberry Pi 4B/Raspberry Pi OS 64-bit (bookworm), using Python + PIL + Luma.LCD. This exercise introduce using OpenCV to read images, convert OpenCV ndarray to PIL Image, then display on 2.4 inch TFT Module 240×320 ST7789V using Luma.LCD. Also implement face detection. Connection between ST7789 and Raspberry Pi, follow last exercise, same GPIO pins (for sure, the pin order on display module hanged). Also other setup , create Python virtual environment and install luma.lcd. Read last exercise . To use OpenCV (cv2) in this exercise we have to install opencv-python in Python virtual environment: With Python virtual environment activated, run the command: pip install opencv-python Exercise code: luma_st7789_cv2_image_show.py , read a single jpg image using cv2, convert OpenCV ndarray to PIL...

ILI9488 SPI LCD on Raspberry Pi/Python using Luma.LCD

Image
Luma.LCD  provides a Python3 interface to small LCD displays connected to Raspberry Pi and other Linux-based single-board computers (SBC). It provides a Pillow-compatible drawing canvas, and other functionality. This exercises tested on Raspberry Pi 4/64-bit Raspberry Pi OS (bookworm) using Python3 + Luma.LCD to driver 3.5 inch 480x320 ILI9488 SPI LCD . Connection: Follows the suggested wiring for ILI9488 in Luma.LCD docs . Enable SPI Interface: Make sure SPI is enabled in Raspberry Pi using raspi-config. ( https://luma-lcd.readthedocs.io/en/latest/hardware.html#enabling-the-spi-interface ) sudo raspi-config Create Python virtual environment Install luma.lcd: Create Python virtual environment to include site packages: python -m venv --system-site-packages envPy_luma Activate the virtual environment: source envPy_luma/bin/activate install the latest version of the library in the virtual environment with: pip install --upgrade luma.lcd Ex...

Cartoonized images display on 320×480 ST7796 SPI LCD, using Python on Raspberry Pi 4B

Image
Previous post introduced Cartoonize image using OpenCV in Python, run on Windows 11 . This exercises run on Raspberry Pi 4B/64 bit Raspberry Pi OS (bookworm), and modified to display on Waveshare 3.5" 320×480 ST7796 SPI LCD . Connection and setup demo (include ST7796 driver), read  Test "Waveshare 3.5inch Capacitive Touch LCD" on Raspberry Pi Zero 2 W .  OpenCV (cv2) is needed, to install OpenCV in Python virtual environment: Switch to where you want to Python virtual environment located. Create Python virtual environment to include site packages, where envPy_cv2 is the name of my virtual environment: $ python -m venv --system-site-packages envPy_cv2 Activate the virtual environment: $ source envPy_cv2/bin/activate Install OpenCV: $ pip install opencv-python Exit virtual environment after finished: $ deactivate In Thonny, configure interpreter to select the Python executable in the new virtual environment. Exercise code: pyCartoonize....

Cartoonize image using OpenCV in Python

Image
I found a great example code to cartoonize image using OpenCV in Python, let's give it a try! Reference:  Best Ways to Cartoonize an Image Using OpenCV in Python Modified code in my exercise, pyCartoonize.py. """ Cartoonize image using OpenCV in Python I found a great example code to cartoonize image using OpenCV in Python, let's give it a try! reference: https://blog.finxter.com/5-best-ways-to-cartoonize-an-image-using-opencv-in-python/ In the post, 4 method are listed to Cartoonize an Image Using OpenCV in Python. Method 1: Bilateral Filtering and Edge Detection. Produces a smooth, clean cartoon effect. Good for high-resolution images but can be computationally intensive. Method 2: Color Quantization and Edge Enhancement. Delivers a visually distinct cartoon with flat colors and crisp borders. Works best with strongly contrasting images. The setup is slightly complex due to k-means. Method 3:...

Simple USB Cam viewer in Windows 11, using Python + OpenCV

Image
My scenario is I have two USB Cam deviecs: - A Video Capture Adapter, used to convert HDMI output from Raspberry Pi, convert to USB, my PC will recognize it as a USB web cam. - A normal USB web cam. I use them to record Raspberry Pi operation and unit under developed, as show in the video: https://www.youtube.com/watch?v=JVnYG2-OC8w But in Windows, only one Camera can be opened at the same time. So I make a simple Python code to display the web cam view on screen, no any capture/record control. Such that I can record screen with both my Raspberry Pi operation and the web cam view. In the Python code, OpenCV (cv2) is used to handle the cam, so have to install it. In my practice: - Create a Python virtual environment in Windows 11, named envUSBCAM.      Enter the command in Terminal:    > python -m venv envUSBCAM    Activate the virtual environment:   > .\\Scripts\activate - Install OpenCV in the virtual e...

Python on Raspberry Pi to display images on ST7796S SPI LCD

Image
Python exercises run on Raspberry Pi 4/64-bit Raspberry Pi OS (bookworm) to display images on Waveshare 3.5 inch 320x480 Capacitive Touch LCD, with ST7796S driver . For connection and setup (include downloading of demo and drivers), refer to the post  Test "Waveshare 3.5inch Capacitive Touch LCD" on Raspberry Pi Zero 2 W . Exercise Code: LCD_image_show.py , display single image. Convert and rotate 1024x768 jpg image to 320x480, and display on ST7796 SPI LCD. #!/usr/bin/python # -*- coding: UTF-8 -*- #import chardet """ Python exercise run on Raspberry Pi 4: Read image and display on Waveshare 3.5inch Capacitive Touch LCD with ST7796 SPI driver. Connection and setup, read: https://coxxect.blogspot.com/2025/01/test-waveshare-35inch-capacitive-touch.html remark: All test images were generated by X's Grok, not real. """ import st7796 from PIL import Image, ImageOps if __name__=='__main__': disp = st7796.st77...