ESP32 + RS232 TTL serial communication

ixybus
Posts: 1
Joined: Fri Mar 15, 2019 9:47 am

ESP32 + RS232 TTL serial communication

Postby ixybus » 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:
squematic.png
Couldn't find a suitable image to make the squematic wiring so I picked this converter, I'm not using this one, but the one I provided on the url
squematic.png (360.03 KiB) Viewed 668 times
This is my code:
  1. #define RXD2 16
  2. #define TXD2 17
  3.  
  4. void setup() {
  5.   // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  6.   Serial.begin(115200);
  7.   //Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);
  8.   Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
  9.   Serial2.println("serial2test");
  10.   Serial.println("Serial Txd is on pin: " + String(TX));
  11.   Serial.println("Serial Rxd is on pin: " + String(RX));
  12.  
  13. }
  14.  
  15. void loop() {
  16.   Serial2.print("hello");
  17.   Serial2.write("hellowrite");
  18.   Serial.print(char(Serial2.read()));
  19.   delay(1000);
  20. }
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:
terminal2.png
terminal2.png (55.2 KiB) Viewed 668 times
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?

Who is online

Users browsing this forum: Bing [Bot] and 25 guests