For a simple project I'm in need to use 2 serial ports on my ESP32. (Now I'm testing with serial 0 and Serial1 , later on I will use serial1 and Serial2)
I've been reading in to use serial1 on this device but still cannot get it working in the test sketch
At this point using the stuff I've found on ESP32 + RS232 TTL serial communication - Programming Questions - Arduino Forum I used the code below.
When i connect a ttl - usb converter to pin 26-27 I can send data from Serial0 to Serial 1 but not from Serial1 to Serial0
Perhaps there is a better way to do this in v1.0.4. for the esp32..
Every tip / trick is welcome.
// EXAMPLE USAGE
#include <HardwareSerial.h>
//#define SerialDataBits 115200
HardwareSerial SerialTFMini( 1 );
HardwareSerial SerialController( 2 );
// serial(1) = pin27=RX green, pin26=TX white
// serial(2) = pin16=RXgreen , pin17=TX white
void setup()
{
SerialController.begin( 9600 );
SerialTFMini.begin( 9600, SERIAL_8N1, 27, 26 );
Serial.begin(9600);
Serial1.begin(9600); // open serial over TX and RX pins
}
void loop()
{
Serial.println("Test print serial0");
Serial1.println("Test print serial1");
delay(1000);
// read from port 0, send to port 1 ... working
if (Serial.available())
{
Serial1.print(Serial.read());
}
// read from port 1, send to port 0 ... not working
if (Serial1.available())
{
Serial.println("is er ");
Serial.print(Serial1.read());
}
}