/SSD1306-Display-SysInfo

System information for the SSD1306 OLED Display on Raspberry Pi

Primary LanguagePythonMIT LicenseMIT

SSD1306 Display SysInfo

System information for the SSD1306 OLED Display on Raspberry Pi

This project was designed around the Adafruit PiOLED 128x32 OLED display.
As it involves a SSD1306 chipset, this can be adapted for such displays and of other resolutions.

This project is based on the Python script and instructions from here.

What does this do?

Mainly, this displays the following system information:

  • Time
  • IP address (IPv4)
  • CPU load
  • Memory usage
  • Disk usage

Bonus feature

When a msg.txt file is created in the same directory as the Python script, the file contents will be outputted and centered (x & y) on the display. The file then gets removed and there will be a delay before it updates the display again (to either display the next message from said file or to go back to the system information view).

This was developed to make use of TPLink-LightBulb-HTTP's last status logging, but it can be used for various other purposes.

Configuration

This was tested with a Raspberry Pi Zero W. If it is a different device, then further modifications may have to be done to the scripts or system.

Getting i2c ready

The i2c interface first needs to be enabled. You can do this through the raspi-config TUI. Alternatively, you can run a command to achieve this.

sudo raspi-config nonint do_i2c 0

Once set to enabled, the device has to be rebooted. But in this case, we will shutdown instead.

sudo shutdown now

Connect the display to the respective GPIO and then power the device back on again.

To verify that the display is being picked up on, run the following:

sudo apt install i2c-tools
sudo i2cdetect -y 1

If all goes well, you should see a mention of 3c (0x3c address).

Gathering the Python packages

The Python script has several requirements.

First, we first make sure we have PIP (package manager) installed.

sudo apt-get install python3-pip

We then need PIL for drawing images for the display.

sudo apt-get install python3-pil

We are going to assume that we are in the home directory of the current user. Adjust the steps as needed.

We will need to change directory into where the Python script is.

cd ~/SSD1306-Display-SysInfo

A Python virtual environment will need to be created.

python -m venv env --system-site-packages

Get into the context of that virtual environment.

source env/bin/activate

There is a package that is required in order to drive the display.

pip3 install adafruit-circuitpython-ssd1306

Additional configuration

If your display is not 128x32, then adjust the width and height values under the disp variable.

Running the script

To run, simply run:

python main.py

If you get an Import error, make sure you are using the virtual environment.

If you wish to run the Python script such as in the context of a service or to just run it more directly, you can use the virtual environment in a single command.

/home/{USER}/SSD1306-Display-SysInfo/env/bin/python3 /home/{USER}/SSD1306-Display-SysInfo/main.py