Posts

Showing posts from October, 2024

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

Install Python 3.13 on Windows 11 and setup in Thonny Python IDE

Image
To install Python 3.13 on Windows:- Visit https://www.python.org/ , to download Python 3.13.0 for Windows. In my case run the downloaded exe file as administrator , otherwise fail with error of "The installation is forbidden by system policy. Contact your system administration" . Make sure to check "Add python.exe to PATH" in the installation dialog. To setup Thonny Python IDE to use the new Python 3.13.0:- I have to manually add the Python executable in Thonny options. Check the video: A simple Python code to get info of the running Python and platform. import os, sys, platform print(sys.implementation.name, ":") print(sys.version) print(sys.platform) print("=============================================") print("Running on: ", platform.platform()) print("=============================================")

Multi SSD1306 OLED, on Raspberry Pi Pico 2/MicroPython

Image
My exercise on  Raspberry Pi Pico 2 (RP2350) running MicroPython v1.24.0-preview.321, to display on two  128x64 SSD1315 I2C OLED (SSD1306 compatible) , and one  128x64 SSD1306 SPI OLED . The 3rd, 4th and 5th exercises display on three OLEDs as one framebuf. In the 4th and 5th exercises, groupedOLED_class is implemented, make it easier to append OLEDs at runtime. Two I2C SSD1306 OLED share the same I2C bus with different address. Connection: Exercise code: mpyPico2_tri_oled_hello.py , a simple hello world display on 3 OLED separately. """ MicroPython/Raspberry Pi Pico 2 exercise display on three OLED, 0.96" 128x64 SSD1306 OLED - two I2C OLED share one I2C with different I2C address - and one SPI OLED. To install MicroPython ssd1306 driver on Pico 2. read: https://coxxect.blogspot.com/2024/09/i2c-oled-ssd1306ssd1315-screen-with.html Two I2C OLEDs are connected to the same I2C(0) with different I2C address The I2C address of the left ...