BPI-R2/R3 and SSD1306 oled screen

no, i guess on github the branch is interpreted as pullrequest because of name pr and filtered out

but you can access it via the link https://github.com/frank-w/bpi-r2-ssd1306-display/tree/pr or by cloning my repo and switching to it by “git checkout pr”

if i use -r flag of i2cdetect, display is shown

root@bpi-r2:~# i2cdetect -y -r 2                                                                                                 
     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f                                                                              
00:          -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
20: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
30: -- -- -- -- -- -- -- -- -- -- -- -- 3c -- -- --                                                                              
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --                                                                              
70: -- -- -- -- -- -- -- --

i moved some code in functions and added a uptime (currently not displayed)

Pull request has been merged. Thanks!

i hope it does not break anything with your icons…

btw. is there any larger display which can be used the same way? i saw some larger displays on ebay, but i’m unsure they will work like this (which is very small)

e.g. this: https://www.ebay.de/itm/2-4-Serial-UART-I2C-SPI-IPS-Super-TFT-320x240-Display-Module-for-Arduino/371812222044

btw. pip should be installed in debian with

apt install --no-install-recommends python3-pip

else many tools/libs get installed you don’t want on a router (gcc,g++,build-essential,cpp,make, *-dev)

Zusammenfassung
Die folgenden zusätzlichen Pakete werden installiert:
  binutils binutils-arm-linux-gnueabihf binutils-common build-essential bzip2
  cpp cpp-8 dh-python dpkg-dev fakeroot g++ g++-8 gcc gcc-8 gir1.2-glib-2.0
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
  libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libdpkg-perl
  libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-8-dev
  libgirepository-1.0-1 libgomp1 libisl19 libmpc3 libmpfr6 libpython3-dev
  libpython3.7 libpython3.7-dev libstdc++-8-dev libubsan1 linux-libc-dev make
  manpages manpages-dev patch python-pip-whl python3-asn1crypto
  python3-cffi-backend python3-crypto python3-cryptography python3-dbus
  python3-dev python3-distutils python3-entrypoints python3-gi python3-keyring
  python3-keyrings.alt python3-lib2to3 python3-pkg-resources
  python3-secretstorage python3-setuptools python3-six python3-wheel
  python3-xdg python3.7-dev
Vorgeschlagene Pakete:
  binutils-doc bzip2-doc cpp-doc gcc-8-locales debian-keyring gcc-8-doc
  libstdc++6-8-dbg gcc-multilib autoconf automake libtool flex bison gdb
  gcc-doc libgcc1-dbg libgomp1-dbg libitm1-dbg libatomic1-dbg libasan5-dbg
  liblsan0-dbg libtsan0-dbg libubsan1-dbg libmpx2-dbg libquadmath0-dbg
  glibc-doc bzr libstdc++-8-doc make-doc ed diffutils-doc python-crypto-doc
  python-cryptography-doc python3-cryptography-vectors python-dbus-doc
  python3-dbus-dbg gnome-keyring libkf5wallet-bin gir1.2-gnomekeyring-1.0
  python-secretstorage-doc python-setuptools-doc
Die folgenden NEUEN Pakete werden installiert:
  binutils binutils-arm-linux-gnueabihf binutils-common build-essential bzip2
  cpp cpp-8 dh-python dpkg-dev fakeroot g++ g++-8 gcc gcc-8 gir1.2-glib-2.0
  libalgorithm-diff-perl libalgorithm-diff-xs-perl libalgorithm-merge-perl
  libasan5 libatomic1 libbinutils libc-dev-bin libc6-dev libcc1-0 libdpkg-perl
  libexpat1-dev libfakeroot libfile-fcntllock-perl libgcc-8-dev
  libgirepository-1.0-1 libgomp1 libisl19 libmpc3 libmpfr6 libpython3-dev
  libpython3.7 libpython3.7-dev libstdc++-8-dev libubsan1 linux-libc-dev make
  manpages manpages-dev patch python-pip-whl python3-asn1crypto
  python3-cffi-backend python3-crypto python3-cryptography python3-dbus
  python3-dev python3-distutils python3-entrypoints python3-gi python3-keyring
  python3-keyrings.alt python3-lib2to3 python3-pip python3-pkg-resources
  python3-secretstorage python3-setuptools python3-six python3-wheel
  python3-xdg python3.7-dev

