ESP32, Arduino and RS232

Hi, hope you all well.

So, I've been trying serial communication between Arduino Uno and ESP32 using a jumper cable, and it works really well, I can send data from ESP32 to Arduino, and Arduino send back data to ESP32. But when I replace those jumper cable to RS232 cable and RS232 to TTL module, nothin happen in the serial monitor. What do I do wrong?

In both Arduino and ESP32, I'm using SoftwareSerial library. Both serial 1 and 2 usinh Baud rate 9600.

In Arduino

  • I am using pin 2 and 3 for Serial2, 0, 1 for Serial1
  • to RS232 module, I connect the pin, RX to RX TX to TX and VCC to 5V, GND to GND

In ESP32 I use pin 16, 17, and the same rx tx like Arduino and gnd and vcc to 3V3.

I use the exact same code from which I use to serial communication using jumper cable.

What do I do wrong? What is the different between communicating using jumper cable and RS232 cable?

I already try to cross the rx tx, and also change the VCC in Arduino to 3V3, but still nothing happen... Can somebody help me?

Please post a schematic. Also links to the modules you used, or post the data. Time after time, words have been found to be insufficient here.

Did your "jumper cable" have 5V-3.3V level translation? If not, you may have blown the ESP pins.

I don't understand what you are doing. please post the schematic you are planning.
according to my experience arduino can do serial communication with esp32 by direct jumper cable. from the problem you mentioned, do you want to replace the serial interface (both arduino and esp32) by using the RS232 -TTL module?
Is your circuit structured like this?
ESP32 => RS232 TTL module => RS232 cable => RS232 TTL module => Arduino
I've never used ESP32 + RS232 TTL serial communication so can't really give any advice.

Yess, my circuit exactly structured like that. Oh it's too bad that you don't have experience on this matter, but I new too in this kind of programming, but it works well when I'm using jumper cable, but it doesn't work when I'm using RS232 cable

You will not get real help here until you post a schematic diagram, and information about the modules you are using.

I have lots of experience with different kinds of serial, but I'm not going to try to guess what you did. Is this the kind of jumper cable you used?
image

So, the first thing is like this

And then I try to change it like this

I can not see which terminals you have attached the wires to. Please provide a wiring diagram. You have now been asked three times. Also information about the RS-232 modules.

Is your serial cable a crossover cable? It has to be, connections cross over like:
RX<->TX
TX<->RX

which needs more attention is on the esp32 - rs232 ttl module. Ic Max232 requires a supply voltage (Vcc) of 5V (based on datasheet). maybe you can try using the ttl level shifter module to connect the esp32 with the rs232 TTL module.
esp32 => ttl level shifter module => rs232 ttl module => rs232 cable => rs232 ttl module => arduino

1 Like

Hi, I'm so sorry for my bad drawing, I can't afford the software. This is the schema that I use when I'm communicating using jumper cable

And this is my schema for usign RS232 cable and RS232-to-TTL module

This is my code on Arduino:

#include <SoftwareSerial.h>
SoftwareSerial arduino(2,3);

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  arduino.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  String command = "";
  while (arduino.available() > 0) {
    command += char(arduino.read());
  }

  command.trim();
  Serial.println("Command received: " + command);

  if (command == "K") {
    arduino.write("Data From Arduino");
  } else {
    arduino.write("Wrong Command");
  }

  command = "";
  delay(5000);
}

This is my Code in ESP32

#include <ArduinoJson.h>
char jsonOutput[128];

#define RXD2 16
#define TXD2 17

#include <SoftwareSerial.h>
SoftwareSerial arduino(RXD2, TXD2);
unsigned long previousMillis = 0;
const long interval = 5000;

#include <WiFi.h>
// const char* ssid = "SSID1";
// const char* password = "Password1";

const char* ssid = "SSID2";
const char* password = "Password2";

#include <HTTPClient.h>

void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  arduino.begin(9600);
  connectWiFi();
}

void loop() {
  // put your main code here, to run repeatedly:
  
  unsigned long currentMillis = millis();

  if ((currentMillis - previousMillis) >= interval) {
    previousMillis = currentMillis;
    
    String dataSerial = "";

    while (arduino.available() > 0) {
      dataSerial += char(arduino.read());
    }

    dataSerial.trim();
  
    if (dataSerial != "") {
      if (WiFi.status() == WL_CONNECTED) {
        HTTPClient http;

        http.begin("https://jsonplaceholder.typicode.com/posts");

        Serial.println("\nSending data... wait for http response");
        String jsonParams;
        jsonParams = "{\"title\":\"" + dataSerial + "\"}";

        int httpResponseCode = http.POST(jsonParams);

        Serial.println("StatusCode: " + String(httpResponseCode));
        if (httpResponseCode > 0) {
          String response = http.getString();
          Serial.println(response);
        } else {
          Serial.println("Error on sending POST...");
        }
      
        http.end();
      } else {
        connectWiFi();
      }

      dataSerial = "";
    }
    
    arduino.write("K");
  }
}

void connectWiFi() {
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(2000);
    Serial.println("Connecting to WiFi...");
  }

  Serial.println("Connected to the WiFi network");
  Serial.println(WiFi.localIP());
}

In case the picture is not clear: Arduino to RS232

ESP32 to RS232

Is the RS232 module connected to your ESP32 spec'd to work from 3.3v?

Yess, I think so... What do I have to do to handle this?

@aarg asked if you are using a RS232 crossover cable???
if you are not sure use jumpers on the 9 pin RS232 connectors
pin 2 to pin 3
pin 3 to pin 2
pin 5 to pin 5

Check the module specification, that should tell you.

Also, have you carried out a simple loopback test on each module? Connect a module Tx to its Rx and send a few characters. You should receive what you sent. However, I note you mentioned SoftwareSerial, and i'm not sure it can send and receive at the same time.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.