Pi-4 Model B: Setup LCD display

I purchased a Raspberry Pi 4 Rack Mount with OLED Monitor from UCTRONICS. It worked fine with Raspberry PI OS per the instructions provided with no issues, however I am setting up this as a cluster to use Kubernetes and wanted to leverage Ubuntu PI Linux. The information provided from UCTRONICS was only for the PI OS so I had to do a few things to get the display to work properly.

First Steps

  • Download the monitor script from GitHub: Uctronics Script
  • You will install the following packages but slightly differently than the README file.
    • python3-pip
    • python3-pil
    • fonts-dejavu
    • python3-dev (optional)
    • raspi-config
    • RPi.GPIO
    • adafruit-circuitpython-ssd1306

Step 1 – Install prerequisite packages

  1. Unzip the python script you downloaded from GitHub. I installed mine under “/usr/local/display”
  2. Download and Install raspi-config from repo: https://archive.raspberrypi.org/debian/pool/main/r/raspi-config/raspi-config_20210212_all.deb
  3. Install packages (as root or use sudo):
$ sudo apt update
$ sudo apt upgrade
$ sudo apt-get install RPi.GPIO python3-pip python3-pil fonts-dejavu -y    
$ sudo pip3 install adafruit-circuitpython-ssd1306        

If you run into issues see Troubleshooting section below

Configure and Test

Now that we have the packages installed we need to do a few things to get it up and running properly. We also want to auto start this as well. The procedure I used works but if you want to do something differently to autostart then thats up to you.

Enable i2c

$ sudo raspi-config

1. Select #3 Interface Options
2. Select P5 I2C and enable it
3. Then Select Finish

Test

Start python script, your directory may differ.

$ cd /usr/local/display/U6143_ssd1306-master/
$ sudo python3 ssd1306_stats.py

If the display starts and you see data on the monitor then you are all good. Now we need to set it up to start upon reboot.

Create start scripts and service

Display Script

$ cd /usr/local/display/U6143_ssd1306-master/
$ vi display.sh

#!/usr/bin/bash
# 

display="/usr/local/display/U6143_ssd1306-master/ssd1306_stats.py"

if [ -f $display ];then
        echo "running $display script"  
        /usr/bin/python3 $display
else
        echo "$display is not present, exiting"
exit 1
fi

Service Script

$ sudo vi /etc/systemd/system/display.service
[Unit]
After=network.service

[Service]
ExecStart=//usr/local/display/U6143_ssd1306-master/display.sh

[Install]
WantedBy=default.target

Configure Service

$ sudo systemctl daemon-reload
$ sudo systemctl start display. (You should see something similar to below)
$ systemctl status display

● display.service
     Loaded: loaded (/etc/systemd/system/display.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2021-03-29 18:05:30 UTC; 17h ago
   Main PID: 1789 (display.sh)
      Tasks: 6 (limit: 4433)
     Memory: 25.1M
     CGroup: /system.slice/display.service
             ├─  1789 /usr/bin/bash /usr/local/display/U6143_ssd1306-master/display.sh
             ├─  1806 /usr/bin/python3 /usr/local/display/U6143_ssd1306-master/ssd1306_stats.py
             ├─131964 /bin/sh -c top -bn1 | grep load | awk '{printf "CPU Load: %.2f", $(NF-2)}'
             ├─131965 top -bn1
             ├─131966 grep load
             └─131967 awk {printf "CPU Load: %.2f", $(NF-2)}

Mar 29 18:05:31 pi4b-node2 display.sh[1789]: running /usr/local/display/U6143_ssd1306-master/ssd1306_stats.py script
Mar 29 18:05:30 pi4b-node2 systemd[1]: Started display.service.

$ ps -ef |grep display

root        1789       1  0 10:42 ?        00:00:00 /usr/bin/bash /usr/local/display/U6143_ssd1306-master/display.sh
root        1806    1789  4 10:42 ?        00:02:54 /usr/bin/python3 /usr/local/display/U6143_ssd1306-master/ssd1306_stats.py
root      125927  118832  0 11:41 pts/0    00:00:00 grep --color=auto display

If it works go ahead and enable the service for persistent reboots

$ sudo systemctl enable display

Troubleshooting

You may get some errors, I did initially but the procedure above fixed them. You should not have issues as long as you followed everything. Of course things can change overtime.

Issue installing adafruit-circuitpython-ssd1306

Command:

pip3 install adafruit-circuitpython-ssd1306

Error:

Requirement already satisfied: pyserial>=3.0 in /usr/lib/python3/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-ssd1306) (3.4) Building wheels for collected packages: RPi.GPIO   Building wheel for RPi.GPIO (setup.py) ... error

