Clock with large display - Part 2

In the first part of this blog I had rebuilt and described the project of our customer Hans-Ulrich Küster with its large-format display of the time. In order to obtain a large display as possible, he had placed two MAX7219 8x32 Matrix Displays on top of each other. As a clock served a Real Time Clock RTC DS3231 I2C.

In this part I would like to show how I replaced the Micro Controller with Atmega 328P by the Wi-Fi-enabled Micro Controllers of Espressif. For this purpose, I first left the sketch largely unchanged, but the two interfaces SPI and I2C are each at other pins than on the Micro Controller Board with Atmega. So I had to adapt the circuit and the sketch.

Hardware used:


Nodemcu Lua Amica Module V2 ESP8266 ESP-12F WiFi WiFi Development Board with CP2102


ESP32 NODEMCU Module WLAN WIFI Development Board with CP2102


MAX7219 8x32 4 in 1 Dot Matrix LED display module


Real Time Clock RTC DS3231 I2C

Breadboard (Breadboard) and Cable (Jumper Wire)

For the ESP8266, I stood for several days before a seemingly insoluble problem, because the SPI interface indicated in the Pinout chart with MOSI at SD1, CS at CMD and SCLK at CLK just did not work. More on that later.


All the faster it went for the ESP32. Here is the pin assignment for the SPI interface:

 #define clk_pin 18// or sck
 #define data_pin 23 // or Mosi
 #define CS_PIN 2 // OR SS

And the connections for the RTC on the I2C interface:

// SDA to D21
// SCL to D22

From previous experiments I knew that the ESP32 does not know the variable LED_BUILTIN, so -  after the corresponding error message - I added the following line at the beginning of the sketch

 int LED_BUILTIN = 2;
The correct time was known by the (Battery buffered) Real Time Clock  from the previous trials, So I could upload the sketch with
 bool syncOnFirstStart = false; // synchronize true with PC, otherwise false

Only for synchronization with the time of the PC the variable must be set to true for a short time:

bool syncOnFirstStart = true

Construction with ESP32

Heureka. That was really quick.

Here the sketch for the ESP32 for Download


And now? Fix the problem with the ESP8266? Or first of all, download the time from a NTP server directly from the Internet?

I decided for the quick solution with an example sketch of the library Timelib.h. In the example-sketch Timentp_esp8266wifi.ino, I only needed insert my wireless SSID and password and the current time was displayed in the serial monitor.


The other problem had still not been solved by itself. Even to upload the sketch, I had to disconnect the plug connection CS to CMD, otherwise there was an error message when connecting. So Internet search for the SPI interface on the ESP8266. To my amazement, I saw an experimental setup with the analog-to-digital converter MCP3008, which I knew well from the Raspberry Pi. However, that was connected to the pins where in the Pinout diagram in front of the known abbreviations was an H, ie HSCLK = D5 = GPIO14, HMISO = D6 = GPIO12, HMOSI = D7 = GPIO13 and HCS = D8 = GPIO15. So I attached DIN, CS and CLK accordingly, adapted to the sketch, and behold: it worked.

ESP8266 Pinout

Construction with ESP8266

Here are the changes to the sketch of Mr. Küster:

 #define CS_PIN 15
 #define clock_pin 14
 #define mosi_pin 13
 #define miso_pin 12// not needed on display
 // SCL to D1 = GPIO5
 // SDA to D2 = GPIO4

And here the whole sketch to Download.

Synchronization with NTP server

The idea for using the WLAN-enabled Micro Controller came to me because one has to upload the sketch twice to synchronize the Real Time Clock with the system time of the computer, once bool syncOnFirstStart = true; once with bool syncOnFirstStart = false; For improvement and because the significantly better Real Time Clock DS3231 does not show the exact time after several weeks,  I wanted to combine the sketch of Mr. Küster with the big display with the example sketch for the NTP time.

Essentially, the sketch for the internet time is reduced only for the issue in the serial monitor and then inserted into the sketch of Mr. Küster. And then of course, the source for synchronization had to be changed. This happens in Line 159:

 RTC.adjust(Datetime(uint16_t(ye()), UINT8_T(montroy()), UINT8_T(day()), UINT8_T(hour()), UINT8_T(minute()), UINT8_T(second())));
 // OLD: RTC.ADJUST (DATETIME (F (__ Date__), F (__ Time__)));

This one Download of the sketch for the ESP8266 with time synchronization from the NTP server. Please note that you must enter your "WLAN credentials", ie SSID (name) and password in lines 35 and 36. And the switching between summer time and winter time is done by commenting in the lines 40 or 41.

