ESP32 + RS232 TTL serial communication
Posted: Fri Mar 15, 2019 10:12 am
Hello!
I'm currently trying to communicate my ESP32 DevKitV1 through serial. I bought a TTL-RS232 like this one:
https://es.aliexpress.com/store/product ... st=ae803_4
So I wired it to the ESP32 like this: This is my code:
I'm using HardwareSerial since I've seen everyone saying it's better that SoftwareSerial, and what I want to do is to read from the Serial2 (connected to the RS232) and print it on Serial (ESP32). With this code I can print on both serials just fine (sort of) but I can't seem to be able to read from Serial2:
The final goal is to be able to type something on Serial2 so it's sent to the ESP32, and read it correctly.
Am I missing something? Should I not be crossing the TX/RX pins?
I'm currently trying to communicate my ESP32 DevKitV1 through serial. I bought a TTL-RS232 like this one:
https://es.aliexpress.com/store/product ... st=ae803_4
So I wired it to the ESP32 like this: This is my code:
- #define RXD2 16
- #define TXD2 17
- void setup() {
- // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
- Serial.begin(115200);
- //Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
- Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
- Serial2.println("serial2test");
- Serial.println("Serial Txd is on pin: " + String(TX));
- Serial.println("Serial Rxd is on pin: " + String(RX));
- }
- void loop() {
- Serial2.print("hello");
- Serial2.write("hellowrite");
- Serial.print(char(Serial2.read()));
- delay(1000);
- }
Am I missing something? Should I not be crossing the TX/RX pins?