🛠 Se connecter au WiFi et lire l'heure NTP (WiFiS3)
Objectives
Leverage the board's second chip: the embedded ESP32-S3 acts as a WiFi (2.4 GHz only) and Bluetooth Low Energy modem, controlled from the RA4M1 via the official WiFiS3 library. You will connect to a WPA2 network, retrieve the time from an NTP server, and understand the "two brains" model: the RA4M1 runs your sketch, while the ESP32-S3 runs its own WiFi stack and communicates with the RA4M1 over UART.
Hardware
- 1 Arduino UNO R4 WiFi + USB-C cable
- A 2.4 GHz WiFi access point (not 5 GHz: the ESP32-S3 does not support it)
- Outgoing Internet access (NTP = UDP 123) for the clock step.
Full Code
#include <WiFiS3.h>
const char* SSID = "votre-reseau";
const char* PASS = "votre-cle";
void setup {
Serial.begin(115200);
while (!Serial && millis < 5000) { } // laisse le temps d'ouvrir le Moniteur
Serial.print(F("Connexion a ")); Serial.println(SSID);
WiFi.setTimeout(20000); // patience : 20 s max
int status = WiFi.begin(SSID, PASS);
if (status != WL_CONNECTED) {
Serial.print(F("Echec, code ")); Serial.println(status);
while (true) { } // en prod : réessayer, pas boucler
}
Serial.print(F("IP = ")); Serial.println(WiFi.localIP);
unsigned long epoch = WiFi.getTime; // requête NTP via l'ESP32-S3
Serial.print(F("Epoch NTP = ")); Serial.println(epoch);
}
void loop {
if (WiFi.status != WL_CONNECTED) {
Serial.println(F("WiFi perdu, reconnexion..."));
WiFi.disconnect;
WiFi.begin(SSID, PASS);
}
delay(1000);
}
Expected Verification
The Monitor displays a local IP address (192.168.x.x) followed by a consistent Unix timestamp (≈ 1.7–1.8 billion seconds). Unplug the WiFi router: WiFi.status goes offline and the reconnection loop takes over.
Common Errors
- 5 GHz network: connection fails systematically — the ESP32-S3 is strictly 2.4 GHz.
- Special characters or accents in the password entered in the sketch: escaping and encoding can cause issues; test with a simple key first.
- Calling
WiFi.beginwithout a timeout followed by code that proceeds too quickly: useWiFi.setTimeoutand check the return code. - Having reflashed the ESP32-S3 with custom firmware: the WiFiS3 modem is no longer present — you must reflash the original firmware (official tutorial "custom firmware ESP32-S3", see advanced tutorial).
- Confusing the two chips in the logs: a
statusthat never changes often signals a problem with the RA4M1↔ESP32-S3 UART link, not your network.
Other tutorials for this board
- Premier Blink sur la UNO R4 WiFi : la première UNO 32 bits
- Apprivoiser la matrice LED 12x8 intégrée
- Toucher capacitif : touchRead sans composant
- Inclinomètre sur la matrice : l'IMU LSM6DSV16X en I²C
- Serveur web embarqué : piloter la matrice depuis le navigateur
- Horloge persistante : RTC à pile + resynchronisation NTP
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino