README
¶
Raspberry PI Zero WiFi-NTP 7-Segment Desktop Clock
Simple WiFi NTP desktop clock with a large 7-segment display. Built on Raspberry PI Zero.

With LED dot NTP synchronization indicator...
Why?
- Computers and mobile devices have been using NTP, GSM/GPRS, GPS/GNSS to synchronize time for decades. Desktop / wall and alarm clocks still live in 19th century.
- Changing time twice a year due to retarded DST sucks ass.
- I want to have an indication to see if the time is accurate (synchronized) or not.
- Maybe I want to have Stratum 1 desktop clock.
Hardware BOM
- Raspberry PI Zero with WiFi and GPIO Headers
- Adafruit 1.2" 7-Segment Display with I2C Backpack
- Breadboard Wires
- Optional Abelectronics RTC Pi Backup Hat
- Optional Adafruit VEML7700 Lux Sensor
- USB power supply and cable
- Case, either 3D printed or make your own
- Screen, Size: 120 x 50 x 3mm
Building the hardware
Wiring GPIO to Adafruit Segment Display I2C
- RPi
3.3Vto 7-Segment DisplayIO(V_IO) - RPi
5Vto 7-Segment Display+(+5V) - RPi
GNDto 7-Segment Display-(GND) - RPi
SCLto 7-Segment DisplayC(SCL) - RPi
SDAto 7-Segment DisplayD(SDA)

Optional RTC Backup Battery Hat
RTC is not required and almost never used while using NTP. However in case of power loss AND internet/wifi/router not being up before Raspberry PI boots, you will get time from fake-hwclock, which is no use. RTC backup will make your time accurate in this rare circumstance.

There are many RTC backup modules available on the market, this one is Pi Zero sized.
Install RTC Hat between PI GPIO and wires going to the display. Make sure you install the coin battery before powering it on. The vendor warns that operation without battery will damage the board. Follow instructions below for software setup.
Advanced - GSM/GPRS/GPS/GNSS Hat

A complete overkill but you can also get time from:
- GSM tower via NITZ (no paid subscription required)
- GSM network location (CLBS / CIPGSMLOC)
- GPRS network location (AGPS)
- GNSS/GPS/COMPASS/etc. GPS based time
You can use one of these hats or similar. MAX-M8Q has passthrough GPIO and awesome Raspberry PI and NTP setup instructions.
GSM/GPRS time penetrates buildings like normal cell phone. GPS requires an open sky access but is less dependent on ground infrastructure.
Light sensor
Rpiclock is set to change brightness based on time of day. A more advanced case would be to use a I2C based Lux sensor to measure ambient light and change display brightness based on input from the sensor. Example sensor VEML7700.
Case

