Skip to content

How to change UART pin

Quốc Hùng edited this page Dec 29, 2022 · 3 revisions

How to change UART pin

I. Modbus:

Default Modbus UART pin

Board ESP32 ESP8266 STM32 Raspberry Pi
RX 16 14 PA3 15
TX 17 12 PA2 14

1. For ESP32:

Method 1:
Change it by adding the following two define lines

#define MODBUS_RXD_Pin <newRxPin>
#define MODBUS_TXD_Pin <newTxPin>

Before

#define ERA_AUTH_TOKEN "*"

Method 2:
Create HardwareSerial object

HardwareSerial serialMB(1);

Then using

serialMB.begin(9600, SERIAL_8N1, newRxPin, newTxPin);
ERa.setModbusStream(serialMB);

Before

ERa.begin();

2. For Raspberry Pi

Create ERaSerialLinux object

ERaSerialLinux serialMB;

Then using

serialMB.begin("/dev/*", 9600);
ERa.setModbusStream(serialMB);

Before

ERa.begin();

3. Other boards

Create HardwareSerial object

HardwareSerial serialMB(newRxPin, newTxPin);

or SoftwareSerial object

SoftwareSerial serialMB(newRxPin, newTxPin);

Then using

serialMB.begin(9600);
ERa.setModbusStream(serialMB);

Before

ERa.begin();

3. Note

If board have Modbus DE pin then using

ERa.setModbusDEPin(dePin);

Before

ERa.begin();

II. Zigbee:

Default Zigbee UART pin

Board ESP32 Raspberry Pi
RX 32 USB
TX 33 USB

1. For ESP32:

Method 1:
Change it by adding the following two define lines

#define ZIGBEE_RXD_Pin <newRxPin>
#define ZIGBEE_TXD_Pin <newTxPin>

Before

#define ERA_AUTH_TOKEN "*"

Method 2:
Create HardwareSerial object

HardwareSerial serialZB(1);

Then using

serialZB.begin(115200, SERIAL_8N1, newRxPin, newTxPin);
ERa.setZigbeeStream(serialZB);

Before

ERa.begin();

2. For Raspberry Pi

Create ERaSerialLinux object

ERaSerialLinux serialZB;

Then using

serialZB.begin("/dev/*", 115200);
ERa.setModbusStream(serialZB);

Before

ERa.begin();