Clock with ESP32 and led matrix

This experiment displays the current time using ESP32 module and a led matrix.

In this sketch, the ESP32 module reads current time using NTP protocol. The current time is displayed on led matrix driven by MAX7219. The led matrix is build using 4 dot matrix modules (8x8) chained togheter to form a display with 32x8 pixels.

The display is controlled via the ESP32 led matrix library, optimized for high density characters (5x7 font).



Hardware set-up

Following hardware is required to build the experiment:
  • ESP32 module (e.g. ESPDUINO-32)
  • 4 dot matrix modules with MAX7219
Implement following connections:
  • Connect 5V(ESP32) together with MAX7219.VCC
  • Connect GND(ESP32) together with MAX7219.GND
  • Connect GPIO19(ESP32) together with MAX7219.DIN
  • Connect GPIO5(ESP32) together with MAX7219.CS
  • Connect GPIO18(ESP32) together with MAX7219.CLK
The following picture shows the Clock breadboard:

ESP32 Clock breadboard

ESP32 software

Before writing software make sure to have installed the software development environment, downloadable from Arduino Software web site. It may be needed to download some library if not already present. Libraries are required also to manage the external devices.

The sketch has to include the required libraries:

#include <SPI.h>
#include "LedMatrix.h"
#include <WiFi.h>
#include "time.h"


The loop() function implements the Clock functionality.

void loop(){ delay(1000); printLocalTime(); } void printLocalTime(){ ledMatrix.clear(); struct tm timeinfo; if(!getLocalTime(&timeinfo)){ Serial.println("Failed to obtain time"); if (first) { ledMatrix.setText("--:--"); ledMatrix.drawText(); //use either commit() or commith() depending on your led matrix orientation ledMatrix.commith(); } return; } // Serial.println(&timeinfo, "%H:%M:%S"); int seconds = timeinfo.tm_sec; char formattedTime[10]; strftime(formattedTime, 10, (seconds & 1) == 1 ? "%H:%M" : "%H %M", &timeinfo); Serial.println(formattedTime); first = false; ledMatrix.setText(String(formattedTime)); ledMatrix.drawText(); //use either commit() or commith() depending on your led matrix orientation ledMatrix.commith(); }


Download the complete sketch here and enjoy it.

Share Share on Facebook Share on Twitter Bookmark on Reddit Share via mail
Creative Commons Attribution-Share Alike | Terms and conditions | Privacy policy