- Raspberry Pi 4 (8GB)
- Ubuntu Server 21.10 (64-bit server OS for arm64 architectures)
- Mini-tower case with SSD (NVMe M.2)
- 128×64 I2C OLED display
- Make sure your system is up to date
sudo apt update && sudo apt upgrade -y
Reboot your PI
sudo reboot
- Install drivers and libraries
sudo apt install -y python3-pip python3-dev python3-pil python3-setuptools python3-rpi.gpio i2c-tools
- Add your current user account to the group
i2c
sudo usermod -aG i2c ubuntu
-
Connect the OLED Display to the Raspberry Pi
-
Check if the display was recognized
i2cdetect -y 1
The output should look like the following:
ubuntu@ubuntu:~$ i2cdetect -y 1
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: -- -- -- -- -- -- -- --
ubuntu@ubuntu:~$
- Install SSD1306 python libary
sudo pip3 install adafruit-circuitpython-ssd1306
- Install monitor script
Clone the script from Michael Klements
git clone https://github.com/mklements/OLED_Stats.git
Go to the cloned directory
cd OLED_Stats
Then run the script by entering:
python3 stats.py
If you have the following error when you execute the script:
ubuntu@ubuntu:~/OLED_Stats$ python3 stats.py
Traceback (most recent call last):
File "/home/ubuntu/OLED_Stats/stats.py", line 16, in <module>
oled_reset = digitalio.DigitalInOut(board.D4)
File "/usr/local/lib/python3.9/dist-packages/digitalio.py", line 145, in __init__
self.direction = Direction.INPUT
File "/usr/local/lib/python3.9/dist-packages/digitalio.py", line 175, in direction
self._pin.init(mode=Pin.IN)
File "/usr/local/lib/python3.9/dist-packages/adafruit_blinka/microcontroller/bcm283x/pin.py", line 37, in init
GPIO.setup(self.id, GPIO.IN)
RuntimeError: Not running on a RPi!
ubuntu@ubuntu:~/OLED_Stats$
Pay attention to the last line! It means that you have a persmission problem. There are two methods to solve this issue:
Method 1. Run the script with elevated privileges:
sudo python3 stats.py
Method 2. Make sure the current user has the proper privileges.
With Ubuntu server 21.10 64-bit on RPi 4, that can be achieved by creating a gpio
group, and adding an udev rule to give this group access to /dev/gpiomem
(which can normally only be accessed by root).
Create a /etc/udev/rules.d/90-gpio.rules
file
sudoedit /etc/udev/rules.d/90-gpio.rules
add the following content
KERNEL=="gpiomem", OWNER="root", GROUP="gpio"
Create the group gpio
and assign it to an existing user, in my case "ubuntu":
sudo groupadd -f --system gpio
sudo usermod -a -G gpio ubuntu
Reboot
sudo reboot
You should be able to run the script as following:
python3 stats.py
- Run The Script On Start-up
Open up crontab by entering the following command:
crontab –e
Add the following line to the end of the file to run the script:
@reboot cd /home/ubuntu/OLED_Stats && python3 stats.py &
reboot and you should now have a working OLED stats display that starts up automatically each time your Pi boots up.
All credits to: https://www.the-diy-life.com/add-an-oled-stats-display-to-raspberry-pi-os-bullseye/
Brilliant instructions!!
Couple of observations from my experience installing this on u20.04:
On my pi this needed
sudo i2cdetect -y 1
On running
python3 stats.py
I got the following error repeating but my oled came alive:I ran this to solve that one:
sudo apt-get install libraspberrypi-bin -y
Then I got this:
The solution to this for me was adding the video group to the ubuntu user:
sudo usermod -aG video ubuntu
However, weirdly, logging out and logging back in wasn't enough - you need to reboot at this point.
Not sure if this is my browser or character encoding issue but copy pasting this
crontab –e
gave me a confusing error because I know this is correct:If you type
crontab -e
it works fine.Thanks for this @Nguimjeu