Skip to content

Example 12: UART Serial Communication ​

Experiment Overview ​

Implement serial communication between ESP32 and external devices via UART (Universal Asynchronous Receiver-Transmitter). ESP32 has 3 UART ports, FastBee supports configuring serial ports for debug output, Modbus communication or custom data exchange.

Hardware Wiring ​

UART PortTX PinRX PinPurpose
UART0GPIO1GPIO3USB debug output
UART1GPIO16GPIO17Modbus/External devices
UART2GPIO18GPIO19Extended serial port

UART0 is used for USB debug output by default, UART1/2 can be used to connect external devices.

JSON Configuration Example ​

json
{
  "peripherals": [
    {
      "id": "uart0",
      "name": "Serial0-Debug",
      "type": 1,
      "enabled": false,
      "pins": [1, 3],
      "params": {
        "baudRate": 115200,
        "dataBits": 8,
        "stopBits": 1,
        "parity": 0
      }
    },
    {
      "id": "uart1",
      "name": "Serial1-Modbus",
      "type": 1,
      "enabled": false,
      "pins": [16, 17],
      "params": {
        "baudRate": 9600,
        "dataBits": 8,
        "stopBits": 1,
        "parity": 0
      }
    }
  ]
}

Parameter Description ​

ParameterDescriptionOptions
baudRateBaud rate9600, 19200, 38400, 57600, 115200
dataBitsData bits7, 8
stopBitsStop bits1, 2
parityParity0=None, 1=Odd, 2=Even

Peripheral Execution Linkage ​

Scenario: Serial Data Send (Platform Trigger) ​

Function: Send data to external device via UART1 through cloud platform command

Web Interface Configuration Steps ​

Step 1: Create Rule

  1. Click Peripheral Execution in the left menu
  2. Click New Rule button
  3. Fill in basic configuration:
    • Rule Name: Serial Send Data
    • Report Data: ✅ Enable
    • Enabled: ✅ Enable

Step 2: Configure Trigger

  1. Click Add Trigger button

  2. Fill in trigger configuration:

    FieldValueDescription
    Trigger TypeSelect Platform TriggerReceive cloud platform commands
    OperatorSelect Set ModeReceived data as action parameters

Step 3: Configure Action

  1. Click Add Action button

  2. Fill in:

    • Action Type: Select Serial Send
    • Target Peripheral: Select uart1
  3. Click Save button

Test Method:

Send any string via cloud platform, e.g.: Hello UART Data will be sent through UART1's TX pin (GPIO16)

UART Parameter Reference ​

ParameterDescriptionOptions
Baud RateCommunication speed9600, 19200, 38400, 57600, 115200
Data BitsNumber of data bits7, 8
Stop BitsNumber of stop bits1, 2
ParityParity methodNone, Odd, Even

Notes ​

  1. UART0 Occupied: UART0 (GPIO1/3) is used for USB debug, not recommended to reassign
  2. Pin Mapping: ESP32 UART TX/RX can be mapped to any GPIO (except GPIO6-11)
  3. Voltage Matching: ESP32 is 3.3V level, level shifting needed for 5V devices
  4. Modbus Configuration: When used for Modbus, baud rate is typically 9600, must match slave device
  5. Buffer: UART receive buffer defaults to 256 bytes, read promptly for large data volumes
  6. ESP32-S3: S3's UART0 outputs via USB CDC, physical UART starts from UART1

FastBee | fastbee.cn