Posts

Resize jpg and convert to bmp in RGB888 and RGB565 mode, using Python/GIMP

Image
This video show how to resize jpg and convert to bmp in RGB888 and RGB565 mode, in two approach: - Using Python code - Using GIMP Approach 1 using Python: Tested on Python 3.13.0 with cv2 4.10.0 (OpenCV) installed, run on Python virtual environment/Windows 11. To create Python virtual environment in Windows 11, and install libraries, read  https://coxxect.blogspot.com/2024/10/create-python-virtual-environment-in.html . py_cv_batch_resize_RGB888.py """ Python/cv2 to resize all jpg in 'images' folder, and save to 'resized_images_rgb888' folder in RGB888 mode. This code was generated by Copilot mainly. Run on Windows 11/Python 3.13.0 in virtualenvironment, with OpebCV/cv2 installed. To create Python virtual environment in Windows 11, and libraries include OpenCV/cv2, ref: https://coxxect.blogspot.com/2024/10/create-python-virtual-environment-in.html """ import os import cv2 TARGET_WIDTH = 240 TARGET_HEIGHT = 240 d

Raspberry Pi Pico 2/MicroPython read bmp images and draw on ST7789 display pixel-by-pixel.

Image
Follow the former exercises of  Raspberry Pi Pico 2/MicroPython display on 1.54" 240x240 ST7789 SPI IPS and  Python code to read .bmp info from header (work on Desktop Python and MicroPython) , this exercise read bmp images, and draw on ST7789 display pixel-by-pixel. Exercise code: mpy_pico2_bmp.py """ Raspberry Pi Pico/MicroPython exercise to display on 1.54" IPS 240x240 with SPI ST7789 driver Pixel-by-Pixel Read, decode bmp in /images/ directory, and disply on 240x240 SPI ST7789 display. Target: - 240x240 RGB565 .bmp - 240x240 RGB888 .bmp ref: Using library: russhughes/st7789py_mpy https://github.com/russhughes/st7789py_mpy to install st7789py_mpy on Raspberry Pi Pico 2/MicroPython, https://coxxect.blogspot.com/2024/10/raspberry-pi-pico-2micropython-display.html to know more about bmp structure: https://coxxect.blogspot.com/2024/10/python-code-to-read-bmp-info-from.html to convert jpg to RGB565/RGB888 bmp using GIMP, read the

Python code to read .bmp info from header (work on Desktop Python and MicroPython)

Image
This exercise read header of bmp file to get information about the image, such as image width and height, number of bit per pixel, specially offset, such that we can get the bitmap image later. This help me understanding more about bmp file structure. For the BMP file format, I reference  https://en.wikipedia.org/wiki/BMP_file_format . Exercise Code: The Python code work on desktop Python and MicroPython, tested on: - Python 3.13.0 on Windows 11 - MicroPython v1.24.0 on Raspberry Pi Pico2 with RP2350 py_bmp_info.py """ Python/MicroPython exercise to read bmp file and get the bmp info, to understand the structure of bmp header. Work on both: - desktop Python (tested on Windows 11) .bmp image have to be save in 'images' directory under working directory. - MicroPython (tested on Raspberry Pi Pico2 with RP2350 running MicroPython v1.24.0 on 2024-10-25 ) .bmp files have to be saved in /images/ directory. To prepare the bmp using GIMP

Python/PyQt6 slideshow run on Windows 11

Image
A simple Python/PyQt6 SlideShow to display jpg images in images folder. It's generated by Copilot, except the lines marked in blue. Tested on Windows 11 with PyQt6 installed in Python virtual environment . pyqt6_slideshow.py import sys import glob from PyQt6.QtWidgets import QApplication, QLabel, QMainWindow, QVBoxLayout, QWidget from PyQt6.QtGui import QPixmap from PyQt6.QtCore import QTimer from PyQt6.QtCore import Qt class SlideShowWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("Image Slide Show") self.image_label = QLabel(self) self.image_label.setAlignment(Qt.AlignmentFlag.AlignCenter) layout = QVBoxLayout() layout.addWidget(self.image_label) container = QWidget() container.setLayout(layout) self.setCentralWidget(container) self.image_files = glob.glob(" images/ *.jpg") self.current_index = 0 self.show_image()

Create Python virtual environment in Windows 11, and install PyQt6 failed and succeeded.

Image
This video show steps to create Python virtual environment in Windows 11, also set in Thonny using the Python executable in the virtual environment, then install PyQt6 in the new created virtual environment. To create Python virtual environment in Windows 11 , enter the command in Command prompt, where envTry is the name of the virtual environment to be created. python -m venv envTry To activate the virtual environment, run "activate" under the "Scripts" folder in the new virtual environment. To use the Python in the virtual environment : > Run > Configure Interpreter... > Select Local Python 3 in the interpreter option. > Browser to select the Python executable in the virtual environment. To install PyQt6 using pip, simple enter the command : pip install PyQt6 If fail with error: Microsoft Visual C++ 14.0 or greater is required. Get it with "Microsoft C++ Build Tools". Visit the link ( https:/

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

Image
Exercise of Raspberry Pi Pico 2 running MicroPython v1.24.0-preview.449 (normal and RISCV version) to display on  1.54" 240x240 ST7789 SPI IPS . Connection: Library: Library  russhughes/st7789py_mpy (driver for 320x240, 240x240, 135x240 and 128x128 ST7789 displays written in MicroPython) is used in this exercise, read the video to install it on Pico 2. Exercise code: mpy_pico2_st7789_hello.py """ Raspberry Pi Pico/MicroPython exercise to display on 1.54" IPS 240x240 with SPI ST7789 driver Hello World and color test Using library: russhughes/st7789py_mpy, driver for 320x240, 240x240, 135x240 and 128x128 ST7789 displays written in MicroPython. (https://github.com/russhughes/st7789py_mpy) Connection: ----------- GND GND VCC 3V3 SCL GP18 SDA GP19 RES GP20 DC GP21 CS GP17 BLK GP22 GP16 (dummy, not used) """ import os, sys from machine import Pin, SPI import time import st7789py as st7789 import vg

Python code to get system info, for desktop Python, MicroPython and CircuitPython

Image
It's a simple Python code to get system info, tested on cpython (desktop Python), MicroPython on Raspberry Pi Pico2 and CircuitPython on ESP32-S3. ex_py_info.py """ Exercise to get system info in Python Tested on: - desktop Python on Windows 11 - MicroPython on Raspberry Pi Pico 2 (RISCV) - CircuitPython on ESP32-S3 """ import os, sys print(sys.implementation.name, ":") print(sys.version) print(sys.platform) if sys.implementation.name == 'cpython': # Desktop Python import platform print("=============================================") print("Running on: ", platform.platform()) print("=============================================") elif sys.implementation.name == 'micropython' or sys.implementation.name == 'circuitpython': # MicroPython or CircuitPython print("====================================") print(sys.implementation[0], os.uname()