🛠 Serveur web embarqué : l'Ethernet natif 10/100 du Teensy 4.1 (DP83825)
Objectives
The Teensy 4.1 integrates an Ethernet 10/100 Mbit controller with DMA and an on-board TI DP83825I PHY: only the RJ45 connector with magnetics is missing, sold as a solder kit. This tutorial sets up an HTTP server that exposes the board's measurements to the local network — no shield, no SPI, no chip-select.
Hardware
- 1 Teensy 4.1 (the TEENSY41_NE variant does NOT have an Ethernet chip: check your reference)
- 1 RJ45 connector kit: https://www.pjrc.com/store/ethernet_kit.html (fine soldering)
- Ethernet cable, DHCP router
Key points
- Since the PHY is internal, no
Ethernet.init(cs)is needed:Ethernet.begin(mac)is sufficient. - The official Ethernet library (WebServer, ChatServer, SMTP...) runs as-is on the 4.1.
Ethernet.hardwareStatusdetects the absence of hardware — essential to distinguish an NE variant from an unplugged cable.Ethernet.maintainrenews the DHCP lease: call it in the loop.- 10/100 only, no gigabit: for telemetry and lightweight APIs, this is more than enough.
Complete code
#include <Ethernet.h>
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; // MAC unique !
EthernetServer server(80);
void setup {
Serial.begin(9600);
Ethernet.begin(mac); // DHCP ; (mac, ip) pour statique
if (Ethernet.hardwareStatus == EthernetNoHardware) {
Serial.println("Pas de materiel Ethernet (variant -NE ?)");
while (true) delay(1);
}
server.begin;
Serial.print("serveur a ");
Serial.println(Ethernet.localIP);
}
void loop {
Ethernet.maintain;
EthernetClient client = server.available;
if (!client) return;
bool lineDone = false;
while (client.connected && !lineDone) {
if (client.available) {
char c = client.read;
if (c == '\n') lineDone = true; // fin des en-tetes HTTP
}
}
client.println("HTTP/1.1 200 OK");
client.println("Content-Type: text/html");
client.println("Connection: close");
client.println;
client.println("<html>A0 = ");
client.print(analogRead(14));
client.println("</html>");
client.stop;
}
Expected verification
The IP address assigned by DHCP is displayed on the serial port; typing it into a browser displays a page showing the value of A0, refreshed on each reload.
Common errors
- Forgetting to solder the RJ45 kit (or accidentally buying the NE variant):
hardwareStatusreturnsEthernetNoHardware. - Cloning the example without changing the MAC address: two machines with the same MAC cause phantom network failures.
- Not calling
Ethernet.maintain: the DHCP lease expires and the server becomes unreachable after a few hours. - Alternatives if you don't have the kit: a W5500/Wiz820 shield on SPI works on all Teensy models — less elegant, but no soldering required.
Other tutorials for this board
- Premiers pas sur le Teensy 4.1 : Teensyduino, Teensy Loader et premier Blink
- GPIO et PWM sur le Teensy 4.1 : 55 broches en 3,3 V, ni 5 V tolérées ni traîne
- Entrées analogiques du Teensy 4.1 : 18 broches, 2 ADC, 0-3,3 V fixes et zéro DAC
- Logger sur carte SD via le port SDIO natif du Teensy 4.1
- Boîte à rythmes USB MIDI : classes MIDI, MIDIx16 et port hôte USBHost_t36
- Ingénierie mémoire du Teensy 4.1 : TCM, DMAMEM, EXTMEM, flash QSPI et EEPROM
Code examples for this board
clignotante.inoArduinotouche-capacitive.inoArduinoanalogique-12-bits.inoArduinomidi-piano.inoArduinopwm-respiration.inoArduinoservo-angle.inoArduino