How to Build a Plug-In Pi Zero Display and Show Something Useful

Jamie Bailey
Initial State
Published in
6 min readOct 12, 2020

--

Raspberry Pi Zero Plug-In Display

Introduction

I wanted to create a simple, compact display driven by a Raspberry Pi Zero that plugs into a power outlet to display some useful information in my kitchen. No visible wires hanging out or anything that looks funky. I assumed someone already makes a Pi Zero case + power supply combo that I could just buy and plug in. Alas, I found no such convenient product on the interwebs (why?!?!?). Unwilling to accept defeat, I came up with a solution using off-the-shelf parts. This ended up being a fun little project from the hardware to the software. I am hoping I can save someone from the same frustrations I had by documenting this build.

In this project, we will:

  • Build a compact Raspberry Pi Zero display that plugs into a power outlet using cheap, off-the-shelf components.
  • Set up a Pi Zero to run a simple Python script on boot that retrieves information from a web API and cycles through that info on the display.

Parts and Materials

Raspberry Pi Zero Plug-In Display Parts and Materials
Raspberry Pi Zero Plug-In Display Parts and Materials

Here are the parts I used for my final build:

  • Raspberry Pi Zero WH ($14, link).
  • Adafruit 2.23" 128x32 OLED Bonnet ($22.50, link).
  • 16 GB micro SD card ($6, link).
  • Dodoli 12W USB wall charger ($10 for two, link).
  • UCEC USB-A male to USB micro male adapter ($9 for two, link).
  • Pi Zero case (optional).

The plan is to run the Pi Zero headless. I keep and reuse one wireless keyboard/mouse (link) and an HDMI cable with an HDMI mini adapter (link) attached to a TV to set up any Pi Zeros for the first time.

Assembly is simple. The OLED display plugs into the 40-pin GPIO header of the Pi Zero. The USB micro male adapter plugs into the USB power port of the Pi Zero and the USB charger provides the actual power. You will need to format the SD card and install the Raspberry Pi OS (a great tutorial on getting your Pi set up for the first time can be found here).

Don’t Do This!!

Pi Zero Display Backwards Fail
Pi Zero Display Backwards Fail

My first attempt at finding the parts to use for this project looked like the image above. I bought the wrong USB charger because I failed to take into account that USB-A plugs in only one way. That USB wall charger orients the display toward the wall. No bueno. Make sure the USB-A plug is oriented like the one in the previous section (link)!!

Alternative Setup

Altnerative Plug-In Pi Zero Display Parts
Altnerative Plug-In Pi Zero Display Parts

The Nekmit USB charger I bought first has both a USB-A port that is oriented in the wrong direction (useless!) and a USB-C port that can plug in either direction (useful!). Unfortunately, I could not find a USB-C male to USB micro male adapter. But, I did find a couple of adapters to connect together to make it work. This build is a bit more expensive but gets the job done:

  • Raspberry Pi Zero WH ($14, link).
  • Adafruit 2.23" 128x32 OLED Bonnet ($22.50, link).
  • 16 GB micro SD card ($6, link).
  • Nekmit 30W USB-C charger ($20, link).
  • USB-C female to USB micro male adapter ($7 for five, link).
  • USB-C male to USB-C male adapter ($10, link).
Alternative Plug-in Pi Zero Display
Alternative Plug-in Pi Zero Display

Display Something Useful — Detailed Example

Plug-in Pi Zero Display In Action
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
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.

--

--

Jamie Bailey
Initial State

EVP Strategy, Alto | ex-CEO Initial State | SaaS | startup guy | nerd