Fix:

Make sure you installed the RPi.GPIO package and do not use the method in the README file for the UCTRONICS python script that is for PI OS only.

$ sudo apt-get install RPi.GPIO

apt-get install errors

It is possible you may get errors related to installing packages that will require fix or remove to take place. If you get an error stating that “apt –fix-broken install” should be run go ahead and do so. This will fix some package problems including prerequisites related to your install.

$ sudo apt --fix-broken install

Appendix A: Install Log

root@pi4b-node4:~# pip3 install adafruit-circuitpython-ssd1306
Processing ./.cache/pip/wheels/f4/bb/b7/54d9938e43f03b7587e4ba971669275297f67e1f25e181fbe2/adafruit_circuitpython_ssd1306-2.11.2-py3-none-any.whl
Processing ./.cache/pip/wheels/b7/e8/5e/c11967ce642778a901039337646891039a04b422033a1f408d/adafruit_circuitpython_busdevice-5.0.6-py3-none-any.whl
Processing ./.cache/pip/wheels/62/a0/97/53f5e97896b56ba9b0e897234cb8c9a1ed4ac6a6578ea7d7c7/adafruit_circuitpython_framebuf-1.4.6-py3-none-any.whl
Processing ./.cache/pip/wheels/bd/f1/12/abe65f070deed2526e6537845154d6771c2cdf78bf31fe0dd6/Adafruit_Blinka-6.4.1-py3-none-any.whl
Requirement already satisfied: Adafruit-PlatformDetect>=3.1.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (3.4.1)
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (1.1.8)
Requirement already satisfied: pyftdi>=0.40.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (0.52.9)
Collecting RPi.GPIO
  Using cached RPi.GPIO-0.7.0.tar.gz (30 kB)
Requirement already satisfied: sysv-ipc>=1.1.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (1.1.0)
Requirement already satisfied: rpi-ws281x>=4.0.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (4.2.6)
Requirement already satisfied: pyusb>=1.0.0 in /usr/local/lib/python3.8/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-ssd1306) (1.1.1)
Requirement already satisfied: pyserial>=3.0 in /usr/lib/python3/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-ssd1306) (3.4)
Building wheels for collected packages: RPi.GPIO
  Building wheel for RPi.GPIO (setup.py) ... error


root@pi4b-node2:~# apt-get install python3-pip python-dev -y
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python-dev-is-python2' instead of 'python-dev'
python3-pip is already the newest version (20.1.1-2).
The following additional packages will be installed:
  libpython2-dev libpython2-stdlib libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib python-is-python2 python2 python2-dev python2-minimal python2.7 python2.7-dev python2.7-minimal
Suggested packages:
  python2-doc python-tk python2.7-doc binfmt-support
The following NEW packages will be installed:
  libpython2-dev libpython2-stdlib libpython2.7 libpython2.7-dev libpython2.7-minimal libpython2.7-stdlib python-dev-is-python2 python-is-python2 python2 python2-dev python2-minimal python2.7 python2.7-dev python2.7-minimal