Download and 3D Print rpiclock.stl or design your own case.
Software configuration
OS
-
Linux
- Raspberry Pi OS (formerly Raspbian), ubiquitous but is quite of a bloat and slow to boot, but otherwise works well, safe choice.
- Alpine easy config transfer between SD cards, doesn't require shutdown, smaller, faster and not bloated. My personal choice.
- piCore.
- instant-pi.
- DietPi despite promising name is actually quite slow to boot, likely due to Pigbian base.
-
FreeBSD - maybe. Super slow to boot and no wlan support on rpi zero.
-
NetBSD - no wlan support.
-
Plan 9 / 9front - maybe if rewritten in C.
-
RISC OS - maybe if rewritten in C.
Power
Check if Raspberry PI is not experiencing low voltage. You can run vcgencmd get_throttled, it should return 0x0. On Alpine you need to install install raspberrypi-utils.
I2C Interface
Make sure I2C interface is enabled. On Raspbian this is done using raspi-config under Interface Options.
On Alpine mount mmc boot partition and edit /boot/usercfg.txt (or config.txt). Add: dtparam=i2c_arm=on.
Run i2cdetect -y 1.
WiFi, Locale, Timezone, DST, etc.
Make sure to configure WiFi, Locale, Timezone and DST. On Raspbian this is done using raspi-config. On Alpine setup-alpine.
NTP
A real NTP daemon supporting RFC5905 is required to be able to get leap indicator and show whether the clock is synchronised or not. You can still use rpiclock without NTP but it will not show the status.
$ apt install ntp
I typically configure it for pool.ntp.org and my local wifi router, which has battery backup for time.
RTC hwclock (optional)
Skip this if not using an RTC HAT.
Raspbian
$ sudo apt remove fake-hwclock
$ sudo echo dtoverlay=i2c-rtc,ds1307 >> /boot/config.txt
$ sudo echo rtc-ds1307 >> /etc/modules
$ sudo echo '5 * * * * * root /sbin/hwclock -w' >> /etc/crontab
Edit /lib/udev/hwclock-set, remove following lines:
if [ -e /run/systemd/system ] ; then
exit 0
fi
Alpine
Mount mmc card under /media/mmcblk0p1 to write to usercfg.txt.
# mount -o remount,rw /media/mmcblk0p1
# echo dtparam=i2c_arm=on >> /media/mmcblk0p1/usercfg.txt
# echo dtoverlay=i2c-rtc,ds1307 >> /media/mmcblk0p1/usercfg.txt
# echo i2c-dev >> /etc/modules
# echo rtc-ds1307 >> /etc/modules
# echo '5 * * * * /sbin/hwclock -w -l' >> /etc/crontabs/root
# sed -i 's/^clock="UTC"/clock="local"/' /etc/conf.d/hwclock
# rc-update del swclock boot
# lbu ci -d
Reboot, check if hwclock works. Ideally this should be done before WiFi is configured so NTP won't interfere with RTC testing. You can also disable chrony from start on boot to test.
Troubleshooting
# lsmod | grep i2c
# lsmod | grep ds1307
# apk add --no-cache i2c-tools
# i2cdetect -y 1
Clock Service Install
Download the binary from Releases.
Raspbian
If using systemd Download Service File and move in to ~/.config/systemd/user/rpiclock.service. Make sure the right path to the binary is specified.
$ loginctl enable-linger $USER
$ systemctl --user daemon-reload
$ systemctl --user enable --now rpiclock.service
Alpine
You may already done this for the RTC, if not:
# mount -o remount,rw /media/mmcblk0p1
# echo dtparam=i2c_arm=on >> /media/mmcblk0p1/usercfg.txt
# echo i2c-dev >> /etc/modules
# lbu ci -d
Setup NTP:
# setup-ntp chrony
# echo "allow 127.0.0.1" >> /etc/chrony/chrony.conf
# echo "makestep 1.0 3" >> /etc/chrony/chrony.conf
# rc-service chronyd restart
# lbu ci -d
RPIClock service:
# wget -O /sbin/rpiclock https://github.com/tenox7/rpiclock/releases/download/1.2/rpiclock
# chmod 755 /sbin/rpiclock
# lbu include /sbin/rpiclock
# wget -O /etc/init.d/rpiclock https://raw.githubusercontent.com/tenox7/rpiclock/refs/heads/main/rpiclock.openrc
# chmod 755 /etc/init.d/rpiclock
# lbu include /etc/init.d/rpiclock
# rc-update add rpiclock default
# rc-service rpiclock start
# lbu ci -d
Once you're done with the setup, you can distribute /media/mmcblk0p1/hostname.apkovl.tar.gz and usercfg.txt to other systems.
References
Legal
- Copyright (c) 2024 by Antoni Sawicki
Documentation
¶
Overview ¶
rpiclock dummy display driver, prints out to screen for debug
rpiclock driver for Pimoroni Micro Dot pHAT with Lite-On LTP-305 https://shop.pimoroni.com/en-us/products/microdot-phat
rpiclock driver for Adafruit seven segment LED display with backpack (HT16K33) https://www.adafruit.com/product/1270