Have fun with reconstruction. If you have a stable Internet connection and good Wi-Fi reception in the bedroom, then you can omit the RTC and synchronize the time more frequently with the NTP server.

DisplaysEsp-32Esp-8266Projects for advancedSmart home


Andreas Wolter

Andreas Wolter

Die Projekte in diesem Blog dienen auch zur Inspiration für Erweiterungen. Wie man lesen kann, hat Bernd Albrecht Sie inspiriert. Versuchen Sie es selbst einmal und lassen Sie uns wissen, ob es funktioniert hat. Die Idee klingt interessant.

Andreas Wolter

AZ-Delivery Blog

Steffen Mutter

Steffen Mutter

Das ist ja ein tolles Projekt, insbesondere NTP sync ist wirklich eine tolle Idee.
Um die ‘ultimative’ Uhr zu bauen, so Bernd Albrecht Zeit und Muße verspürt, wäre die Digitale Anzeige in der Mitte, aber der Doppelpunkt als extra LEDs, die im Sekundentakt blinken. (Module sind m.E. trennbar)
Rund um die digitale Anzeige einen Ring mit 3×60 LEDs, um die Stunden (ist nur eine LED an, die alle 12 Minuten um eine LED weiter springt), Minuten und Sekunden anzuzeigen.
Wäre sicher ziemlich aufwändig zu realisieren, würde sich aber als Uhr in (m)einer Firma sicher sehr gut machen, zumal die dank NTP (sync jede Stunde) und RTC (wenn jemand das WLAN getötet hat) sehr genau geht…

Ruediger Ebert

Ruediger Ebert

Da mir die Anzeige zu hell war, habe ich ein Potentiometer zur Helligkeitsregelung angeschlossen.
Wer dies auch realisieren möchte, nachfolgende eine kurze Anleitung:

Potentiometer Anschluss zwischen 3.3V und 0V. Abgriff an Analog-Input des ESP8266 anschliessen.
Wert des Potis: 10K

Im Definitionsteil des Sketches folgende Zeilen hinzufügen:
const int analogInPin = A0; // ESP8266 Analog Pin ADC0 = A0
int brightnessPotValue = 0;

Zum Loop folgende Zeilen hinzufügen:
brightnessPotValue = analogRead(analogInPin);
int c = map(brightnessPotValue, 0, 1023, 0, 15);
uhr.control(MD_MAX72XX::INTENSITY, c);


Ruediger Ebert

Ruediger Ebert

@ Bernd Albrecht: Danke :-)

Bernd Albrecht

Bernd Albrecht

@ Ruediger Ebert: Grundsätzlich ist die Internetzeit in Universal Time Coordinated (UTC) angegeben. Deshalb ist bei dem Sketch „Uhr_2_X_Anzeige_ESP8266_WLAN_NTP.ino“
in den Zeilen 38-41 die Korrektur für die jeweilige Zeitzone angegeben, zurzeit 2 Stunden für MESZ. Der Wert wird in der Variablen timeZone gespeichert. Die Korrektur wird in Zeile 98 addiert.
Schnellste Möglichkeit für die Anzeige in UTC:
Zeile 40 auskommentieren und eine weitere Zeile einfügen:
//const int timeZone = 2; // Central European Summer Time (MESZ)
const int timeZone = 0; // Universal Time Coordinated (UTC)

Nils Sappok

Nils Sappok

Vielen Dank für diesen – wie immer – exzellenten Beitrag!
Da möchte ich es gleich mal nach bauen….
Wie wäre es noch mit einer WS2812B 5050 RGB LED Matrix? Ich habe noch die 8×8 von Euch und zusätzlich gerade eines der flexiblen 8×32 Panels erhalten. Mit dem Uno läuft es problemlos, aber mit dem ESP32 NodeMCU habe ich es noch nicht geschafft. Obwohl es Beispiele im Netz ohne gibt, muss ich wohl einen Pegelwandler einsetzen.
Bleibt gesund! :)

Ruediger Ebert

Ruediger Ebert

Für ein Projekt benötige ich die Anzeige der Uhrzeit in UTC. Dies dies mit dem vorgestellten Projekt möglich?


Leave a comment

All comments are moderated before being published

Recommended blog posts

  1. Install ESP32 now from the board manager
  2. Lüftersteuerung Raspberry Pi
  3. Arduino IDE - Programmieren für Einsteiger - Teil 1
  4. ESP32 - das Multitalent
  5. OTA - Over the Air - ESP programming via WLAN