0 upgraded, 14 newly installed, 0 to remove and 61 not upgraded.
Need to get 7149 kB of archives.
After this operation, 32.1 MB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2.7-minimal arm64 2.7.18-1build2 [335 kB]
Get:2 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2.7-minimal arm64 2.7.18-1build2 [1205 kB]
Get:3 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2-minimal arm64 2.7.18-2 [13.5 kB]
Get:4 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2.7-stdlib arm64 2.7.18-1build2 [1846 kB]
Get:5 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2.7 arm64 2.7.18-1build2 [248 kB]
Get:6 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2-stdlib arm64 2.7.18-2 [7332 B]
Get:7 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2 arm64 2.7.18-2 [9068 B]
Get:8 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2.7 arm64 2.7.18-1build2 [946 kB]
Get:9 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2.7-dev arm64 2.7.18-1build2 [2237 kB]
Get:10 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 libpython2-dev arm64 2.7.18-2 [7388 B]
Get:11 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python-is-python2 all 2.7.17-4 [2496 B]
Get:12 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2.7-dev arm64 2.7.18-1build2 [288 kB]
Get:13 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python2-dev arm64 2.7.18-2 [1264 B]
Get:14 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python-dev-is-python2 all 2.7.17-4 [1396 B]
Fetched 7149 kB in 1s (4833 kB/s)                
Selecting previously unselected package libpython2.7-minimal:arm64.
(Reading database ... 111217 files and directories currently installed.)
Preparing to unpack .../0-libpython2.7-minimal_2.7.18-1build2_arm64.deb ...
Unpacking libpython2.7-minimal:arm64 (2.7.18-1build2) ...
Selecting previously unselected package python2.7-minimal.
Preparing to unpack .../1-python2.7-minimal_2.7.18-1build2_arm64.deb ...
Unpacking python2.7-minimal (2.7.18-1build2) ...
Selecting previously unselected package python2-minimal.
Preparing to unpack .../2-python2-minimal_2.7.18-2_arm64.deb ...
Unpacking python2-minimal (2.7.18-2) ...
Selecting previously unselected package libpython2.7-stdlib:arm64.
Preparing to unpack .../3-libpython2.7-stdlib_2.7.18-1build2_arm64.deb ...
Unpacking libpython2.7-stdlib:arm64 (2.7.18-1build2) ...
Selecting previously unselected package python2.7.
Preparing to unpack .../4-python2.7_2.7.18-1build2_arm64.deb ...
Unpacking python2.7 (2.7.18-1build2) ...
Selecting previously unselected package libpython2-stdlib:arm64.
Preparing to unpack .../5-libpython2-stdlib_2.7.18-2_arm64.deb ...
Unpacking libpython2-stdlib:arm64 (2.7.18-2) ...
Setting up libpython2.7-minimal:arm64 (2.7.18-1build2) ...
Setting up python2.7-minimal (2.7.18-1build2) ...
Linking and byte-compiling packages for runtime python2.7...
Setting up python2-minimal (2.7.18-2) ...
Selecting previously unselected package python2.
(Reading database ... 111952 files and directories currently installed.)
Preparing to unpack .../0-python2_2.7.18-2_arm64.deb ...
Unpacking python2 (2.7.18-2) ...
Selecting previously unselected package libpython2.7:arm64.
Preparing to unpack .../1-libpython2.7_2.7.18-1build2_arm64.deb ...
Unpacking libpython2.7:arm64 (2.7.18-1build2) ...
Selecting previously unselected package libpython2.7-dev:arm64.
Preparing to unpack .../2-libpython2.7-dev_2.7.18-1build2_arm64.deb ...
Unpacking libpython2.7-dev:arm64 (2.7.18-1build2) ...
Selecting previously unselected package libpython2-dev:arm64.
Preparing to unpack .../3-libpython2-dev_2.7.18-2_arm64.deb ...
Unpacking libpython2-dev:arm64 (2.7.18-2) ...
Selecting previously unselected package python-is-python2.
Preparing to unpack .../4-python-is-python2_2.7.17-4_all.deb ...
Unpacking python-is-python2 (2.7.17-4) ...
Selecting previously unselected package python2.7-dev.
Preparing to unpack .../5-python2.7-dev_2.7.18-1build2_arm64.deb ...
Unpacking python2.7-dev (2.7.18-1build2) ...
Selecting previously unselected package python2-dev.
Preparing to unpack .../6-python2-dev_2.7.18-2_arm64.deb ...
Unpacking python2-dev (2.7.18-2) ...
Selecting previously unselected package python-dev-is-python2.
Preparing to unpack .../7-python-dev-is-python2_2.7.17-4_all.deb ...
Unpacking python-dev-is-python2 (2.7.17-4) ...
Setting up libpython2.7-stdlib:arm64 (2.7.18-1build2) ...
Setting up libpython2.7:arm64 (2.7.18-1build2) ...
Setting up libpython2.7-dev:arm64 (2.7.18-1build2) ...
Setting up python2.7 (2.7.18-1build2) ...
Setting up libpython2-stdlib:arm64 (2.7.18-2) ...
Setting up python2 (2.7.18-2) ...
Setting up libpython2-dev:arm64 (2.7.18-2) ...
Setting up python-is-python2 (2.7.17-4) ...
Setting up python2.7-dev (2.7.18-1build2) ...
Setting up python2-dev (2.7.18-2) ...
Setting up python-dev-is-python2 (2.7.17-4) ...
Processing triggers for libc-bin (2.32-0ubuntu3) ...
Processing triggers for man-db (2.9.3-2) ...
Processing triggers for mime-support (3.64ubuntu1) ...

root@pi4b-node2:~# apt-get install RPi.GPIO
Reading package lists... Done
Building dependency tree       
Reading state information... Done
Note, selecting 'python3-rpi.gpio' for regex 'RPi.GPIO'
Note, selecting 'rpi.gpio-common' for regex 'RPi.GPIO'
The following NEW packages will be installed:
  python3-rpi.gpio rpi.gpio-common
