Posts

Showing posts from 2024

Python 3 +OpenCV + PyQt6 to display usbcam

Image
A simple exercise run on Windows 11/Python 3.13.0 to capture images from usbcam display with GUI using OpenCV and PyQt6. It's tested in Python virtual environment on Windows 11, with OpenCV aand PyQt6 installed . pyqt6_cv2_usbcam.py , actually it's provided by MicroSoft Copilot. import sys import cv2 from PyQt6.QtWidgets import QApplication, QLabel, QWidget, QVBoxLayout from PyQt6.QtGui import QImage, QPixmap from PyQt6.QtCore import QTimer class WebcamViewer(QWidget): def __init__(self): super().__init__() self.initUI() self.cap = cv2.VideoCapture(0) self.timer = QTimer(self) self.timer.timeout.connect(self.update_frame) self.timer.start(20) def initUI(self): self.setWindowTitle('Webcam') self.image_label = QLabel(self) layout = QVBoxLayout() layout.addWidget(self.image_label) self.setLayout(layout) def update_frame(self): ret, frame = self.cap...

download bmp via WiFi and display using OnDiskBitmap, running on ESP32S3/CircuitPython 9.

Image
Previous exercises post " Seeed Studio XIAO ESP32S3 Sense/CircuitPython display on 1.28" 240x240 GC9A01 Round IPS LCD " and " Display bmp with XIAO ESP32S3 Sense/CircuitPython on GC9A01 Round LCD using OnDiskBitmap, adafruit_imageload and adafruit_slideshow ". It's another exercise running on Seeed Studio XIAO ESP32S3 Sense/CircuitPython 9.2.1, to download bmp from Python http server via WiFi, save to local filesystem, and display on 1.28" 240x240 GC9A01 Round IPS LCD using OnDiskBitmap. Actually, it's ESP32S3 version of another previous exercise " Pico 2 W/CircuitPython download bmp via WiFi, and display using OnDiskBitmap ". Connection between XIAO ESP32S3 Sense and GC9A01 Round IPS LCD, refer to previous exercise " Seeed Studio XIAO ESP32S3 Sense/CircuitPython display on 1.28" 240x240 GC9A01 Round IPS LCD ". To run http server on using Python (tested in Windows 11/Python 3): > python -m ...

Display bmp with XIAO ESP32S3 Sense/CircuitPython on GC9A01 Round LCD using OnDiskBitmap, adafruit_imageload and adafruit_slideshow

Image
Previous exercise on " Seeed Studio XIAO ESP32S3 Sense/CircuitPython display on 1.28" 240x240 GC9A01 Round IPS LCD ", it's another exercise to display bmp using OnDiskBitmap, adafruit_imageload and adafruit_slideshow. Actually, it's ported from my previous exercises on Raspberry Pi Pico with 1.54" 240x240 ST7789 SPI IPS: ~  Raspberry Pi Pico 2/CircuitPython 9 display bmp on ST7789 LCD using adafruit_imageload/adafruit_slideshow ~  displayio.OnDiskBitmap on Pico 2 W/CircuitPython 9 Connection, same as in previous exercise . All testing images were generated using "Image Creator in Bing", not real. Converted to 240x240 RGB888/RGB565 using Python . The exercises need libraries gc9a01, adafruit_imageload and adafruit_slideshow. To install the libraries using circup: circup install gc9a01, adafruit_imageload, adafruit_slideshow To know how to install and use circup, read:  https://coxxect.blogspot.com/2024/12/inst...

Seeed Studio XIAO ESP32S3 Sense/CircuitPython display on 1.28" 240x240 GC9A01 Round IPS LCD

Image
This exercise run on  Seeed Studio XIAO ESP32S3 Sense running CircuitPython 9.2.1, to display on  1.28" 240x240 GC9A01 Round IPS LCD . Also exercises to run Turtle graphics on CircuitPython. Libraries (or modules) gc9a01, adafruit_display_text and adafruit_turtle are needed. In old approach, you can download them from  CircuitPython Libraries and copy to CircuitPython device manually. In this video, the libraries were installed using another approach CircUp. To install CircUp, read my previous post " Install and using CircUp (CircuitPython library updater) to install CircuitPython libraries ". If you use old approach to download manually, notice that gc9a01.mpy is in Community Bundle (circuitpython-community-bundle-...), not Adafruit Circuit Bundle (adafruit-circuitpython-bundle-...). Connection: Exercise Code: cpy_XS3_gc9a01_color.py , simple demo exercise with color test. """ Color test on Seeed Studio XIAO...

Install and using CircUp (CircuitPython library updater) to install CircuitPython libraries

