====== Display ======
writing down some notes for getting ssd1306 oled display to work on r3
to avoid using adafruit libs i try luma-oled which is available on pypi
https://luma-oled.readthedocs.io/en/latest/python-usage.html
apt install python3 python3-venv
add user and create python3 venv and activate it
frank@bpi-r3:~$ python3 -m venv .venv_display
frank@bpi-r3:~$ . .venv_display/bin/activate
(.venv_display) frank@bpi-r3:~$
install luma-oled package
pip3 install luma-oled
spidev needs compiler for target
aarch64-linux-gnu-gcc -pthread -Wno-unused-result -Wsign-compare -DNDEBUG -g -fwrapv -O2 -Wall -g -ffile-prefix-map=/build/python
3.9-PN012d/python3.9-3.9.2=. -fstack-protector-strong -Wformat -Werror=format-security -g -fwrapv -O2 -fPIC -I/home/frank/.venv_dis
play/include -I/usr/include/python3.9 -c spidev_module.c -o build/temp.linux-aarch64-cpython-39/spidev_module.o
error: command 'aarch64-linux-gnu-gcc' failed: No such file or directory
----------------------------------------
ERROR: Failed building wheel for spidev
Failed to build spidev
ERROR: Could not build wheels for spidev which use PEP 517 and cannot be installed directly
apt install gcc python3-dev
at least gcc installs many depencies which should be removed from router when all is done:
The following NEW packages will be installed:
binutils binutils-aarch64-linux-gnu binutils-common cpp cpp-10
fontconfig-config fonts-dejavu-core gcc gcc-10 libasan6 libatomic1
libbinutils libbrotli1 libc-dev-bin libc-devtools libc6-dev libcc1-0
libcrypt-dev libctf-nobfd0 libctf0 libdeflate0 libfontconfig1 libfreetype6
libgcc-10-dev libgd3 libgomp1 libisl23 libitm1 libjbig0 libjpeg62-turbo
liblsan0 libmpc3 libmpfr6 libnsl-dev libpng16-16 libtiff5 libtirpc-dev
libtsan0 libubsan1 libwebp6 libxpm4 linux-libc-dev manpages manpages-dev
alternative way: building wheels in chroot
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
cd tmp
tar -czf ../luma-oled.tar.gz *.whl
{{ :en:bpi-r3:luma-oled.tar.gz |}}
connect it (3v3,gnd,sda,scl)
{{:en:bpi-r3:oled_connection1.jpg?direct&400 |}}
{{:en:bpi-r3:oled_connection2.jpg?direct&200|}}
root@bpi-r3:~# apt install i2c-tools
root@bpi-r3:~# 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: -- -- -- -- -- -- -- --
root@bpi-r3:~# ls -l /dev/i2c-2
crw-rw---- 1 root i2c 89, 2 Dec 31 08:51 /dev/i2c-2
root@bpi-r3:~# adduser frank i2c
root@bpi-r3:~# su -l frank
frank@bpi-r3:~$ . .venv_display/bin/activate
(.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")
...
>>>
tried to get my rpi 3.5" display working too, but gpio-lib is only for rpi
Installing collected packages: luma-lcd
Successfully installed luma-lcd
(.venv_display) frank@bpi-r3:~$ python3 display.py
Traceback (most recent call last):
File "/home/frank/.venv_display/lib/python3.9/site-packages/luma/core/lib.py", line 23, in __rpi_gpio__
import RPi.GPIO as GPIO
File "/home/frank/.venv_display/lib/python3.9/site-packages/RPi/GPIO/__init__.py", line 23, in
from RPi._GPIO import *
RuntimeError: This module can only be run on a Raspberry Pi!
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/frank/display.py", line 6, in
serial = spi(port=1, device=0, gpio_DC=23, gpio_RST=24)
File "/home/frank/.venv_display/lib/python3.9/site-packages/luma/core/interface/serial.py", line 305, in __init__
bitbang.__init__(self, gpio, transfer_size, reset_hold_time, reset_release_time, DC=gpio_DC, RST=gpio_RST)
File "/home/frank/.venv_display/lib/python3.9/site-packages/luma/core/interface/serial.py", line 188, in __init__
self._gpio = gpio or self.__rpi_gpio__()
File "/home/frank/.venv_display/lib/python3.9/site-packages/luma/core/lib.py", line 29, in __rpi_gpio__
raise luma.core.error.UnsupportedPlatform(
luma.core.error.UnsupportedPlatform: GPIO access not available