currently facing issues maybe because of this…python tries to compile some c-files…maybe i need to setup an chroot to compile these and copy back the built files…or drop the compile-packages after install

apt install --no-install-recommends binutils binutils-arm-linux-gnueabihf binutils-common build-essential bzip2 cpp cpp-8 dh-python dpkg-dev fakeroot g++ g++-8 gcc gcc-8 python3-dev python3-setuptools python3-wheel

run pip install and then uninstall build-packages

apt remove --purge binutils binutils-arm-linux-gnueabihf binutils-common build-essential cpp cpp-8 dh-python dpkg-dev fakeroot g++ g++-8 gcc gcc-8 python3-dev libexpat1-dev libpython3-dev libpython3.7 libpython3.7-dev python3-dev python3.7-dev
apt autoremove --purge

Maybe compilation can be avoided by using

pip install --only-binary=:all: <pkgname>

by default the i2c-devices have group root till you install i2c-tools, you can create an i2c-group manually (before adding your user to i2c-group) but i2c-utils should be no security problem

seems like there is no binary package of ADAFRUIT-* available for armhf

but my installation on my test-device has created whl-files which can be installed directly

python3 -m pip install --no-index --find-links=~/whl psutil Adafruit-SSD1306 Adafruit-BBIO

i will add the whl-files to my repo soon

Can’t say if this python script would work with it… I bought my SSD1306 cause it was small and fits on the front of the BPI-R2 metal enclosure from China. With a little modification (which I haven’t done yet), it looks like it might fit in the IR and lights window. I would’ve bought a bigger one, but it wanted a front-facing display and that limited my options on purchasing.

Hmmmm, that would be much nicer to have the script running on barebones instead of a docker container…

started the script now on my router…seems like the interfaceUp does not work for ppp-interfaces…

$ cat /sys/class/net/ppp8/operstate 
unknown
$ ip link sh ppp8
54: ppp8: <POINTOPOINT,MULTICAST,NOARP,UP,LOWER_UP> mtu 1492 qdisc pfifo_fast state UNKNOWN mode DEFAULT group default qlen 3
    link/ppp

i changed the condition to throw exception if state is down (instead of !=“up”)

Have now other wan-ipv4

imho for wifi we need to check hostapd too…as interface can be up without hostapd running so not functional. It will be tricky to match hostapd processes to interfaces…maybe read config files on start to get filename for specific interface and the read processes with config in cmdline

Something like this: hostapd.py (649 Bytes)

added the code (with prepared debug) to my github repo

after switching from iptables to nftables i do this part now like this:

table ip filter {
	chain FORWARD {
		type filter hook forward priority 0; policy drop;
		...
		ip saddr 192.168.0.8 udp dport 5160 counter name "voip1" comment "counting packets for SIP1"
		ip daddr 192.168.0.8 udp dport 5160 counter name "voip1" comment "counting packets for SIP1"
		ip saddr 192.168.0.8 udp sport 5161 counter name "voip2" comment "counting packets for SIP2"
		ip daddr 192.168.0.8 udp dport 5161 counter name "voip2" comment "counting packets for SIP2"
	}
	counter voip1 {
	}
	counter voip2 {
	}
}

and readout with python-script:

import os
import json

logdir="/var/log/"

def getCounter(countername):
    stream = os.popen('nft list counter filter '+countername+' -j')
    output = stream.read()
    #print(output)
    j=json.loads(output)
    #return j["nftables"][0]["counter"]["bytes"]
    return j["nftables"][0]["counter"]["packets"]

v1=getCounter("voip1")
v2=getCounter("voip2")

with open(logdir+"voip1.log", "a") as f:
    f.write(str(v1)+"\n")
with open(logdir+"voip2.log", "a") as f:
    f.write(str(v2)+"\n")

i know there is a nftables module for python, but i wanted to have less depencies

calculation of last 2 values in both files is same as before

FYI, got display working on r3 working too with module luma-oled

https://luma-oled.readthedocs.io/en/latest/python-usage.html

pip3 install luma-oled

if connected the right way (pins 1=vcc,3=sda,5=scl,6=gnd) it should be visible in i2cdetect at address 0x3c

root@bpi-r3:~# apt install i2c-tools
root@bpi-r3:~# i2cdetect -y -r 2