0 upgraded, 2 newly installed, 0 to remove and 61 not upgraded.
Need to get 25.8 kB of archives.
After this operation, 94.2 kB of additional disk space will be used.
Get:1 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 rpi.gpio-common arm64 0.7.0-0.2 [3792 B]
Get:2 http://ports.ubuntu.com/ubuntu-ports groovy/universe arm64 python3-rpi.gpio arm64 0.7.0-0.2 [22.0 kB]
Fetched 25.8 kB in 1s (50.2 kB/s)         
Selecting previously unselected package rpi.gpio-common:arm64.
(Reading database ... 112115 files and directories currently installed.)
Preparing to unpack .../rpi.gpio-common_0.7.0-0.2_arm64.deb ...
Unpacking rpi.gpio-common:arm64 (0.7.0-0.2) ...
Selecting previously unselected package python3-rpi.gpio.
Preparing to unpack .../python3-rpi.gpio_0.7.0-0.2_arm64.deb ...
Unpacking python3-rpi.gpio (0.7.0-0.2) ...
Setting up rpi.gpio-common:arm64 (0.7.0-0.2) ...
Setting up python3-rpi.gpio (0.7.0-0.2) ...

root@pi4b-node2:~# pip3 install adafruit-circuitpython-ssd1306
Processing ./.cache/pip/wheels/f4/bb/b7/54d9938e43f03b7587e4ba971669275297f67e1f25e181fbe2/adafruit_circuitpython_ssd1306-2.11.2-py3-none-any.whl
Processing ./.cache/pip/wheels/62/a0/97/53f5e97896b56ba9b0e897234cb8c9a1ed4ac6a6578ea7d7c7/adafruit_circuitpython_framebuf-1.4.6-py3-none-any.whl
Processing ./.cache/pip/wheels/bd/f1/12/abe65f070deed2526e6537845154d6771c2cdf78bf31fe0dd6/Adafruit_Blinka-6.4.1-py3-none-any.whl
Processing ./.cache/pip/wheels/b7/e8/5e/c11967ce642778a901039337646891039a04b422033a1f408d/adafruit_circuitpython_busdevice-5.0.6-py3-none-any.whl
Requirement already satisfied: RPi.GPIO in /usr/lib/python3/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (0.7.0)
Processing ./.cache/pip/wheels/a5/8d/f7/0d28f2382ea77b66b0a64eb1bc43b10eb07aa8bd5e7369d0b2/sysv_ipc-1.1.0-cp38-cp38-linux_aarch64.whl
Requirement already satisfied: Adafruit-PureIO>=1.1.7 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (1.1.8)
Requirement already satisfied: pyftdi>=0.40.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (0.52.9)
Requirement already satisfied: Adafruit-PlatformDetect>=3.1.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (3.4.1)
Requirement already satisfied: rpi-ws281x>=4.0.0 in /usr/local/lib/python3.8/dist-packages (from Adafruit-Blinka->adafruit-circuitpython-ssd1306) (4.2.6)
Requirement already satisfied: pyusb>=1.0.0 in /usr/local/lib/python3.8/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-ssd1306) (1.1.1)
Requirement already satisfied: pyserial>=3.0 in /usr/lib/python3/dist-packages (from pyftdi>=0.40.0->Adafruit-Blinka->adafruit-circuitpython-ssd1306) (3.4)
Installing collected packages: sysv-ipc, Adafruit-Blinka, adafruit-circuitpython-framebuf, adafruit-circuitpython-busdevice, adafruit-circuitpython-ssd1306
Successfully installed Adafruit-Blinka-6.4.1 adafruit-circuitpython-busdevice-5.0.6 adafruit-circuitpython-framebuf-1.4.6 adafruit-circuitpython-ssd1306-2.11.2 sysv-ipc-1.1.0
186  mkdir /usr/local/display
  187  mv /root/U6143_ssd1306-master /usr/local/display
  188  scp andy@pi4b-node2:/usr/local/display/display.sh /usr/local/display/
  189  scp andy@pi4b-node2:/usr/local/display/U6143_ssd1306-master/display.sh /usr/local/display/U6143_ssd1306-master/display.sh 
  190  scp andy@pi4b-node2:/etc/systemd/system/display.service /etc/systemd/system/display.service
  191  systemctl daemon-reload
  192  systemctl status display
  193  systemctl enable display
  194  systemctl start display
  195  systemctl status display
  196  ps -ef |grep python