🛠 Serveur web embarqué : l'Ethernet natif 10/100 du Teensy 4.1 (DP83825)

Teensy 4.1 · intermediaire · Schéma : le Teensy 4.1 avec son PHY TI DP83825I embarqué et le connecteur RJ45 magnétique (kit à souder) branché à ses pieds ; flèches vers le câble Ethernet et le navigateur d'un PC sur le réseau local.

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

Key points

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

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials