Simple WiFi NTP desktop clock with a large 7-segment display. Built on Raspberry PI Zero.
With LED dot NTP synchronization indicator...
- 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.
- 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
- 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)
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.
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.
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.
Download and 3D Print rpiclock.stl or design your own case.
-
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.
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.
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.
Make sure to configure WiFi, Locale, Timezone and DST. On Raspbian this is done using raspi-config. On Alpine setup-alpine.
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 ntpI typically configure it for pool.ntp.org and my local wifi router, which has battery backup for time.
Skip this if not using an RTC HAT.
$ 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/crontabEdit /lib/udev/hwclock-set, remove following lines:
if [ -e /run/systemd/system ] ; then
exit 0
fi
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 -dReboot, 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.
# lsmod | grep i2c
# lsmod | grep ds1307
# apk add --no-cache i2c-tools
# i2cdetect -y 1Download the binary from Releases.
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.serviceYou 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 -dSetup 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 -dRPIClock 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://github.com/ghraw/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 -dOnce you're done with the setup, you can distribute /media/mmcblk0p1/hostname.apkovl.tar.gz and usercfg.txt to other systems.
- Copyright (c) 2024 by Antoni Sawicki




