This Python script displays system statistics on an OLED display connected to a Raspberry Pi. It utilizes the psutil
library to gather system information and the luma.oled
library for interfacing with the OLED display.
- Raspberry Pi with GPIO access
- OLED display
- Python 3.x installed on the Raspberry Pi
pip
package manager installed on the Raspberry Pi
-
Clone the Repository:
git clone https://github.com/f-4-u/rpi_oled.git cd rpi_oled
-
Create and Activate a Virtual Environment:
python3 -m venv env source env/bin/activate
-
Install Dependencies:
pip install -r requirements.txt
-
Connect OLED Display:
Ensure your OLED display is properly connected to the Raspberry Pi.
-
Activate Virtual Environment:
source env/bin/activate
-
Run the Script:
python stats.py
The script will continuously display system statistics on the OLED display.
-
Exit the Script:
To stop the script, press
Ctrl+C
.
If you add or remove dependencies in your script, update the requirements.txt
file:
pip freeze > requirements.txt
And re-install the dependencies:
pip install -r requirements.txt
To automatically start the stats.py
script at bootup on your Raspberry Pi, you can create a systemd service. Follow these steps:
-
Create a systemd Service File:
Create a new file named
display-stats.service
in the/etc/systemd/system/
directory.sudo nano /etc/systemd/system/display-stats.service
Add the following content to the file:
[Unit] Description=Display Stats Script After=network.target [Service] ExecStart=/path/to/your/project/env/bin/python /path/to/your/project/stats.py WorkingDirectory=/path/to/your/project User=yourusername Group=yourusername Restart=always [Install] WantedBy=multi-user.target
Replace
/path/to/your/project
with the actual path to your project directory and setyourusername
to the username of your Raspberry Pi. -
Reload systemd and Enable the Service:
sudo systemctl daemon-reload sudo systemctl enable display-stats.service
-
Start the Service:
sudo systemctl start display-stats.service
To check the status or troubleshoot, you can use:
sudo systemctl status display-stats.service
To stop or restart the service:
sudo systemctl stop display-stats.service sudo systemctl restart display-stats.service
To ensure proper access to GPIO and I2C functionalities, it may be necessary to add your default user to the gpio
and i2c
groups on your Raspberry Pi. Follow these steps:
-
Add User to
gpio
Group:sudo usermod -aG gpio $USER
-
Add User to
i2c
Group:sudo usermod -aG i2c $USER
-
Restart Your Raspberry Pi:
To apply the changes, restart your Raspberry Pi:
sudo reboot
After completing these steps, your user should have the necessary group memberships to access GPIO and I2C without requiring elevated privileges. This is important for running scripts interacting with hardware interfaces seamlessly.
The script uses the Dogica font. Dogica is a monospace typeface made with Inkscape and FontForge and tailored for GB Studio. It features more than 200 characters in an 8x8 grid and comes in two styles: monospace and pixel, the kerned version. Four pictures for GB Studio are included. It is free for personal and commercial use under the OFL license. Credit/attribution is not required for raster works.
This project is licensed under the MIT License.