Posts

Showing posts with the label Raspberry 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...

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

Picamera2+OpenCV+matplotlib Python exercise to display histogram, run on Raspberry Pi

Image
Previous exercise of  Python/OpenCV run on Raspberry Pi to capture images from Camera Module 3 using Picamera2 and display using OpenCV . The exercise plot the histogram using matplotlib. To install OpenCV and matplotlib on Raspberry Pi OS, read the HERE . picam2_cv2_histogram.py """ Picamera2 + OpenCV exercise: Run on Raspberry Pi 5 + Camera Module 3, capture image using capture_array() and display using cv2.imshow(). - plot histogram of the images. Press: S/s to save Q/q to quit My cameras: Picamera2(0) - Camera Module 3 NoIR Wide Picamera2(1) - Camera Module 3 """ import cv2 import picamera2 from libcamera import controls import platform from importlib.metadata import version import time import matplotlib import matplotlib.pyplot as plt print("Python:", platform.python_version()) print(picamera2.__name__ + ":", version(picamera2.__name__)) print(cv2.__name__ + ":", cv2.__version__) print(matplotlib.__nam...

CircuitPython to download bmp images from web, and display on ILI9341 SPI TFT.

Image
Last post show ESP32-S3 running CircuitPython 9.0.3 to display on ILI9341 SPI LCD, detect FT6336 Cap. Touch, and load bmp from SD card using adafruit_imageload . The post show exercise to download bmp images from internet and display on ILI9341 SPI LCD. Basically, the network part follow the CircuitPython  adafruit_imageload example imageload_from_web.py . In the original example, bmp file is downloaded from https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_ImageLoad/main/examples/images/4bit.bmp . In this exercise, my own Python http server was setup on Raspberry Pi 5/64-bit Raspberry Pi OS (bookworm), to store my bmp images. Enter the command in Terminal: python3 -m http.server Or save it in a executable shell script as shown in the video. Exercise code: cpyS3_ili9341_imageload_from_web.py """ CircuitPython exercise run on ESP32-S3, to load image from web and display on ILI9341 SPI LCD. ref: https://github.com/adafruit/...

How much current drawn by Raspberry Pi Camera Module 3?

Image
It's a roughly test on Raspberry Pi 5/64-bit Raspberry Pi OS (bookworm) with Camera Module 3 (NoIR Wide and normal) .

Install CircuitPython firmware on Waveshare ESP32-S3-Zero, run on Raspberry Pi OS (bookworm).

Image
With esptool installed on Raspberry Pi 5 running Raspberry Pi OS (bookworm) , this video show steps to install CircuitPython 9.0.0-beta.0 on Waveshare ESP32-S3-Zero . Visit https://circuitpython.org/downloads , search ESP32-S3-Zero. It's custom build of CircuitPython 9.0.0-beta.0 for Waveshare ESP32-S3-Zero. Download the .BIN file. Erase flash: $ esptool.py --chip esp32s3 --port <PORT> erase_flash Write flash: $ esptool.py --chip esp32s3 --port <PORT> --baud 460800 write_flash -z 0x0 <.BIN> Test Code pinmap.py """CircuitPython Essentials Pin Map Script""" import microcontroller import board import os import sys info = os.uname()[4] + "\n" + \ sys.implementation[0] + " " + os.uname()[3] print("=======================================") print(info) print("=======================================") print() board_pins = [] for pin in dir(microcontroller.pin): if ...

Install esptool inside Virtual Environment, on Raspberry Pi 5 running 64-bit Raspberry Pi OS (bookworm).

Image
In pre-bookworm Raspberry Pi OS, esptool can be install esptool directly, system-wide, using pip. This is no longer the case in the new Raspberry Pi OS (bookworm). From bookworm onwards, when using pip, packages must be installed into a Python virtual environment. (ref: https://www.raspberrypi.com/documentation/computers/os.html#installing-python-packages-using-apt ) This video show steps in  Esptool.py Documentation  to Install esptool inside Virtual Environment, on Raspberry Pi 5 running 64-bit Raspberry Pi OS (bookworm). - Create a virtual environment and choose its name, e.g. ‘esptoolenv’:   $ python -m venv esptoolenv - Activate the virtual environment:   $ source esptoolenv/bin/activate - Install the esptool.py within the active virtual environment:   $ pip install esptool - When you’re done, deactivate the virtual environment:   $ deactivate next: ~  Install CircuitPython firmware on Waveshare ESP32-S3-Zer...

Python/PyQt5/Picamera2 to control Raspberry Pi Cameras with GUI, added White Balance setting.

Image
Further works on my previous post Python/PyQt5/Picamera2 to control Raspberry Pi Cameras with GUI, with camera_controls , added White Balance setting. Actually, I'm not sure the setting and operation of Awb and ColourGains. refer:  ~ The Picamera2 Library document, Appendix C: Camera controls. Code: picam2_qt5_2024-01-20.py """ Python 3/PyQt5 + picamera2 to control Raspberry Pi Camera Modules Tested on Raspberry Pi 5/64-bit Raspberry Pi OS (bookworm) # in my setup: # Picamera2(0) - HQ Camera # Picamera2(1) - Camera Module 3 picam2_qt5_2023-12-28.py first exercise picam2_qt5_2024-01-03.py Added Auto-Focus feature detection, and switch AF Mode between Continuous & Manual picam2_qt5_2024-01-07.py Display Preview in seperated window, both Main/Preview windows have Capture button. picam2_qt5_2024-01-13.py Add camera_controls to adjust brightness at runtime. Handle sys.argv, such that user can select cam at c...

Python/PyQt5/Picamera2 to control Raspberry Pi Cameras with GUI, with camera_controls.

Image
Follow my previous exercise  Python/PyQt5 GUI to control Raspberry Pi Camera using picamera2 lib , added function to change camera_controls for brightness at runtime. This video also show two instances run to control two cameras at the same time. Because my Camera Module 3 (with Auto-Focus) is assigned to Picamera2(1), so I make 1 as default. If you have one camera only, or you want 0 as default, set: DEFAULT_CAM_NUM = 0 picam2_qt5_2024-01-13.py """ Python 3/PyQt5 + picamera2 to control Raspberry Pi Camera Modules Tested on Raspberry Pi 5/64-bit Raspberry Pi OS (bookworm) # in my setup: # Picamera2(0) - HQ Camera # Picamera2(1) - Camera Module 3 picam2_qt5_2023-12-28.py first exercise picam2_qt5_2024-01-03.py Added Auto-Focus feature detection, and switch AF Mode between Continuous & Manual picam2_qt5_2024-01-07.py Display Preview in seperated window, both Main/Preview windows have Capture button. picam2_qt5_2024-01-13.py Add camera_controls to adjust brig...