python-module still needs compile-tools which i try to avoid, but have not yet found a way for this (only install and deinstall after installing python-module)

oled_connection2

photo shows the example from the documentation linked above on my r3

(.venv_display) frank@bpi-r3:~$ python3                                                                                              
Python 3.9.2 (default, Feb 28 2021, 17:03:44)                                                                                        
[GCC 10.2.1 20210110] on linux                                                                                                       
Type "help", "copyright", "credits" or "license" for more information.                                                               
>>> from luma.core.interface.serial import i2c                                                                                       
>>> from luma.core.render import canvas                                                                                              
>>> from luma.oled.device import ssd1306                                                                                             
>>> serial = i2c(port=2, address=0x3C)                                                                                               
>>> device = ssd1306(serial)                                                                                                         
>>> with canvas(device) as draw:                                                                                                     
...     draw.rectangle(device.bounding_box, outline="white", fill="black")                                                           
...     draw.text((30, 40), "Hello World", fill="white")
1 Like

have you tried this in 2023?

Not yet tried again because i’m busy with other things…have you tried and it does not work?

so far no dice, still at it to get this working

which point does not work? does the device show up in i2cdetect?

at least my display does show up in i2cdetect, if it does not for you make sure connection is right

for installing packages, i used these commands

apt install python3 python3-pip python3.11-venv
python3 -m venv venv
. venv/bin/activate
pip3 install luma-oled #install into venv

#next commands for creating wheel files (in a arm64 chroot) to avoid install compile-tools on router
pip install wheel #needed for RPi.GPIO
pip wheel --wheel-dir tmp luma-oled

uploaded wheel-files here on my wiki: en:bpi-r3:display [FW-WEB Wiki]

Basicly these packages can be installed with

pip install some-package.whl

There is also pip install --no-deps in combination with pip check to maybe skip install of spidev (which needs compile-tools) and maybe the rpi-gpio package

the following packages are needed: luma-oled,luma-core,pillow,cbor2,smbus2 after these installed and adding my user to i2c group i get no error, but display stays dark…have now installed all packages in my venv, but still nothing on display…need to check with another one

edit: got it solved…

https://luma-oled.readthedocs.io/en/latest/python-usage.html

says:

When a program ends, the display is automatically cleared. This means that a fast program that ends quickly may never display a visible image.

so i added this to my script (after the with block) and it shows the image

import time
time.sleep(10)

tested uninstalling the libs…

pip uninstall pyftdi pyusb spidev RPi.GPIO

and display still works :wink: so we only need luma-oled,luma-core, pyserial,smbus2,pillow,cbor2

updated my repo to now use luma

GitHub - frank-w/bpi-r2-ssd1306-display at luma

stats-luma

what pins did you connect the display to? when i run —i2cdetect -y -r 2— no display detected.

As i wrote above

1=vcc,3=sda,5=scl,6=gnd

Made picture from my 1.0 board as there it is better visible

using the below on openwrt snapshot its not detected

opkg update;opkg install --force-depends --force-reinstall python3 python3-pip python3-venv gcc python3-dev i2c-tools python3-smbus kmod-i2c-gpio kmod-usb-hid-cp2112 kmod-regmap-i2c kmod-i2c-smbus

pip install rpi-gpio --pre

python3 -m venv venv
. venv/bin/activate
pip3 install luma-oled

#next commands for creating wheel files (in a arm64 chroot) to avoid install compile-tools on router
pip install wheel #needed for RPi.GPIO
pip wheel --wheel-dir tmp luma-oled

 wget https://www.fw-web.de/dokuwiki/lib/exe/fetch.php?media=en:bpi-r3:luma-oled.tar.gz

Rpi-gpio is not needed…try pip install --no-deps

Ok,you use openwrt…maybe you need a special module there…but i2c is used for sfp too so it should be active

This looks cool, would like to do this as well. Are there any larger devices that are supported?

Afaik larger displays are mostly spi and not i2c…i have an old rpi display,but had not got it working…for basic system info this display is enough for me.

Maybe someone else try this too and get a step further

1 Like

I wonder if its the display as it cannot be detected.

https://amzn.to/47efKpx

All of those SDD1306 compatible displays should work with a kernel driver providing framebuffer like for any other GPU and display connected in more conventional ways, see https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git/tree/drivers/gpu/drm/solomon/ssd130x-i2c.c#n67