Posts

Showing posts from December, 2023

Raspberry Pi Pico W (Arduino Framework) display on 0.85 inch 128x128 LCD with GC9107 SPI driver, using GFX Library for Arduino (Arduino_GFX).

Image
Below video show steps to to display on Waveshare 0.85 inch 128x128 LCD with GC9107 SPI driver  with  Raspberry Pi Pico W . It should work on Raspberry Pi Pico and  WeAct RP2040 Dev. Board . GFX Library for Arduino (Arduino_GFX) is needed, make sure it's installed in Library Manager. To use Arduino_GFX on Raspberry Pi Pico (or RP2040), we have to use board of Raspberry Pi Pico/RP2040 by Earle F. Philhower III) . Read the post former post to Install Earle Philhower Raspberry Pi Pico Arduino core on Arduino IDE . It will not work on board Raspberry Pi Pico from Arduino Mbed OS RP2040 Boards by Arduino . In the video, it's tested with Arduino_GFX examples. Examples > GFX Library for Arduino > HelloWorld Examples > GFX Library for Arduino > Clock Examples > GFX Library for Arduino > WiFiAnalyzer > PicoWiFiAnalyzer And finally tested using PDQgraphicstest to compare Arduino_HWSPI() a...

Python/PyQt5 GUI to control Raspberry Pi Camera using picamera2 lib

