Simple Internet Status Display with Raspberry Pi Zero W
Build a straightforward internet connection monitor using a Raspberry Pi Zero W and Pimoroni Display Hat Mini 2.0 that shows your connection status in real-time.
Over the last week, I added a couple of new Pis to my growing collection, including a new Zero W, Zero 2 W, and some accessories. I needed a quick win yesterday, so I busted out a project to play with my new Pimoroni Display Hat Mini 2.0 and the new Zero W.
Project Overview
This project displays the current internet status on a Display Hat Mini 2.0, using a Raspberry Pi Zero W. The primary code is written in Python 3 and runs via a service file that is executed on boot. When the connection is up, the display shows a green message stating "Wi-Fi is currently up", and when the connection is down, it shows a red message stating "Wi-Fi is currently down".
Hardware Requirements
- Raspberry Pi Zero W (tested with Raspbian Bullseye)
- Display Hat Mini 2.0
Software Requirements
- Python 3
- Required Python libraries:
- RPi.GPIO
- spidev
- PIL (Python Imaging Library)
- numpy
- st7789
- displayhatmini
Installation Steps
-
First, follow Pimoroni's Display Hat Mini instructions to install the Display Hat Mini Python Libraries.
-
Install the required system packages and enable SPI:
sudo apt update sudo apt install python3-rpi.gpio python3-spidev python3-pip python3-pil python3-numpy sudo raspi-config nonint do_spi 0
-
Install the necessary Python packages:
sudo pip3 install Pillow sudo pip3 install st7789 pip3 install displayhatmini
-
Copy the project files to their respective locations:
internet_status.py
→/home/pi/
internet_status.service
→/etc/systemd/system/
-
Enable and start the service:
sudo systemctl enable internet-status.service sudo systemctl start internet-status.service
How It Works
The Python script runs a continuous loop that:
- Attempts to establish a connection to
www.google.com
- Updates the Display Hat Mini with the current status
- Waits 15 seconds before checking again
Here's the core connection checking function:
def check_connection():
try:
# Try to connect to Google's server
host = socket.gethostbyname("www.google.com")
s = socket.create_connection((host, 80), 2)
return True
except:
# If connection fails, return False
return False
The display updates in real-time, using green text to indicate an active connection and red text to show when the connection is down.
Conclusion
This project demonstrates how to create a simple but effective internet status monitor using a Raspberry Pi Zero W and Display Hat Mini 2.0. It's a fun project for those who want to keep an eye on their network connection status with a dedicated physical display.
The complete code and setup instructions are available in my GitHub repository: Raspi Zero W Internet Service Service