NTP-Based Clock

This project is designed to be a simple & generic NTP-based clock.

Simple power up the hardware and it will show you the current time, complete with blinking : symbol.

Hardware

The hardware for this project is simple:

Wiring the project is very simple, and merely consists of connecting the display to the Mini D1 board, which is powered by a simple USB-PSU:

  1. Vcc -> Vcc
  2. Gnd -> Ground
  3. CLK -> WeMos D1 D3
  4. DIO -> WeMos D1 D2

 

The assembled result looks something like this:

The result..

The screen is bright, but hard to read in this photo. The time shown is 13:28, which you can see if you squint just enough. Once placed in a suitable container it looks much more readable, in this case showing 14:52:

The result..

Software

The software for this project is very simple, and logically divided into three parts:

  • Handling connections to the local WiFi network.
  • Fetching the current date & time, via NTP.
  • Drawing the time.

For dealing with the date & time, including retrieving the current time via NTP, I used the standard time library, which has excellent support for such things.

I've also added support for over-the-air-updates, which means that new code can be flashed on the deployed harware without touching the cabling, directly from the Arduino IDE.

Operation

If you've previously configured WiFi details the device will connect automatically, and begin showing the current time. If you've never configured the device it will instead notice that, and configure itself as an access-point. This means you can use your mobile phone, or other WiFi-connected device, to connect to this access-point and select the local WiFi network it should become part of.

Once running the system will:

  • Update the display once a second, to handle the blinking ":".
    • Initially I configured it to only update when the minute changed, but later added the blinking : behaviour.
  • Resync the time, via NTP, every five minutes to avoid drift.

The Code

The main code looks like this:

Several libraries are used, and these are bundled together in a git repository, you can access all the source by cloning the repo involved, and then looking at the project: