/rpiclock

Raspberry PI Zero WiFi-NTP/RTC Desktop Clock

Primary LanguageGoApache License 2.0Apache-2.0

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.

RPI Zero Clock

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

Building the hardware

Wiring GPIO to Adafruit Segment Display I2C

  • RPi 3.3V to 7-Segment Display IO (V_IO)
  • RPi 5V to 7-Segment Display + (+5V)
  • RPi GND to 7-Segment Display - (GND)
  • RPi SCL to 7-Segment Display C (SCL)
  • RPi SDA to 7-Segment Display D (SDA)

Wiring Diagram

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.

RTC HAT

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

GSM/GPRS/GPS 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

3D Printed Case

Download and 3D Print rpiclock.stl or design your own case.

Software configuration

OS

  • Linux. The ubiquitous Raspberry Pi OS (formerly Raspbian) is quite of a bloat and slow to boot but otherwise works pretty well. Disable wait for network to speed up boot. Faster options are Alpine, piCore or instant-pi.

  • FreeBSD - maybe. Super slow to boot and no wlan support on rpi zero.

  • NetBSD - no wlan support.

  • Plan 9 - https://periph.io/ is not supported

Power

Check if Raspberry PI is not experiencing low voltage. You can run vcgencmd get_throttled, it should return 0x0.

I2C Interface

Make sure I2C interface is enabled. On Raspbian this is done using raspi-config under Interface Options. Run i2cdetect -y 1. It should show value 70 on position 70.

WiFi, Locale, Timezone, DST, etc.

Make sure to configure WiFi, Locale, Timezone and DST. On Raspbian this is done using raspi-config.

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

RTC hwclock (optional)

Skip this if not using an RTC HAT.

RTC/hwclock also depends on which OS you are using. Following instructions are for Raspbian:

$ sudo apt install i2c-tools
$ 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

Reboot, check if hwclock works:

$ i2cdetect -y 1

should show UU on position 68.

$ sudo hwclock -r
$ sudo hwclock -w

Clock Service Install

Download 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.service

References

Legal

  • This is not an officially supported Google product.
  • Copyright © 2021-2023 Google LLC