🛠 Serveur web embarqué : piloter la matrice depuis le navigateur
Objectives
Turn the board into a web server: the WiFiS3 library provides WiFiServer to listen on port 80, receive an HTTP request from a browser, and return an HTML page. You will control the LED matrix using simple GET links — the backbone of any embedded control interface.
Hardware
- 1 Arduino UNO R4 WiFi connected to the same network as the PC (see WiFi station tutorial)
- A browser on the same local network
- WiFi credentials in the sketch (never in a public repository).
Complete code
#include <WiFiS3.h>
#include "Arduino_LED_Matrix.h"
ArduinoLEDMatrix matrix;
WiFiServer server(80);
const char* SSID = "votre-reseau";
const char* PASS = "votre-cle";
void setup {
Serial.begin(115200);
WiFi.begin(SSID, PASS);
while (WiFi.status != WL_CONNECTED) { delay(200); }
Serial.print(F("Ouvrir http://")); Serial.println(WiFi.localIP);
matrix.begin;
server.begin;
}
void loop {
WiFiClient client = server.available;
if (!client) { return; }
String requete = "";
while (client.connected && !requete.endsWith("\r\n")) {
if (client.available) {
requete = client.readStringUntil('\r'); // 1re ligne = GET /chemin HTTP/1.1
break;
}
}
bool on = requete.indexOf("led=on") >= 0;
matrix.beginFrame;
for (uint8_t c = 0; c < 12; c++) matrix.setColumn(c, on ? B11111111 : 0);
matrix.show;
client.println(F("HTTP/1.1 200 OK"));
client.println(F("Content-Type: text/html"));
client.println(F("Connection: close"));
client.println;
client.println(F("<html><body style='font-family:sans-serif'>"));
client.println(on ? F("<h2>Matrice ALLUMEE</h2>") : F("<h2>Matrice ETEINTE</h2>"));
client.println(F("<a href='/led=on'><button>ON</button></a> "));
client.println(F("<a href='/led=off'><button>OFF</button></a>"));
client.println(F("</body></html>"));
client.stop; // indispensable, sinon le navigateur tourne en boucle
}
Expected verification
The Monitor displays a URL http://192.168.x.x ; opened in the browser, it shows two buttons. Clicking ON turns on all 96 LEDs, OFF turns them off. Each click generates a request visible if you display requete on the Monitor.
Common errors
- Forgetting
client.stop: the connection remains open, the browser reloads indefinitely, and the board becomes saturated. - Reading the entire request with a blocking
whileloop without a timeout: a client that does not close freezes the loop; hence reading only one line. - The browser also sends a request for /favicon.ico: your parser must ignore unknown paths (here, anything that is not led=on turns off — acceptable, but handle the case).
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
- Se connecter au WiFi et lire l'heure NTP (WiFiS3)
- Inclinomètre sur la matrice : l'IMU LSM6DSV16X en I²C
- Horloge persistante : RTC à pile + resynchronisation NTP
Code examples for this board
clignotante.inoArduinobouton-poussoir.inoArduinodac-analogique.inoArduinoentree-analogique.inoArduinopwm-respiration.inoArduinoservo-balayage.inoArduino