Image
CircUp (CircuitPython library updater) is a tool to manage and update libraries (modules) on a CircuitPython device. In old approach, we will download library bundle from CircuitPython Libraries , extract, and fine the libraries to upload to CircuitPython device manually. If any libraries updated, we have to do it again. With CircUp, it install and update libraries automatically.  This utility looks at all the libraries on the device and checks if they are the most recent (compared to the versions found in the most recent version of the Adafruit CircuitPython Bundle and Circuitpython Community Bundle). If the libraries are out of date, the utility helps you update them. It's suggested to install CircUp in virtualenv (Python virtual environment). This video show steps to create virtualenv in Windows 11, install CircUp in virtualenv, and install libraries on CircuitPython device using CircUp. Circup requires Python 3.5 or higher. To create a virtualenv for circup,...

Pico 2 W/CircuitPython download bmp via WiFi, and display using OnDiskBitmap.

Image
Previous Raspberry Pi Pico 2W/CircuitPython 9 exercise display bmp in local filesystem on 1.54" IPS 240x240 with SPI ST7789 driver using displayio.OnDiskBitmap . This exercise using Pico 2 W wireless feature, download bmp via WiFi to local filesystem, then display on ST7789 LCD using OnDiskBitmap. We are going to setup a python http server on Windows 11, then Pico 2 W connect to the same WiFi network ("ssid" here) and request bmp from the http server. The simplest way to setup http server in Python is: python -m http.server Then you can reach the http server at http://[IP address]:8000/ Exercise code: cpy_pico2w_wifi_OnDiskBitmap.py """ Raspberry Pi Pico 2 W/CircuitPython 9 to display bmp on 1.54" 240x240 ST7789 SPI IPS Download bmp from wifi and display on LCD using OnDiskBitmap Connection: ----------- GND GND VCC 3V3 SCL GP18 SDA GP19 RES GP20 DC GP21 CS GP17 BLK GP22 CircuitPython Libraries Bundle for Version 9.x nee...

Set CircuitPython file system Writable, and write/read text file on CircuitPython.

Image
This code simple try to write a text file in CircuitPython file system and read back, tested on  Raspberry Pi Pico 2 W running CircuitPython 9.2.1. cpy_write_and_read_text_file.py """ CircuitPython exercise to write and read text file. Tested on Raspberry Pi Pico 2 W/CircuitPython 9.2.1 """ print("- To write hello.txt -") try: with open("/hello.txt", "w") as fp: fp.write("hello, world! from coXXect") except OSError as err: print(err) print("- To read hello.txt 0") try: with open("/hello.txt", "r") as fp: print(fp.readline()) except OSError as err: print(err) It will raise OSError of Read-only filesystem. Because by default in CircuitPython, filesystem is read-only for running code. cpy_check_vfs_readonly.py , check if the filesystem is readonly or not. """ CircuitPython code to check if Filesystem is Read Only or Writable....

displayio.OnDiskBitmap on Pico 2 W/CircuitPython 9

Image
Last post Raspberry Pi Pico 2/CircuitPython 9 exercise to display bmp on ST7789 LCD using adafruit_imageload/adafruit_slideshow , here is another method on CircuitPython to display bmp, using  displayio.OnDiskBitmap , tested on my new  Raspberry Pi Pico 2 W running CircuitPython 9.2.1. Connection, same as in last post . To prepare 240x240 bmp, read  Resize jpg and convert to bmp in RGB888 and RGB565 mode, using Python/GIMP Exercise Code: cpy_pico2w_OnDiskBitmap.py , display bmp using OnDiskBitmap() """ Raspberry Pi Pico 2/CircuitPython 9 to display on 1.54" 240x240 ST7789 SPI IPS Display bmp using OnDiskBitmap() Connection: ----------- GND GND VCC 3V3 SCL GP18 SDA GP19 RES GP20 DC GP21 CS GP17 BLK GP22 CircuitPython Libraries Bundle for Version 9.x needed: (https://circuitpython.org/libraries) - adafruit_st7789.mpy ref: displayio.OnDiskBitmap() - https://docs.circuitpython.org/en/latest/shared-bindings/displayio/index....

my dev. board: Raspberry Pi Pico 2 W

Image
my dev. board: Raspberry Pi Pico 2 W Currently (24-11-30), there are no official firmware in micropython.org . You can download the preview version here . scroll down to download MicroPython UF2 for Pico 2 W (mp_firmware_unofficial_latest.uf2). As first test, I try to blink the onboard LED by following https://projects.raspberrypi.org/en/projects/getting-started-with-the-pico , but failed. Later, I found the reason: Refer to Raspberry Pi Pico 2 W Datasheet   and schematic , Pico 2 W (should be same as in Pico W) onboard LED is connected to CYW43439KUBG chip, not RP2350, so have to specially handled like this: led = machine.Pin("LED", machine.Pin.OUT) blink.py , MicroPython code to blink the onboard LED from machine import Pin, Timer led = machine.Pin("LED", machine.Pin.OUT) print("led:", led) timer = Timer() def blink(timer): led.toggle() timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink) while True: ...

