Skip to main content

ESP32-S3-POE-ETH-8DI-8DO Working with Arduino

This chapter includes the following sections. Please read as needed:

Arduino Getting Started​

New to Arduino ESP32 development and looking for a quick start? We have prepared a comprehensive Getting Started Tutorial for you.

Note: This tutorial uses the ESP32-S3-Zero as a reference example, and all hardware code is based on its pinout. Before you start, we recommend checking the pinout of your development board to ensure the pin configuration is correct.

Setting Up the Development Environment​

1. Install and Configure the Arduino IDE​

Please refer to the tutorial Install and Configure Arduino IDE to download and install the Arduino IDE and add ESP32 support. ESP32-S3-POE-ETH-8DI-8DO required development board installation description

Board NameInstallation RequirementVersion Requirement
esp32 by Espressif SystemsOffline installation / Online installation3.0.0 or later

Install Libraries​

  • When installing Arduino libraries, there are typically two options: Online Installation and Offline Installation. ** If the library installation requires offline installation, you must use the provided library files.**
  • For most libraries, users can easily search for and install them via the Arduino IDE's online Library Manager. However, some open-source or custom libraries are not synchronized to the Arduino Library Manager, so they cannot be found through online search. In this case, you can only install these libraries manually offline.
  • For a library installation tutorial, see the library installation section in the Install and Configure Arduino IDE.
  • The ESP32-S3-POE-ETH-8DI-8DO library files are stored in the example program. Click here to go to: ESP32-S3-POE-ETH-8DI-8DO Example Programs.

Library installation instructions for ESP32-S3-POE-ETH-8DI-8DO

Library NameDescriptionVersionLibrary Installation Requirement
ArduinoJsonLightweight JSON libraryv6.21.4Online or offline installation
PubSubClientMQTT message publish/subscribe libraryv2.8.0Online or offline installation
NTPClientNetwork time synchronization client libraryv3.2.1Online or offline installation
info

For more LVGL learning and usage, refer to the LVGL Official Documentation.

Example​

Demo-flow-01

ESP32-S3-POE-ETH-8DI-8DO Example

ExampleBasic DescriptionDependency Library
01_MAIN_WIFI_APRS485 interface control, Bluetooth control, Bluetooth IP transmission, Web page control (short range)Can be flashed directly. The Web page can only be used when connected to the device's Wi-Fi
02_MAIN_WIFI_STARS485 interface control, Bluetooth control, Bluetooth IP transmission, Web page control (short range)Requires modifying the Wi-Fi to connect to. The Web page is for intranet use only
03_MAIN_ALLRS485 interface control, Bluetooth control, Bluetooth IP transmission, Web page control (short range), Waveshare Cloud control (long range)Requires modifying the Wi-Fi to connect to. A device must be created in Waveshare Cloud. The Web page is for intranet use only. (Note: Waveshare Cloud is no longer maintained. Please choose another cloud service.)

Arduino Project Settings​

ESP32-S3-16MB-OPI-Parameters

01_MAIN_WIFI_AP​

Example Description

  • This example implements controlling the switches of 8 digital outputs via Wi-Fi, Bluetooth, Ethernet, and RS485. This example enables the Wi-Fi AP mode.

Notes

  • Can be flashed directly.
  • The Web page can only be used when connected to the device's Wi-Fi, or, when a network cable is connected, by accessing the Ethernet port IP on the local network.

