Monday, May 05, 2025

Raspberry Pi Zero 2W + 0.91 inch OLED (SSD1306)

Playing with this cheap OLED display:
Size: 0.91 inch
Resolution: 128 x 32 pixels
Interface: I2C
Operating voltage: 3.3 V~5V
 
Update the system once:

$ sudo apt update
$ sudo apt upgrade -y

$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 12 (bookworm)
Release: 12
Codename: bookworm

$ uname -a
Linux pizero2w 6.12.25+rpt-rpi-v8 #1 SMP PREEMPT Debian 1:6.12.25-1+rpt1 (2025-04-30) aarch64 GNU/Linux

Setup I2C for Raspi

$ sudo raspi-config → then enable I2C communication from "Interface Options" menu
$ sudo reboot

Install I2C utilities

$ sudo apt install i2c-tools

Connect the display to raspi

Display GND →  Raspi GND pin no.5
Display VCC →  Raspi 3V pin no.1
Display SDA  →  Raspi pin no.2
Display SCK  →  Raspi pin no.3

Check if Raspi can detect the display 

$ i2cdetect -y 1 → this command should show "0x3C" address


Install the following packages for python environment:

$ sudo apt install python3-pip
$ sudo apt install python3-venv

Create python virtual environment

$ mkdir $HOME/ws_py
$ cd $HOME/ws_py && python -m venv .venv

Activate python virtual environment (current working directory is $HOME/ws_py)

$ . .venv/bin/activate
(.venv) ~/ws_py $

After python virtual environment is activated, install python packages using pip

$ pip install Pillow
$ pip install RPi.GPIO
$ pip install adafruit-circuitpython-ssd1306
$ pip install adafruit-blinka

Check if the display is working properly using example code from Adafruit

$ cd $HOME/ws_py
$ git clone https://github.com/adafruit/Adafruit_CircuitPython_SSD1306.git
$ cd examples
$ python ssd1306_stats.py

The display should show the IP address, CPU, memory and disk info of the raspberry pi after this step




Monday, April 15, 2024

Selenium on nethunter (pixel)

Make sure firefox is installed

$ firefox -V
Mozilla Firefox 115.5.0esr

Download geckodriver

$ wget https://github.com/mozilla/geckodriver/releases/download/v0.34.0/geckodriver-v0.34.0-linux-aarch64.tar.gz
$ tar xzvf geckodriver-v0.34.0-linux-aarch64.tar.gz

After this step "geckodriver" should be there

$ ./geckodriver -V
geckodriver 0.34.0 (c44f0d09630a 2024-01-02 15:36 +0000)
The source code of this program is available from testing/geckodriver in https://hg.mozilla.org/mozilla-central.
This program is subject to the terms of the Mozilla Public License 2.0. You can obtain a copy of the license
at https://mozilla.org/MPL/2.0/

Install 'selenium'

$ pip3 install selenium

Test code

import os
import sys
import logging
from selenium import webdriver
from selenium.webdriver.firefox.service import Service


THIS_DIR = os.path.dirname(os.path.abspath(__file__))
DRIVER = os.path.join(THIS_DIR, "geckodriver-v0.34.0-linux-aarch64", "geckodriver")

if not os.path.exists(DRIVER):
    print("Cannot find 'geckodriver'")
    sys.exit(1)


def main():
    print("Downloading web page...")

    s = Service(executable_path=DRIVER)

    options = webdriver.FirefoxOptions()
    options.add_argument("--headless")

    driver = webdriver.Firefox(service=s, options=options)
    
    driver.get("https://www.google.com")
    driver.save_screenshot("screenshot.png")

    print("Please check screenshot image")
    driver.quit()


if __name__ == '__main__':
    main()

After run this code "screenshot.png" should be generated

To show "screenshot.png" image in RLogin

$ sudo apt install libsixel-bin
$ img2sixel screenshot.png

Done.

Sunday, March 03, 2024

How to fix error: No module named 'apt_pkg' on Ubuntu 18.04

 Ubuntu 18.04 has python3.6.x installed but after install python3.8 and used "update-alternatives" to change the default python3 to python3.8, got the following error when running unknown command on the terminal

$ dummyyycommand  
    from CommandNotFound import CommandNotFound
  File "/usr/lib/python3/dist-packages/CommandNotFound/CommandNotFound.py", line 19, in
    from CommandNotFound.db.db import SqliteDatabase
  File "/usr/lib/python3/dist-packages/CommandNotFound/db/db.py", line 5, in
    import apt_pkg
ModuleNotFoundError: No module named 'apt_pkg'

This is caused because python3.8 cannot load "apt_pkg.cpython-36m-x86_64-linux-gnu.so"

$ cd /usr/lib/python3/dist-packages; ls -al | grep apt
drwxr-xr-x   4 root root   4096 Mar  3 22:23 apt
drwxr-xr-x   4 root root   4096 Jun  1  2021 aptdaemon
-rw-r--r--   1 root root  51576 Dec  1  2022 apt_inst.cpython-36m-x86_64-linux-gnu.so
-rw-r--r--   1 root root    227 Dec  1  2022 apt_inst.pyi
-rw-r--r--   1 root root 346784 Dec  1  2022 apt_pkg.cpython-36m-x86_64-linux-gnu.so
-rw-r--r--   1 root root   8900 Dec  1  2022 apt_pkg.pyi
drwxr-xr-x   3 root root   4096 Mar  3 22:23 aptsources
-rw-r--r--   1 root root    226 Dec  1  2022 python_apt-1.6.6.egg-info

To fix this issue:


To fix this issue just create a link named 'apt_pkg.so' points to "/usr/lib/python3/dist-packages/apt_pkg.cpython-36m-x86_64-linux-gnu.so"

$ cd /usr/lib/python3/dist-packages
$ sudo ln -s apt_pkg.cpython-36m-x86_64-linux-gnu.so  apt_pkg.so

Monday, January 29, 2024

Tmux startup script tempalte

 Tmux script template

#!/bin/bash

SESSION_NAME=dev

# new-session -c start-directory -n window-name -s session-name -t group-name -x width -y height [shell-command]
tmux has-session -t ${SESSION_NAME} 2>&1 >/dev/null

#if [ $? -ne 0 ];then
#	source /opt/.../export.sh
#	tmux new-session -s $SESSION_NAME -n main -d
#	tmux new-window  -c $SRC_DIR -n editor
#	tmux new-window  -c $BUILD_DIR -n build
#	tmux attach -t $SESSION_NAME
#	tmux select-windows -t $SESSION_NAME:0
#else
#	echo "Session is already started"
#fi
#

if [ $? -ne 0 ]; then
    # create new session
    tmux new-session -s ${SESSION_NAME} -n main -d
    tmux split-window -h
    tmux split-window -v
    tmux attach -t ${SESSION_NAME}
else
    echo "Tmux session is already created. Use 'tmux attach -t SESSION_NAME'"
fi

Friday, January 26, 2024

 Just a note.

Original post: CPU performance over time from T420 to T480