Description
Hardware:
Board: ESP-WROOM-32
Core Installation/update date: 11/jul/2017
IDE name: Arduino IDE
Flash Frequency: 80Mhz
Upload Speed: 115200
Description:
Hi everyone,
I am working on a project in which I need to have an ESP32 connected via serial to another ESP32 and at the same time to a Nextion HMI. I also need to communicate from the central ESP32 to these 2 devices concurrently ( having the serial communications in the "central" ESP32 open to both devices and issuing commands simultaneously)
I have been making some testing in preparation to the interfacing to these devices by replacing the Nextion with an ESP826MOD:
Central ESP32: ESP-WROOM-32 devkit, connected to a USB port of a PC
Client Device A: ESP-WROOM-32 devkit connected to USB port of another PC
Client Device B: ESP8266MOD devkit connected to a USB port of the same PC as Central ESP32
I load a simple sketch (Based on serial passthrough example by Erik Nyquist) on the central ESP32 to open UART1 and UART2. The idea is to open the Serial Monitor connected via the USB port to each device and issue simple strings, which I expect reflected on any of the other Serial Monitors from A and B.
For devices A and B, I setup UART1 for the ESP8266MOD (Device B - TX/RX pins) and UART2 on the 2nd ESP32 (Device A - pins 16 & 17). I then proceed with the following sketches (Based on serial passthrough example by Erik Nyquist):
Sketch:
//Central ESP32
#include <HardwareSerial.h>
HardwareSerial Serial1(1);
HardwareSerial Serial2(2);
void setup() {
// initialize serial:
Serial.begin(115200);
Serial1.begin(115200,SERIAL_8N1, 4, 2); //Baud rate, parity mode, RX, TX
Serial2.begin(115200,SERIAL_8N1, 16, 17);
}
void loop() {
if(Serial.available()) //if user typed something through the USB...
{
Serial1.write(Serial.read()); //Push it through port 1 to Device B
Serial2.write(Serial.read()); //Push it through port 2 to Device A
Serial.flush(); //erase any data on serial port after operation
}
if (Serial1.available()) //If data is received through Serial 1 from Device B...
{
Serial.write(Serial1.read()); //Show data on Serial Monitor
Serial.flush(); //Flush port
}
if (Serial2.available()) //If data is received through Serial 2
{
Serial.write(Serial2.read()); //Show data on Serial Monitor 1
Serial.flush(); //Flush port
}
}
//Client A (ESP32)
HardwareSerial Serial2(2); //Needed since this is an ESP32
void setup() {
Serial.begin(115200);
Serial2.begin(115200, SERIAL_8N1, 16, 17);
}
void loop() {
if (Serial.available()) // If user typed something through the USB...
{
Serial2.write(Serial.read()); // Push it through Port 2 to Central ESP32
}
if (Serial2.available()) // If data is received through Port 2 from Central ESP32
{
Serial.write(Serial2.read()); // Show data on Serial Monitor 2
}
}
//Client B (ESP8266MOD)
void setup() {
Serial.begin(115200);
Serial1.begin(115200, SERIAL_8N1); //Does not need HardwareSerial initiaization or pin def since
} //this Serial is from the awesome ESP8266
void loop() {
if (Serial.available()) //if user typed something through the USB...
{
Serial1.write(Serial.read()); //Push it through port 1 to Central ESP32
}
if (Serial1.available()) //If data is received through Serial 1 from Central ESP32...
{
Serial.write(Serial1.read()); //Show data on Serial Monitor 3
}
}
In summary, I can type any text from Serial monitor of Devices A and B and I will see it on Serial Monitor of Central ESP32, but if I type something on Serial Mon of Central ESP32 I never see anything on Device B and only garbled text on Device A.
I have tried several configurations to no avail. My question is: does anybody knows if an updated library or firmware is available for the ESP32, or some sort of workaround to overcome this issue?
Can somebody point me out in the right direction to be able to use the 3 UARTs concurrently? it is very urgent/critical for me so any idea is welcome.
Thanks in advance
-EZ