Code Analysis

  • Relay_Analysis(): This function is mainly used to analyze the received data and, based on the data content, execute the corresponding digital output control operations and output the corresponding status prompt information.

    • Parameter Analysis
      • uint8_t *buf: A pointer to an unsigned 8-bit integer array. This array should store the received data. The function determines the specific command content based on the value of the first element of the array (buf[0]).
      • uint8_t Mode_Flag: A mode flag indicating the data source. By checking this flag, it outputs the corresponding data source prompt information (such as Bluetooth data, Wi-Fi data, or RS485 data), and performs different digital output operations according to different commands.
    • Logic Flow
      • First, output the corresponding data source prompt information based on the value of Mode_Flag.
      • Then, use a switch statement to execute different operations based on the value of buf[0]:
        • For cases CH1 to CH8, use the digitalToggle function to toggle the level state of the corresponding EXIO pin (such as GPIO_PIN_CH1, etc.), update the corresponding Relay_Flag array element to record the change in digital output state, call the Buzzer_PWM function to control the buzzer, and output the corresponding on or off prompt information based on the final digital output state.
        • For the ALL_ON command, set all GPIO pins (corresponding to the 8-channel digital outputs) to high level (on state), use the memset function to set all elements of the Relay_Flag array to 1, indicating that all digital outputs are on, output a prompt that all digital outputs are on, and control the buzzer.
        • For the ALL_OFF command, similarly set all relevant GPIO pins to low level (off state), update the Relay_Flag array elements to 0, output a prompt that all digital outputs are off, and control the buzzer, with two additional buzzer control operations (with a delay in between).
        • If the value of buf[0] does not match the above command cases, output a prompt indicating that non-command data was received.
  • WIFI_Init (): Configures the device as a Wi-Fi access point (AP), sets up a Web server, and sets request handler functions for different paths, implementing relevant network functions and device control functions, while providing corresponding status prompts.

    • AP Creation
      • First set the Wi-Fi mode to WIFI_AP, then attempt to create a soft AP via WiFi.softAP(ssid, password). If it fails, it will loop with a prompt and retry until successful.
    • Parameter Configuration and Prompts
      • After successfully creating the AP, provide a prompt using the RGB LED (green light for 1 second).
    • IP Address Display
      • Get and format the soft AP's IP address, store it in ipStr, and output it for display, making it easy to know the network address.
    • Web Server Setup
      • Use server.on to set corresponding request handler functions (such as handleRoot, handleGetData, etc.) for multiple paths (such as "/", "/getData", etc.). Each function should be defined elsewhere for different functional operations, such as returning pages, getting data, controlling switches, etc.
      • Finally, call server.begin() to start the Web server and output a startup prompt.

RS485 Control​

Use an RS485 device to connect to the ESP32-S3-POE-ETH-8DI-8DO device. Sending data to the ESP32-S3-POE-ETH-8DI-8DO can control each digital output. Communication is performed at a default baud rate of 9600.

Operation CommandCommand Function
06 05 00 01 55 00 A2 EDToggle CH1 state
06 05 00 02 55 00 52 EDToggle CH2 state
06 05 00 03 55 00 03 2DToggle CH3 state
06 05 00 04 55 00 B2 ECToggle CH4 state
06 05 00 05 55 00 E3 2CToggle CH5 state
06 05 00 06 55 00 13 2CToggle CH6 state
06 05 00 07 55 00 42 ECToggle CH7 state
06 05 00 08 55 00 72 EFToggle CH8 state
06 05 00 FF FF 00 BD BDTurn on all channels
06 05 00 FF 00 00 FC 4DTurn off all channels
  • Hardware Connection

The example uses a USB TO RS232/485 Converter for demonstration.

ESP32-S3-POE-ETH-8DI-8DOUSB-TO-RS232-485
RS485 - A+Tx B - A+
RS485 - B-Rx B - B-
  • Software Operation

    • Use SSCOM for data sending

    • Open the SSCOM software and select the COM port corresponding to the Port B connected above.

    • Open the serial port and use the multi-send function to quickly send commands

      ESP32-S3-POE-ETH-8DI-8DO-01

  • The following commands can be used for digital output control.

    ESP32-S3-POE-ETH-8DI-8DO-02

Bluetooth Control​

Use a mobile Bluetooth debug assistant to connect to the ESP32-S3-POE-ETH-8DI-8DO device. Sending data to the ESP32-S3-POE-ETH-8DI-8DO can control each digital output. Please note: Some Bluetooth debug assistants send data in ASCII format by default. Before controlling the device, you need to enter the correct control commands according to the Bluetooth debug assistant.

ASCIIHexCommand Function
10x31Toggle CH1 state
20x32Toggle CH2 state
30x33Toggle CH3 state
40x34Toggle CH4 state
50x35Toggle CH5 state
60x36Toggle CH6 state
70x37Toggle CH7 state
80x38Toggle CH8 state
90x39Turn on all channels
00x30Turn off all channels
  • Software Operation (View IP)

    • Use the mobile Bluetooth debug assistant nRF Connect for digital output control (other Bluetooth debug assistants can also be used).
    • The following uses nRF Connect for functional demonstration.
    • Connect to the Bluetooth device named ESP32-S3-POE-ETH-8DI-8DO.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Bluetooth_1

  • After successful connection, select Unknown Service, click to read data. If Wi-Fi connection fails for a long time, the RGB will stay red, and this operation will have no response.

  • When Wi-Fi is successfully connected, the device IP will be received as follows. The device IP is 192.168.6.133.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Bluetooth_2

  • The Bluetooth digital output control commands are characters 0-9, i.e., hexadecimal 0x30 - 0x39.

  • Click the send button, select hexadecimal send, and then enter 0x31.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Bluetooth_3

  • Sending 0x31 can control CH1 to toggle its state.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Bluetooth_4

  • Sending 0x38 can control CH8 to toggle its state.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Bluetooth_5

