How to Build a Plug-In Pi Zero Display and Show Something Useful
By: Jamie Bailey
Tags: Raspberry Pi, Python, Makers

Display Something Useful — Detailed Example

Plug-in Pi Zero Display In Action

With the hardware in place, it is time to set up the Pi Zero to display something useful. I recently installed a Pi Zero in my crawl space to monitor temperature and humidity (and wrote up the details of this project here). I am sending the sensor data from my crawl space to Initial State. Instead of viewing this data on the web dashboard, I want it to be displayed on my Pi Zero display in my kitchen along with sensor data from my attic and outside weather information. Since my Pi Zero is headless, I also want to display the IP address in case I need to SSH into it again.

Once Raspberry Pi OS is installed (instructions) and you have set up WiFi (instructions), you will need to enable both SSH (for remote access) and i2c (for the OLED display). At the Pi terminal type:

sudo raspi-config

Select 5 Interfacing Options , P5 I2C , and select <YES> to enable i2c.

Select 5 Interfacing Options , P2 SSH , and select <YES> to enable SSH. Select <Finish> to save and exit.

Next, install the Python library to allow interfacing the Adafruit OLED Bonnet:

sudo pip3 install adafruit-circuitpython-ssd1305

Since I am going to read data from my Initial State account in this example, I want to install the Initial State Read API Python module to make writing my Python script easier:

sudo pip install ISReader

The following Python script rotates through displaying four screens of data — my crawl space temperature/humidity, my attic temperature/humidity, outside temperature/humidity, and the Pi Zero IP address. To use this script as it is, modify the User Settings section with your Initial State access key (more info), bucket key (more info), and stream names to be read.

The Python code above is easy-to-follow and can serve as a template to displaying whatever information you need. For example, you can use it to display information from other web APIs or just other data from Initial State (e.g. stock data, detailed weather data, Chuck Norris jokes).

Remotely Accessing Your Pi

If you want to test out remotely configuring your Pi, at the Pi terminal type:

hostname -I

This will return the IP address of your Pi. At your laptop terminal, type:

ssh pi@<insert Pi ip address>

For example:

SSH into your Pi from your laptop

Once you can successfully SSH into your Pi, you may want to make it boot directly to the console instead of loading the desktop UI. You can do this as follows: sudo raspi-config -> 3 Boot Options -> B1 Desktop / CLI -> B2 Console Autologin -> <ok> -> exit.

Running on Boot

The final piece of the puzzle is to have the Pi Zero run this script on boot. This will allow you to plug your Pi Zero into a power outlet and it start displaying data without any other manual steps. At the Pi terminal:

crontab -e

At the bottom of the text file, add the following line of text (modify the path and script name to your specific path/script name), save, and exit:

@reboot python3 /home/pi/runoled.py &

Notice the 30 second delay on line 46 of the example script. This allows the Pi to establish a WiFi connection before it attempts to hit a web API.

Conclusion

Being able to plug a Pi Zero with an OLED display into a wall outlet and it actually look good is oddly satisfying. I really like the fact that I can reuse this project to display whatever information I want in the future. This project can be particularly useful in a media closet, server room, or in a lab setting.