
#include <M5Unified.h> void setup() { M5.begin(); M5.Display.fillScreen(WHITE); M5.Display.setTextFont(&fonts::FreeMono12pt7b); M5.Display.setTextColor(BLACK); M5.Display.setCursor(0, 0); Serial.begin(115200); Serial2.begin(115200, SERIAL_8N1, 1, 13); } ```cpp void loop() { M5.Display.setCursor(0, 0); M5.Display.printf("M5Stack LAN PoE\n"); if (Serial.available()) { // If the serial port receives a message int ch = Serial.read(); // Read the message Serial2.write(ch); M5.Display.fillCircle(100, 65, 15, GREEN); // Set the light to green } else M5.Display.fillCircle(100, 65, 15, WHITE); Serial2.write('a'); delay(50); if (Serial2.available()) { // If the serial port receives a message int ch = Serial2.read(); // Read the message Serial.write(ch); M5.Display.fillCircle(100, 65, 15, GREEN); delay(50); } else M5.Display.fillCircle(100, 65, 15, WHITE); }#include <M5Unified.h> #include <SPI.h> #include <M5_Ethernet.h> #define SCK 36 #define MISO 35 #define MOSI 37 #define CS 9 // 01 05 00 01 02 00 9d 6a char uart_buffer[8] = {0x01, 0x05, 0x00, 0x01, 0x02, 0x00, 0x9d, 0x6a}; char uart_rx_buffer[8] = {0}; char Num = 0; char stringnum = 0; unsigned long W5500DataNum = 0; unsigned long Send_Num_Ok = 0; unsigned long Rec_Num = 0; unsigned long Rec_Num_Ok = 0; // Enter a MAC address and IP address for your controller below. // The IP address will be dependent on your local network: byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED}; IPAddress ip(192, 168, 1, 177); // Initialize the Ethernet server library // with the IP address and port you want to use // (port 80 is default for HTTP): EthernetServer server(80); void setup() { // Open serial communications and wait for port to open: M5.begin(); Serial.begin(115200); SPI.begin(SCK, MISO, MOSI, -1); Ethernet.init(CS); // start the Ethernet connection and the server: Ethernet.begin(mac, ip); server.begin(); Serial.print("server is at "); Serial.println(Ethernet.localIP()); M5.Display.fillScreen(WHITE); M5.Display.setTextFont(&fonts::FreeMonoBold12pt7b); M5.Display.setTextColor(BLACK); M5.Display.setCursor(0, 0); M5.Display.println("M5Stack W5500 Test"); M5.Display.print(Ethernet.localIP()); } void loop() { // listen for incoming clients EthernetClient client = server.available(); if (client) { Serial.println("new client"); // an http request ends with a blank line boolean currentLineIsBlank = true; while (client.connected()) { if (client.available()) { char c = client.read(); Serial.write(c); // if you've gotten to the end of the line (received a newline // character) and the line is blank, the http request has ended, // so you can send a reply if (c == '\n' && currentLineIsBlank) { // send a standard http response header client.println("HTTP/1.1 200 OK"); client.println("Content-Type: text/html"); client.println("Connection: close"); // the connection will be closed // after completion of the // response client.println("Refresh: 5"); // refresh the page // automatically every 5 sec client.println(); client.println("<!DOCTYPE HTML>"); client.println("<html>"); client.println("<body>"); client.println("<h1>M5Stack W5500 Test</h1>"); client.println("<br />"); client.println("<p>Please click here</p>"); client.println("<a href=\"http://www.M5Stack.com\">M5Stack</a>"); client.println("<br />"); client.println("<br />"); client.println("<br />"); client.print("W5500 Counter Num :"); client.print(W5500DataNum); client.println("<br />"); client.println("<br />"); W5500DataNum++; client.print("Rec_Num_Ok Counter :"); client.print(Rec_Num_Ok); client.println("<br />"); client.println("<br />"); client.print("Rec_Num Counter :"); client.print(Rec_Num); client.println("<br />"); client.println("<br />"); client.println("</body>"); client.println("</html>"); break; } if (c == '\n') { // you're starting a new line currentLineIsBlank = true; } else if (c != '\r') { // you've gotten a character on the current line currentLineIsBlank = false; } } } // give the web browser time to receive the data delay(1); // close the connection: client.stop(); Serial.println("client disconnected"); } }Download Mode: Different devices require entering download mode before programming. This process may vary depending on the main controller. For details, please refer to the device programming tutorial list at the bottom of the Arduino IDE Getting Started Guide page.
For CoreS3: Press and hold the reset button (about 2 seconds) until the internal green LED lights up, then release. The device will enter download mode and wait for programming.
192.168.1.177 with subnet mask 255.255.255.0.192.168.1.x (where x is 2~254 and ≠177), subnet mask 255.255.255.0, default gateway can be left blank.ping 192.168.1.177.http://192.168.1.177 in PC browser to access the built-in web server.