Good evening, I would like a little help. I'm facing difficulties in the communication of the Arduino and also the ESP32 Wroom Dev when using the MAX RS232 DB9 TTL communication module. The fact is that I have the correct pinout in both projects (Arduino Uno 2 RX, 3 TX using the SoftwareSerial library), and in the case of the ESP32, I use the UART RX and UART TX pins 16 and 17 as per the manufacturer's pinout information. I have various devices for testing, and none of them result in valid information. The only way I can achieve this is by using a cable connected to the female DB9 output of the converter, male DB9 to USB in a new instance of Arduino. The information is sent and received correctly in both processes. What is not happening is when I want to read my projects from the MAX RS232, I even tested communication between two Arduinos, both Mega and Uno, and it doesn't result in communication. Below is the model code (for illustration purposes only).
#include <SoftwareSerial.h>
SoftwareSerial mySerial(2, 3); // RX, TX (conectados aos pinos do conversor DB9)
void setup() {
Serial.begin(9600); // Inicializa a comunicação serial USB para depuração
mySerial.begin(9600); // Inicializa a comunicação serial SoftwareSerial
delay(1000); // Aguarda um breve momento para garantir que o segundo Arduino esteja pronto
}
void loop() {
if (Serial.available()) {
String message = Serial.readStringUntil('\n'); // Lê a mensagem da porta serial USB até encontrar o caractere '\n'
mySerial.println(message); // Envia a mensagem completa para o outro Arduino
}
if (mySerial.available()) {
String receivedMessage = mySerial.readStringUntil('\n'); // Lê a mensagem da porta SoftwareSerial até encontrar o caractere '\n'
Serial.print("Received: ");
Serial.println(receivedMessage); // Mostra a mensagem recebida no monitor serial USB
}
}
Each device that uses RS232 has a different protocol type. For instance, an LG TV has a distinct type with ASCII commands, while another device might communicate directly using Hex. Therefore, I need to communicate the Arduino with any device using DB9, but I'm unable to do so. Could you assist me? Please take a look at my code, it's standard. Additionally, when using an RS232 to USB converter cable, there is communication.
I would be very grateful if you could assist me by providing answers that I could use to solve the problem. Yes, the ESP doesn't need the library as it already has it. I posted the Arduino code due to the forum. Thank you. Do you have any proposed solutions?
Attempts I've made:
Reversing RX and TX (didn't solve the issue)
Modifying and treating the codes (didn't solve the issue)
Changing the wiring by creating a PCB (didn't solve the issue)
I was really straightforward, what I need to do is communicate with an Arduino (Uno R3 or Mega 2560) or ESP32 using the RS232 DB9 connector. As for the code, as I mentioned, it works perfectly when I use a "USB to Serial DB9" cable, but there are no results when I connect with the DB9 to DB9 cable. Could someone assist me? Regarding the code, I can post thousands of lines here, but what I really need is to understand why my connection isn't yielding any results.
#include <SoftwareSerial.h>
SoftwareSerial mySerial(6, 7); // RX, TX
String tvPower = "00"; // Power 00=off 01=on
int tvVolume = 0; // Volume
const String tvid = "01"; // The ID you set in your TV
unsigned long previousMillis = 0; // Last time update
int messageToSend = 0;
void setup()
{
Serial.begin(9600);
mySerial.begin(9600);
sendMessage("LG TV RS232", "1.1");
}
void loop()
{
if (mySerial.available() > 0)
{
String incomingString = mySerial.readStringUntil('\n');
Serial.print("I received: ");
Serial.println(incomingString);
parseSerialString(incomingString);
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis > 30000)
{
previousMillis = currentMillis;
if (messageToSend > 0) messageToSend = 0;
if (messageToSend == 0)
{
sendMessage("ka", "FF");
messageToSend++;
}
else if (messageToSend == 1)
{
sendMessage("kf", "FF");
messageToSend++;
}
}
}
void sendMessage(const String &tvcommand, const String &tvstatus)
{
mySerial.println(tvcommand + " " + tvid + " " + tvstatus);
}
void setPower(const String &tvstatus)
{
sendMessage("ka", tvstatus);
}
void setVolume(int volume)
{
if (volume < 0) volume = 0;
if (volume > 64) volume = 64;
String strVolume = String(volume, HEX);
if (strVolume.length() == 1)
{
strVolume = "0" + strVolume;
}
sendMessage("kf", strVolume);
}
void parseSerialString(const String &serialString)
{
String tvcommand = serialString.substring(0, 1);
String tvstatus = serialString.substring(7, 9);
if (tvcommand == "a")
{
tvPower = tvstatus;
Serial.println("Power is: " + tvPower);
}
if (tvcommand == "f")
{
tvVolume = tvstatus.toInt();
Serial.println("Volume is: " + tvstatus);
}
}
The module in question is module 3, therefore when I attempt a test communication with the computer using modules 3 and 1, it works perfectly. When I attempt communication with modules 3, 2, and 1, it works perfectly as well. The issue I am facing is when I use module 3 to communicate with a device such as a TV or another device with RS232 output.
Unfortunately, I haven't been able to do it yet. I'm not managing to communicate the Arduino or ESP with the MaxRS232 TTL. I'll include one of the protocols below as an example.