Raspberry Pi Pico 2/CircuitPython 9 display bmp on ST7789 LCD using adafruit_imageload/adafruit_slideshow

Image
Previous post show how  Raspberry Pi Pico 2/CircuitPython 9 display on 1.54" 240x240 ST7789 SPI IPS . This post show two exercises to display bmp using adafruit_imageload/adafruit_slideshow. adafruit_imageload  decodes an image file into new bitmap and palette objects of the provided type. It’s designed to load code needed during decoding as needed. This is meant to minimize the memory overhead of the decoding code. adafruit_slideshow  CircuitPython helper library for displaying a slideshow of images on a display. Connection: Keep using the same connection in previous exercise . Test images: All the test images shown in the above video were AI generated using "Image Creator in Bing", and resize and convert to 240x240 RGBB888/RGB565 bmp using Python/GIMP . Exercise Code: cpy_pico2_st7789_imageload.py, display bmp using adafruit_imageload """ Raspberry Pi Pico 2/CircuitPython 9 to display on 1.54" 240x240 ST7789 SPI...

Raspberry Pi Pico 2/CircuitPython 9 display on 1.54" 240x240 ST7789 SPI IPS

Image
CircuitPython 9.2.0 run on Raspberry Pi Pico 2  (tested work on Pico 2 W also) to display on 1.54" 240x240 ST7789 SPI IPS . Connection: Code: cpy_pico2_st7789.py , with color test and scrolling text. """ Raspberry Pi Pico 2/CircuitPython 9 to display on 1.54" 240x240 ST7789 SPI IPS Connection: ----------- GND GND VCC 3V3 SCL GP18 SDA GP19 RES GP20 DC GP21 CS GP17 BLK GP22 CircuitPython Libraries Bundle for Version 9.x needed: (https://circuitpython.org/libraries) - adafruit_st7789.mpy - adafruit_display_text folder """ import os, sys import microcontroller import board import busio import displayio import terminalio import adafruit_st7789 from adafruit_display_text import label import time disp_sck = board.GP18 disp_mosi = board.GP19 disp_res = board.GP20 disp_dc = board.GP21 disp_cs = board.GP17 disp_blk = board.GP22 # Release any resources currently in use for the displays displayio.releas...

CircuitPython 9 on Raspberry Pi Pico 2 to get info

Image
Simple CircuitPython code run on  Raspberry Pi Pico 2 /CircuitPython 9 to get info and pin alias. cpy_pico2_info.py import os, sys import microcontroller import board print("====================================") print(sys.implementation[0], os.uname()[3], "\nrun on", os.uname()[4]) print("====================================") print() # List all the Available Names # ref: https://learn.adafruit.com/circuitpython-essentials/circuitpython-pins-and-modules#what-are-all-the-available-names-3082670 board_pins = [] for pin in dir(microcontroller.pin): if isinstance(getattr(microcontroller.pin, pin), microcontroller.Pin): pins = [] for alias in dir(board): if getattr(board, alias) is getattr(microcontroller.pin, pin): pins.append("board.{}".format(alias)) if len(pins) > 0: board_pins.append(" ".join(pins)) for pins in sorted(board_pins): print(pins) o...

my display module: 4.0" 480x320 TFT SPI ST7796 with FT6336U Capacitive Touch

Image
Product Page: ~ LCD wiki - SKU: SKU: MSP4031

Raspberry Pi Pico 2/MicroPython display bmp images on 240x240 ST7789 SPI Display

Image
Previous exercise " Raspberry Pi Pico 2/MicroPython read bmp images and draw on ST7789 display pixel-by-pixel " is a slow approach. Because it draw in pixel-by-pixel, each involve a write sequency. But it help me understand bmp much more. Here is another approach, form a bytearray passing to st7789pt blit_buffer() method, such that the driver write the whole buffer in one sequency to improve the speed much more. For connection and installing st7789py_mpy on Raspberry Pi Pico 2/MicroPython, read: https://coxxect.blogspot.com/2024/10/raspberry-pi-pico-2micropython-display.html To prepare 240x240 RGB565/RGB888 bmp using Python or GIMP, read: https://coxxect.blogspot.com/2024/11/resize-jpg-and-convert-to-bmp-in-rgb888.html Exercise code: mpy_pico2_bmp_buffer.py """ Raspberry Pi Pico/MicroPython exercise to display on 1.54" IPS 240x240 with SPI ST7789 driver Read, decode bmp in /images/ directory, and disply on 240x240 SPI ST77...