Posts

CircuitPython on Pico 2 + Touch LCD, act as a HID mouse.

Image
Refer to the cpy_pico2_st7796_BusDisplay_FT6336.py exercise in last post " Use ST7796 SPI LCD on CircuitPython/Raspberry Pi Pico 2, by instancing BusDisplay object using custom init_sequence ", It simple read touch reported by adafruit_focaltouch and display a cursor on screen, no any actual function. In this exercise I will add a simple handler to detect touch action such as touch-down, touch-up, and touch-move, and finally report to PC as HID mouse function. Connection, refer to last post " Use ST7796 SPI LCD on CircuitPython/Raspberry Pi Pico 2, by instancing BusDisplay object using custom init_sequence ". To install libraries for following exercise using circup: circup install adafruit_display_text adafruit_focaltouch adafruit_hid adafruit_button Exercise Code: cpy_pico2_st7796_BusDisplay_FT6336_handler.py Before we report HID mouse function, we have to detect touch action touch-down, touch-up, and touch-move. In this code, a ...

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....