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
The hardware for this project is simple:
- 1 x WeMos Mini D1 - Approximately €2.50.
- 1 x I2C 4x7-Segment Display - Approximately €1.40.
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:
- Vcc -> Vcc
- Gnd -> Ground
- CLK -> WeMos D1 D3
- DIO -> WeMos D1 D2
The assembled result looks something like this:
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
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.
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
- Resync the time, via NTP, every five minutes to avoid drift.
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: