Code de recherche

Projet d'horloge de base ESP32-S3 Matrice LED RGB Wi-Fi + Horloge NTP - 1

Projet d'horloge de base ESP32-S3 Matrice LED RGB Wi-Fi + Horloge NTP - 1

Horloge Internet ESP32-S3 avec NeoMatrix 8×8 (Wi-Fi + Heure NTP)

Ce projet transforme un ESP32-S3 et une matrice LED RGB NeoMatrix 8×8 (NeoPixel/WS2812) en une petite horloge Internet. L'ESP32 se connecte au Wi-Fi, synchronise l'heure locale à partir d'un serveur NTP, puis défile l'heure commeHH:MMà travers l'affichage 8×8.

ESP32-s3_animation_heure_internet

Comment cela fonctionne (niveau élevé)

1) ESP32-S3 se connecte à votre routeur en utilisant<WiFi.h>.
2) Il synchronise l'heure à partir d'un serveur NTP en utilisant"time.h"etconfigTime().
3) Le temps est formaté commeHH:MMet enregistré dans un petit tampon de texte.
4) Le NeoMatrix affiche le texte et le fait défiler sur le panneau 8×8.

Couleur RVB

La couleur du texte de l'horloge est contrôlée à l'aide de valeurs RVB (Rouge, Vert, Bleu), où chaque canal de couleur varie de 0 à 255 et différentes combinaisons créent des couleurs différentes sur le NeoMatrix. En ajustant lecolor_RED,color_GREEN, etcolor_BLUEvariables, vous pouvez facilement personnaliser l'apparence de l'horloge dans la couleur de votre choix. Pour trouver rapidement les valeurs RGB exactes d'une couleur spécifique, vous pouvez utiliser le sélecteur de couleurs RGB en ligne.Sélecteur de couleurs.

Bibliothèques utilisées

Ceci inclut exactement ce dont le croquis dépend :

#include <WiFi.h>
#include "time.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

InstallerAdafruit NeoMatrixutilisant le gestionnaire de bibliothèques Arduino. Il va également télécharger les dépendances requises telles queAdafruit GFX LibraryetAdafruit NeoPixel.

Paramètres utilisateur importants que VOUS DEVEZ modifier

1) Couleur du texte (RGB)

Réglez la couleur du texte de votre horloge en utilisant des valeurs de 0 à 255 :

//set the color of display made of Red, Green and Blue 
unsigned int color_RED = 17;
unsigned int color_GREEN = 43;
unsigned int color_BLUE = 171;

Ces valeurs sont utilisées ici :

matrix.setTextColor(matrix.Color(color_RED, color_GREEN, color_BLUE));

Remarque :Si vous réglez toutes les couleurs sur 0 (noir), le texte devient invisible. Le croquis comprend une vérification de sécurité :

// if user set all colors to 0, the display will be turned off so set it green
if (color_RED == 0 && color_GREEN == 0 && color_BLUE == 0) {
  color_GREEN = 200;
}

Cela garantit que la matrice n'a jamais l'air "morte" en raison d'un paramètre de couleur invisible.

2) SSID Wi-Fi et mot de passe

Remplacez-les par votre vrai nom de Wi-Fi et votre mot de passe :

const char* WIFI_SSID     = "WiFi";
const char* WIFI_PASSWORD = "passW0rd";

Lors du démarrage, l'ESP32 affiche la progression de la connexion dans le Moniteur Série et se bloque après environ 15 secondes (30 tentatives × 500 ms).

3) Serveur NTP

Le serveur NTP par défaut est :

const char* ntpServer = "pool.ntp.org";

Vous pouvez le garder tel quel. Si vous souhaitez utiliser un serveur local, remplacez le nom d'hôte par votre serveur NTP préféré.

4) Décalage horaire et décalage pour l'heure d'été

Ces deux paramètres contrôlent l'heure locale :

// Toronto-ish: UTC-5, plus 1 hour DST
const long  gmtOffset_sec      = -5 * 3600;  // -5 hours
const int   daylightOffset_sec = 3600;       // +1 hour for DST

Comment les définir :

  • gmtOffset_sec= (décalage horaire UTC en heures) × 3600. Exemple : UTC-5 →-5*3600, UTC+2 →2*3600.
  • daylightOffset_sec=0si vous ne souhaitez pas l'ajustement de l'heure d'été, ou3600si votre région observe actuellement l'heure d'été (+1 heure).

Ceux-ci sont appliqués ici :

configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);

Configuration de l'affichage

Donnée de broche de matrice

Le broche de données est définie ici :

#define MATRIX_PIN 14

Si votre câblage utilise un GPIO différent, changez ce numéro pour qu'il corresponde.

Mise en page NeoMatrix + ordre des couleurs

Votre matrice est initialisée comme ceci :

Adafruit_NeoMatrix matrix(8, 8, MATRIX_PIN,
  NEO_MATRIX_TOP    + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS   + NEO_MATRIX_PROGRESSIVE,
  NEO_RGB           + NEO_KHZ800);

Deux raisons courantes pour lesquelles l'affichage semble "erroné" :

  • Direction de rotation / de câblage :Si le texte apparaît à l'envers ou en miroir, ajustez leNEO_MATRIX_*drapeaux (HAUT/BAS, GAUCHE/DROITE, LIGNES/COLONNES, PROGRESSIF/ZIGZAG).
  • Commande de couleur :Ce code utiliseNEO_RGB. Certains panneaux sontNEO_GRBSi le rouge/le vert/le bleu ne correspondent pas, changez.NEO_RGBà l'ordre correct.

Luminosité

La luminosité est réglée àinitMatrix():

matrix.setBrightness(40);

Augmentez pour un affichage plus lumineux, réduisez pour abaisser la chaleur et la consommation d'énergie.

Comment le temps est généré en tant queHH:MM

L'horloge stocke l'heure formatée dans un tampon de 6 caractères :

char timeText[6] = "00:00";

AlorsupdateTimeText()lit l'heure locale synchronisée NTP et écrit le texte :

// Format HH:MM
snprintf(timeText, sizeof(timeText), "%02d:%02d",
         timeinfo.tm_hour,
         timeinfo.tm_min);

Cela est mis à jour une fois par seconde dans la boucle principale.

Comment le défilement fonctionne sur un affichage 8×8

Une matrice 8×8 est trop étroite pour être affichée.HH:MMà la fois, donc le croquis défile le texte. Il dessine le temps à une position X changeante (scrollX), puis le déplace vers la gauche d'un pixel à chaque mise à jour.

int16_t scrollX = 8;
const uint16_t scrollIntervalMs = 120;

Chaque étape de défilement :

matrix.fillScreen(0);
matrix.setCursor(scrollX, 0);
matrix.print(timeText);
matrix.show();
scrollX--;

Lorsque le texte sort complètement du côté gauche, le code le réinitialise pour recommencer depuis le bord droit :

int16_t textWidth = 30;
if (scrollX < -textWidth) {
  scrollX = matrix.width();
}

Sortie du moniteur série (débogage)

Ce croquis imprime des messages utiles :

  • Progression de la connexion Wi-Fi et adresse IP
  • Que la synchronisation de l'heure ait réussi
  • La chaîne de temps formatée (par exemple,Time text: 14:32)

Si l'écran est vide, le Moniteur Série est le premier endroit à vérifier pour confirmer que le Wi-Fi et le NTP fonctionnent.

Démonstration de projet

Après le téléchargement et la réinitialisation :

  • L'ESP32 se connecte au Wi-Fi
  • Synchronise l'heure depuispool.ntp.org
  • SpectaclesOKbrièvement sur la matrice
  • Fait défiler en continu l'heure actuelle alors queHH:MM

Téléchargements et liens

Le code complet est fourni ci-dessous cet article. Les pièces, outils et fiches techniques sont également liés ci-dessous cet article.

Images

ESP32 S3 Matrix
ESP32 S3 Matrix
ESP32 S3 Matrix  pin out
ESP32 S3 Matrix pin out
ESP32-S3_RGB_8x8_matrix-3
ESP32-S3_RGB_8x8_matrix-3
ESP32-S3_RGB_8x8_matrix1
ESP32-S3_RGB_8x8_matrix1
ESP32-S3_RGB_8x8_matrix-2
ESP32-S3_RGB_8x8_matrix-2
ESP32-s3_internet_clock_animation
ESP32-s3_internet_clock_animation
868-ESP32-S3 RGB LED Matrix Internte Clock Project 1 - Basic Clock
Langue: C++
/*
This is ESP32 sketch that connects to the internet, gets the time and displays it on the RGB matrix
you must set your WiFi correctly to make sure it gets connected. 
 watch video https://youtube.com/shorts/4iWjLiD7fS8
 📚⬇️ Download and resource page https://robojax.com/RJT838
 * Author:  Ahmad Shamshiri (Robojax.com)
 * Date: 07 Jan 2026
www.Robojax.com
https://youTube.com/@robojax


*/
#include <WiFi.h>
#include "time.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>

//set the color of diplay make of Red, Green and Blue 
unsigned int color_RED = 17;
unsigned int color_GREEN = 43;
unsigned int color_BLUE = 171;

// 👇 REPLACE these with your real home WiFi name & password
const char* WIFI_SSID     = "WiFi";
const char* WIFI_PASSWORD = "passW0rd";



#define MATRIX_PIN 14

Adafruit_NeoMatrix matrix(8, 8, MATRIX_PIN,
  NEO_MATRIX_TOP    + NEO_MATRIX_LEFT +
  NEO_MATRIX_ROWS   + NEO_MATRIX_PROGRESSIVE,
  NEO_RGB           + NEO_KHZ800);

char timeText[6] = "00:00";
int16_t scrollX = 8;
unsigned long lastScrollMs = 0;
const uint16_t scrollIntervalMs = 120;

unsigned long lastTimeUpdateMs = 0;
const uint16_t timeUpdateIntervalMs = 1000;

//prototypes
bool updateTimeText();  // forward declaration
void scrollTime();      // forward declaration



// NTP (time) server
const char* ntpServer = "pool.ntp.org";

// Toronto-ish: UTC-5, plus 1 hour DST
const long  gmtOffset_sec     = -5 * 3600;  // -5 hours
const int   daylightOffset_sec = 3600;      // +1 hour for DST



bool updateTimeText() {
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time for display");
    return false;
  }

  // Format HH:MM
  snprintf(timeText, sizeof(timeText), "%02d:%02d",
           timeinfo.tm_hour,
           timeinfo.tm_min);

  Serial.print("Time text: ");
  Serial.println(timeText);
  return true;
}

void scrollTime() {
  matrix.fillScreen(0);
  matrix.setCursor(scrollX, 0);
  matrix.print(timeText);
  matrix.show();

  scrollX--;

  // Rough width: 5 characters ("HH:MM") × 6 pixels each ≈ 30 px
  int16_t textWidth = 30;
  if (scrollX < -textWidth) {
    scrollX = matrix.width();  // reset to right edge (8)
  }
}


void initMatrix() {
  matrix.begin();
  matrix.setBrightness(40);        // be careful with heat
  matrix.setTextWrap(false);
  matrix.setTextColor(matrix.Color(color_RED, color_GREEN, color_BLUE)); // color of text
}

void showMessage(const char* msg) {
  matrix.fillScreen(0);
  matrix.setCursor(0, 0);  // top-left
  matrix.print(msg);
  matrix.show();
}


void printLocalTime() {
  struct tm timeinfo;
  if (!getLocalTime(&timeinfo)) {
    Serial.println("Failed to obtain time");
    return;
  }
  // Format: 2025-11-18 14:35:12
  Serial.printf("%04d-%02d-%02d %02d:%02d:%02d\n",
                timeinfo.tm_year + 1900,
                timeinfo.tm_mon + 1,
                timeinfo.tm_mday,
                timeinfo.tm_hour,
                timeinfo.tm_min,
                timeinfo.tm_sec);
}

void setup() {
  Serial.begin(115200);
  delay(1000);
  Serial.println();
  Serial.println("ESP32-S3 Internet Clock - WiFi + NTP test");

  // Connect to WiFi
  Serial.print("Connecting to WiFi: ");
  Serial.println(WIFI_SSID);
  WiFi.mode(WIFI_STA);
  WiFi.begin(WIFI_SSID, WIFI_PASSWORD);

  int retries = 0;
  while (WiFi.status() != WL_CONNECTED && retries < 30) { // ~15s timeout
    delay(500);
    Serial.print(".");
    retries++;
  }
  Serial.println();

  if (WiFi.status() != WL_CONNECTED) {
    Serial.println("WiFi connection FAILED");
  } else {
    Serial.print("WiFi connected. IP: ");
    Serial.println(WiFi.localIP());
  }

// if user set all colors to 0, the dispaly will be turned off so set it green
  if(color_RED ==0 & color_GREEN ==0 && color_BLUE ==0)
  {
    color_GREEN = 200;
  }

  // Configure time via NTP
  configTime(gmtOffset_sec, daylightOffset_sec, ntpServer);
  Serial.println("Waiting for time...");
  delay(2000); // small wait for initial sync

  printLocalTime(); // print once at startup

    // NEW: init the LED matrix and show a test message
  initMatrix();
  showMessage("OK");
}

void loop() {
  unsigned long now = millis();

  // Update the time string "HH:MM" once per second
  if (now - lastTimeUpdateMs >= timeUpdateIntervalMs) {
    lastTimeUpdateMs = now;
    updateTimeText();  // fills timeText[], e.g. "14:32"
  }

  // Scroll the time across the 8×8 every scrollIntervalMs
  if (now - lastScrollMs >= scrollIntervalMs) {
    lastScrollMs = now;
    scrollTime();      // uses timeText and scrollX
  }
}

Ce dont vous pourriez avoir besoin

Fichiers📁

Fichier Fritzing