ESP32-Controlled Dual 8x8 LED Matrix Display with NTP Time Synchronization
View and Edit Project In Cirkit Designer
Circuit Documentation
Summary
This circuit primarily consists of an ESP32 microcontroller, two 8x8 LED matrix displays, two 3.3V batteries, and a single red LED. The ESP32 is responsible for controlling the LED matrices and managing the WiFi connection for time synchronization. The matrices are used to display information, likely numerical data given the font data provided in the code. The red LED serves as a simple indicator or status light. Power is supplied to the circuit through the 3.3V batteries.
Component List
ESP32 (30 pin)
- Description: A microcontroller with WiFi capabilities.
- Pins: EN, VP, VN, D34, D35, D32, D33, D25, D26, D27, D14, D12, D13, GND, Vin, D23, D22, TX0, RX0, D21, D19, D18, D5, TX2, RX2, D4, D2, D15, 3V3
8x8 Matrix Display
- Description: An 8x8 LED matrix display for showing data.
- Pins: vcc, DIN, clk, CS, Gnd, gnd, CLK
3.3V Battery
- Description: A power source for the circuit.
- Pins: +, -
LED: Two Pin (red)
- Description: A simple red LED.
- Pins: cathode, anode
Wiring Details
ESP32 (30 pin)
- GND connected to 3.3V battery (-) and 8x8 matrix (Gnd)
- Vin connected to 3.3V battery (+) and 8x8 matrix (vcc)
- D19 connected to 8x8 matrix (DIN)
- D18 connected to 8x8 matrix (clk)
- D5 connected to 8x8 matrix (CS)
8x8 Matrix Display
- vcc connected to 3.3V battery (+) and another 8x8 matrix (vcc)
- Gnd connected to 3.3V battery (-) and another 8x8 matrix (gnd)
- DIN connected to ESP32 (D19) and another 8x8 matrix (DIN)
- clk connected to ESP32 (D18) and another 8x8 matrix (CLK)
- CS connected to ESP32 (D5) and another 8x8 matrix (CS)
3.3V Battery
- (+) connected to ESP32 (Vin), 8x8 matrix (vcc), and LED (anode)
- (-) connected to ESP32 (GND), 8x8 matrix (Gnd), and LED (cathode)
LED: Two Pin (red)
- anode connected to 3.3V battery (+)
- cathode connected to 3.3V battery (-)
Documented Code
Main Sketch (sketch.ino)
// Header file includes
#include <WiFi.h>
#include <time.h>
#include <MD_Parola.h>
#include <SPI.h>
#include "Font_Data.h"
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 18 // or SCK
#define DATA_PIN 19 // or MOSI
#define CS_PIN 5 // or SS
// Arbitrary output pins
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define SPEED_TIME 75
#define PAUSE_TIME 0
#define MAX_MESG 20
/********** User Config Setting ******************************/
char* ssid = "hidden";
char* password = "malhar@021";
//calculate your timezone in seconds,1 hour = 3600 seconds and 5.30Hrs = 19800
const int timezoneinSeconds = 19800;
/***************************************************************/
int dst = 0;
uint16_t h, m, s;
uint8_t dow;
int day;
uint8_t month;
String year;
// Global variables
char szTime[9]; // mm:ss\0
char szsecond[4]; // ss
char szMesg[MAX_MESG+1] = "";
void getsec(char *psz)
{
sprintf(psz, "%02d", s);
}
void getTime(char *psz, bool f = true)
{
time_t now = time(nullptr);
struct tm* p_tm = localtime(&now);
h = p_tm->tm_hour;
m = p_tm->tm_min;
s = p_tm->tm_sec;
sprintf(psz, "%02d%c%02d", h, (f ? ':' : ' '), m);
Serial.println(psz);
}
void setup(void)
{
Serial.begin(115200);
delay(10);
Serial.println();
Serial.println();
Serial.print("Connecting to ");
Serial.println(ssid);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(3000);
WiFi.mode(WIFI_STA);
getTimentp();
P.begin(3);
P.setInvert(false);
P.setZone(0, 0, 0);
P.setZone(1, 1, 3);
P.setFont(0, numeric7Seg);
P.setFont(1, numeric7Se);
P.displayZoneText(0, szsecond, PA_LEFT, SPEED_TIME, 0, PA_PRINT, PA_NO_EFFECT);
P.displayZoneText(1, szTime, PA_CENTER, SPEED_TIME, PAUSE_TIME, PA_PRINT, PA_NO_EFFECT);
getTime(szTime);
}
void loop(void)
{
static uint32_t lastTime = 0; // millis() memory
static uint8_t display = 0; // current display mode
static bool flasher = false; // seconds passing flasher
P.displayAnimate();
if (millis() - lastTime >= 1000)
{
lastTime = millis();
getsec(szsecond);
getTime(szTime, flasher);
flasher = !flasher;
P.displayReset(0);
P.displayReset(1);
}
}
void getTimentp()
{
configTime(timezoneinSeconds, dst, "pool.ntp.org","time.nist.gov");
while(!time(nullptr)){
delay(500);
Serial.print(".");
}
Serial.print("Time Update");
}
Font Data (Font_Data.h)
// Data file for user example user defined fonts
#ifndef FONTDATA_H
#define FONTDATA_H
MD_MAX72XX::fontType_t numeric7Seg[] PROGMEM =
{
// Font data omitted for brevity
};
MD_MAX72XX::fontType_t numeric7Se[] PROGMEM =
{
// Font data omitted for brevity
};
#endif
Note: The font data arrays numeric7Seg and numeric7Se have been omitted for brevity. These arrays define custom characters for the LED matrix displays, mapping binary patterns to ASCII characters.