Image
Previous post show a simple example of  Using the Raspberry Pi Camera in Python3/PyQt5 applications using picamera2 lib , here is another exercise with more. The video show the Python/PyQt5 run on Raspberry Pi 5 with dual camera, Camera Module 3 & HQ Camera with 6mm 3MP lens . The Raspberry Pi 5 is running 64-bit Raspberry Pi OS (bookworm). Note that if picam2 = Picamera(0) to use HQ Camera, the code will report RuntimeError: Control AfMode is not advertised by libcamera . Because HQ Camera have no Auto-Focus function. picam2_qt5_2023-12-28.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 """ import sys, platform, os from PyQt5.QtWidgets import QMainWindow, QApplication, QPushButton, QLabel, QWidget, QTabWidget, QVBoxLayout, QGridLayout from PyQt5.QtGui import QIcon fr...

my display module - 0.85inch LCD Module (128x128 GC9107 SPI) by Waveshare

Image
0.85inch LCD Module (128x128 GC9107 SPI) by Waveshare Product page: ~  0.85inch LCD Module - Waveshare Wiki Exercise: ~  Raspberry Pi Pico W (Arduino Framework) display on 0.85 inch 128x128 LCD with GC9107 SPI driver . ~  ESP32-S3-Zero display on 0.85 inch 128x128 LCD with GC9107 SPI driver, using Arduino_GFX .

PyQt5 QTabWidget exercise

Image
py_qt5_tab.py , a simple exercise of using PyQt5 QTabWidget. """ PyQt5 exercise of QTabWidget """ import sys, platform, os from PyQt5.QtWidgets import (QMainWindow, QApplication, QPushButton, QLabel, QWidget, QTabWidget, QVBoxLayout, QGridLayout) from PyQt5.QtCore import pyqtSlot, Qt from PyQt5.QtGui import QPalette, QColor, QFont class App(QMainWindow): def __init__(self): super().__init__() self.title = __file__ self.left = 0 self.top = 0 self.setWindowTitle(self.title) self.main_widget = MyMainWidget(self) self.setCentralWidget(self.main_widget) self.show() class MyMainWidget(QWidget): def read_f(self, file): with open(file, encoding='UTF-8') as reader: content = reader.read() return content def read_pretty_name(self): with open("/etc/os-release") as f: os_release =...

Get OS pretty name using Python, Raspberry Pi OS

Image
Python 3 exercise run on Raspberry Pi 5 running 64-bit Raspberry Pi OS (bookworm) to read OS pretty name (such as Debian GNU/Linux 12 (bookworm) ) by reading and parsing the file "/etc/os-release". pretty_name.py with open("/etc/os-release") as f: os_release = {} for line in f: k,v = line.rstrip().split("=") os_release[k] = v.strip('"') for keys, values in os_release.items(): print(keys, ":", values) print() pretty_name = os_release['PRETTY_NAME'] print("PRETTY_NAME:", pretty_name) Output: PRETTY_NAME : Debian GNU/Linux 12 (bookworm) NAME : Debian GNU/Linux VERSION_ID : 12 VERSION : 12 (bookworm) VERSION_CODENAME : bookworm ID : debian HOME_URL : https://www.debian.org/ SUPPORT_URL : https://www.debian.org/support BUG_REPORT_URL : https://bugs.debian.org/ PRETTY_NAME: Debian GNU/Linux 12 (bookworm)

Using the Raspberry Pi Camera in Python3/PyQt5 applications using picamera2 lib

Image
Exercise to use the Raspberry Pi Camera in Python3/PyQt5 applications using picamera2 lib, with modification to make the preview match with captured images and enable Auto-Focus in Continuous. Tested on Raspberry Pi 5 running 64-bit Raspberry Pi OS (bookworm) with Camera Module 3. Please notice that currently only the Camera Module 3 provide Auto-Focus feature. Firstly, Copy from the example in The Raspberry Pi official manual The Picamera2 Library (2023-11-27) Charpter 8.5 Using the camera in Qt applications, named Qt_Picamera2_App.py. Qt_Picamera2_App.py listed here for reference. """ Copy from the example in The Raspberry Pi official manual The Picamera2 Library (2023-11-27) Charpter 8.5 Using the camera in Qt applications """ from PyQt5 import QtWidgets from PyQt5.QtWidgets import QPushButton, QVBoxLayout, QApplication, QWidget from picamera2.previews.qt import QGlPicamera2 from picamera2 import Picamera2 picam2 = Pic...

Python code to get MAC address using uuid.getnode()

Image
getMAC.py, Python code to get MAC address using uuid.getnode() . import re, uuid node = uuid.getnode() print("uuid.getnode():\t", node) print("node(hex):\t", hex(node)) MACaddr = ":".join(re.findall('..', '%012X' % uuid.getnode())) print("MAC addr\t", MACaddr) Run on Raspberry Pi 5/Raspberry Pi OS 64-bit (bookworm).

Turtle Graphics on ESP32-S3-EYE/CircuitPython

Image
In Python, turtle graphics provides a representation of a physical “turtle” (a little robot with a pen) that draws on a sheet of paper on the floor. It’s an effective and well-proven way for learners to encounter programming concepts and interaction with software, as it provides instant, visible feedback. It also provides convenient access to graphical output in general. py_turtle.py is a Python 3 script run on desktop to draw Rotated Squares using Turtle Graphics. (code copied from https://deborahrfowler.com/MathForVSFX/RotatedSquares.html ) # Turtle Exercise run on Desktop/Python 3 import turtle print("Turtle Exercise run on Desktop/Python 3") def drawSquare(t,size,angle): t.left(angle) halfsize = size * .5 t.pu() t.setpos(0,0) t.backward(halfsize) t.left(90) t.backward(halfsize) t.right(90) t.pd() for i in range(0,4): t.fd(size) t.left(90) def drawSquarePattern(t): t.color("bl...

Setup Auto-mount Shared Folder in VirtualBox between Windows 11 Host OS and Linux Guest OS

Image
This video show steps to setup Auto-mount Shared Folder in VirtualBox between Windows 11 Host OS and Linux Guest OS To set up Shared Folder in VirtualBox, make sure Guest Additions is installed . In VirtualBox control panel: Select target guest OS (Linux Mint) and click Settings. Select Shared Folders tab and click on "+" sign to add new shared folder. Select folder to share, Enable Auto-mount, click OK to finish setup. Start the guest OS (linux Mint). Try to access the shared folder in guest OS, but failed due to Permission denied. The shared folder belong to vboxsf group. To grant permission to user to access the shared folder, add user to vboxsf group: sudo usermod -G vboxsf -a <user> Log out and log in. Now you can access from both host Windows 11 and guest Linux.

HiSpark Hi3861 WiFi IoT Development Board

Image
Hi3861 Development Board is one of the typical development boards recommended for  getting started with OpenHarmony device development .

Install PlatformIO on Visual Studio Code to program ESP32-C6 in ESP-IDF.

Image
It's a fresh new Linux Mint with Visual Studio Code installed , no esptool or ESP-IDF installed. This video show steps to install PlatformIO on Visual Studio Code, to program YD-ESP32-C6-N16 . It's quite straightforward, except that: If following error reported while installing: PlatformIO: can not find working Python 3.6+ Interpreter. Click on Abort PlatformIO IDE Installation, and check available solutions: https://github.com/platformio/platformio-core-installer/issues/1774 Solution for Linux, install the following package and restart IDE. sudo apt-get install python3-venv If fail in accessing USB port: A fatal error occurred: Could not open /dev/ttyUSB0, the port doesn't exist. Grant permission to user, enter the command in Terminal, log out and log in: sudo usermod -a -G dialout <user> Code: Edit platformio.ini to add the last three line about monitor_ setting: [env:esp32-c6-devkitc-1] platform = espressif32 board = esp32-c6-devkitc-1 framewo...

Create Hello World in VSCode/ESP-IDF Extension manually, run on ESP32-C6 to send text to Serial.

Image
With ESP-IDF Extension installed on VSCode , this video show how to create Hello World in VSCode/ESP-IDF Extension manually, run on  YD-ESP32-C6-N16 to send text to Serial. Create new ESP-IDF project: > View > Command Palette > ESP-IDF: New Project Setup new project hello-C6, choose ESP-IDF Board: ESP32-C6 chip (via ESP USB Bridge) Edit and rename main.c to main.cpp : #include <iostream> extern "C" void app_main(void) { for (int i=0; i<=20; i++){ std::cout << "Hello World! "; std::cout << i; std::cout << "\n"; } } Build, Flash and Run: > View > Command Palette > ESP-IDF: Build, Flash and start a monitor on your device

Python/Raspberry Pi to read model name

Image
Python code run on Raspberry Pi to get model name, by reading /proc/device-tree/model. exPy_model.py """ Python run on Raspberry Pi to get model name """ def read_f(file): print(file, ":") with open(file, encoding='UTF-8') as reader: content = reader.read() return content print(read_f("/proc/device-tree/model")) Output run on Raspberry Pi 5/8G running Raspberry Pi OS 64-bit (bookworm) . /proc/device-tree/model : Raspberry Pi 5 Model B Rev 1.0

Python run on Raspberry Pi OS to check memory and disk info using psutil.

Image
psutil (python system and process utilities) is a cross-platform library for retrieving information on running processes and system utilization (CPU, memory, disks, network, sensors) in Python. It is useful mainly for system monitoring, profiling, limiting process resources and the management of running processes. It's a simple Python exercise run on Raspberry Pi 5/8G running Raspberry Pi OS 64-bit (bookworm), to check memory and disk info using psutil. psutil_info.py import psutil #https://psutil.readthedocs.io/en/latest/index.html memory = psutil.virtual_memory() memory_available = round(memory.available/(1024*1024)) memory_total = round(memory.total/(1024*1024)) # Calculate disk information disk = psutil.disk_usage('/') disk_used = round(disk.used/(1024*1024*1024)) disk_total = round(disk.total/(1024*1024*1024)) print(psutil.__name__, psutil.__version__) print() print("Memory:\t", str(memory_available), "MB available ...

Python/picamera2 to read camera properties

Image
Python/picamera2 to read camera properties. picam_info.py """ Python/picamera2 exercise: to read camera properties. """ import picamera2 from importlib.metadata import version #New in Python version 3.8. picam2 = picamera2.Picamera2() camera_properties = picam2.camera_properties print("=============================================") print(picamera2.__name__, version(picamera2.__name__)) # get version of picamera2 print("=============================================") for keys, values in camera_properties.items(): print(keys, ":", values) Output run on Raspberry Pi 5/8G & Camera Module 3 Wide NoIR : ============================================= picamera2 0.3.16 ============================================= Model : imx708_wide_noir UnitCellSize : (1400, 1400) Location : 2 Rotation : 180 PixelArraySize : (4608, 2592) PixelArrayActiveAreas : [(16, 24, 4608, 2592)] ColorFilterArrangement : 0 ScalerCropMaximum : ...