Web Page Control​

Use a mobile Bluetooth debug assistant to connect to the ESP32-S3-POE-ETH-8DI-8DO device, obtain the IP after connecting to Wi-Fi, and open the Web page via the IP.

  • AP Mode

    • Connect to the Wi-Fi of the ESP32-S3-POE-ETH-8DI-8DO device. The Wi-Fi name is ESP32-S3-POE-ETH-8DI-8DO, and the password is waveshare.

    ESP32-S3-POE-ETH-8DI-8DO_TO_Web_0

    • Obtain the current IP through the Bluetooth debug assistant.
    • Open the Web page to control the digital outputs, RS485, and CAN interfaces. (After the device is powered on, it takes a short time to configure. The first time the Web page is opened after each power-on may be slow.)

    ESP32-S3-POE-ETH-8DI-8DO_TO_Web_1

    ESP32-S3-POE-ETH-8DI-8DO_TO_Web_3

  • STA Mode

    • After the device is powered on, it will automatically connect to the configured Wi-Fi (before flashing the program, you need to modify the Wi-Fi to connect to).
    • Obtain the current IP through the Bluetooth debug assistant.
    • Open the Web page to control the digital outputs, RS485, and CAN interfaces. (After the device is powered on, it takes a short time to configure. The first time the Web page is opened after each power-on may be slow.)

    ESP32-S3-POE-ETH-8DI-8DO_TO_Web_4

    ESP32-S3-POE-ETH-8DI-8DO_TO_Web_5

02_MAIN_WIFI_STA​

Example Description

  • This example implements controlling the switches of 8 digital outputs via Wi-Fi, Bluetooth, and RS485. This example enables the Wi-Fi STA mode.

Notes

  • Requires modifying the Wi-Fi to connect to.
  • The Web page only supports controlling the device when it is on the same network as this product. If using a mobile phone for control, mobile data must be turned off.

Code Analysis

  • WIFI_Init (): Makes the device connect to the specified Wi-Fi network in station (STA) mode. If the connection is successful, it performs subsequent network-related configurations (such as obtaining the IP address, starting the Web server, and registering callback functions, etc.). If the connection fails, it provides a corresponding prompt and sets the connection status flag. During the process, it also provides visual prompts of the connection status via the RGB LED.
    • Wi-Fi Network Connection Attempts:
      • First set Wi-Fi to WIFI_STA mode and enable sleep mode, then start connecting to the specified network. During the loop waiting for a successful connection, output a dot as a prompt every half second. On every even-numbered attempt (except the first), briefly light the RGB LED red as a prompt. After every 10 failed attempts, disconnect and reconnect. If the number of attempts exceeds 22, consider the connection failed and exit the loop.
    • Operations After Successful Connection:
      • If the number of connection attempts is less than 23 (i.e., connection successful), set WIFI_Connection to 1, light the green LED for 1 second as a success prompt, then obtain and display the local IP address. Next, register callback functions for multiple paths with the Web server (such as the root path, get data, control different switches, etc.). Finally, start the server and output a startup prompt, enabling the device to accept corresponding control through the web page.
    • Operations After Connection Failure:
      • If the number of attempts is greater than or equal to 23 (connection failed), set WIFI_Connection to 0, output a prompt informing that the device can be controlled via a Bluetooth debug assistant, and light the red LED to indicate the connection failure status.

RS485 Control

Bluetooth Control

Web Page Control

03_MAIN_ALL​

Waveshare Cloud Is No Longer Maintained

The following operations are based on Waveshare Cloud. Waveshare Cloud is no longer maintained, and the following tutorial is for reference only.

Example Description

  • This example is a collection of all functions: RS485 interface control, Bluetooth control, Web page control (short range), and Waveshare Cloud control (long range).

Notes

  • Requires modifying the Wi-Fi to connect to.
  • The Web page only supports controlling the device when it is on the same network as this product. If using a mobile phone for control, mobile data must be turned off.
  • A device must be created in Waveshare Cloud.

RS485 Control

Bluetooth Control

Web Page Control