esp32 to rs-232 device - making sense of the values.

Hello Community,
I am failing on a seemingly simple task: make my esp32 talk to my HDMI Matrix Switcher via RS-232.
I am using a TTL to RS-232 converter that should be 3.3v tolerant: Converter
The Matrix Switcher in question: Matrix Switch
I got the protocol specifications from the manufactorer of the switch: RS 232 Communication Secifications

I hooked up the ESP 32 to the converter. and from there i connect the Matrix Switcher with a db9 cable.

I hooked up:
ESP 32 --> RS232 TTL converter
3.3 V --> VCC
GND --> GND
16 --> TX (I also tried 16 to RX ... just in case it needs to be crossed)
17 --> RX (I also tried 17 to TX ... just in case it needs to be crossed)

and wrote the following simple code according to the communication protocol:

void setup() {
  Serial.begin(115200);
  Serial2.begin(9600, SERIAL_8N1, 16, 17);
  Serial2.write("MT00SW0200NT");
}

void loop() {
}

But nothing happens on the matrix switch. i also tried the other commands in the pdf... still nothing. I think I must be overlooking something obvious since this should not be that hard... just sending commands to a rs-232 device...

Does anybody have an Idea where this is failing? Am i reading the specifications wrong?

Have you tried connecting the matrix to a PC and sending the commands from the PC - does that work?
Have you tried connecting the ESP and converter to a PC and seeing if you get the expected strings on the PC?

unfortunatly I dont have a usb-rs232 cable here and my computers dont have a native 9db connector... :frowning:

I would definitely look at some way of reading the RS232 to/from your devices.

I notice that both your converter and matrix are female DB9, how are you connecting them?

Have you done a loop back test to confirm an ability to send / to receive?

Do you have another ESP32 that you can connect the ESP32 to and from there to your PC to test the send is OK. I.e. ESP32 -> 3v3 serial -> ESP32 -> PC

Then you can connect the switch and 'tap' into the Switches TX (3v3 TX that connects to the ESP32) line to sniff what is happening on that. Edit: not really much use to do that.
What would be nice would be if you have two converters that you could test back to back and then use one to tap into the TX line from the switch. (I always buy two of things on the basis I will destroy one try to get it to work)

By the way, try adding a newLine '\n' or CR newline '\r''\n' to the command. Not mentioned in the doc but often used for sending commands.

Also check the CTS and RTS and DTR lines you may need to loop the CTS to the RTS
see the bottom of

You can use a multimeter to check the levels on the CTS, RTS etc lines
see RS232 Voltage Levels - Signals DTR CTS RTS » Electronics Notes
for the levels expected

countrypaul:
Have you tried connecting the matrix to a PC and sending the commands from the PC - does that work?
Have you tried connecting the ESP and converter to a PC and seeing if you get the expected strings on the PC?

sorry for the late reply. i needed to get the usb-rs232 cable for testing and i got some success but not really.

when i connect the pc USB -> esp32 -> ttl/rs232 converter -> rs232_to_usb_cable -> pc and start up Tera Term on my windows and monitor the serialmonitor of the esp32 everything works as expected. i can send and receive from both devices.

when i connect the matrix switch directly to the pc and send the command "MT00SW0100NT" the switch reacts as intended.

when i connect the esp32 -> ttl/rs232 converter -> matrix switch nothing happens.

countrypaul:
I would definitely look at some way of reading the RS232 to/from your devices.

I notice that both your converter and matrix are female DB9, how are you connecting them?

I got a rs232 male-to-male cable db9 for that.

Idahowalker:
Have you done a loop back test to confirm an ability to send / to receive?

see above... yes i think thats what i did.

drmpf:
Do you have another ESP32 that you can connect the ESP32 to and from there to your PC to test the send is OK. I.e. ESP32 -> 3v3 serial -> ESP32 -> PC

Then you can connect the switch and 'tap' into the Switches TX (3v3 TX that connects to the ESP32) line to sniff what is happening on that. Edit: not really much use to do that.
What would be nice would be if you have two converters that you could test back to back and then use one to tap into the TX line from the switch. (I always buy two of things on the basis I will destroy one try to get it to work)

By the way, try adding a newLine '\n' or CR newline '\r''\n' to the command. Not mentioned in the doc but often used for sending commands.

Also check the CTS and RTS and DTR lines you may need to loop the CTS to the RTS
see the bottom of
advantech

You can use a multimeter to check the levels on the CTS, RTS etc lines
see RS232 Voltage Levels - Signals DTR CTS RTS » Electronics Notes
for the levels expected

i tried
Serial2.write("MT00SW0100NT\r");
Serial2.write("MT00SW0300NT\n");
Serial2.write("MT00SW0300NT\r''\n'");

no change... when tested in TeraTerm i also just wrote "MT00SW0100NT" - nothing additional was needed.

I think the esp32 -> esp32 tasks are now redundant now since i got the cable and established that its working that way. I just have one esp32 here...

I could get a multimeter somewhere... but since the usb -> rs232 directly to the matrix switch also works i guess everything is ok on that site?

the code i used to test all this looks like this...

#define RXD2 16
#define TXD2 17
char c;
String readString;
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);
  Serial2.begin(9600, 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() {
  while (Serial2.available()) {
    c = Serial2.read();
    readString += c;
  }
  if (readString.length() > 0) {
    Serial.print(readString);
    Serial2.print(readString);
    //server.print(readString);
    readString = "";
  }

  Serial2.write("MT00SW0100NT\r");
  delay(4000);
  Serial2.write("MT00SW0300NT\n");
  delay(4000);
}

so everything works... just not esp32 -> ttl/rs232 converter -> hdmi matrix.

can you think of any other tests for me?
thanks a lot for all this input! this is seriously awesome.

since the usb -> rs232 directly to the matrix switch also works i guess everything is ok on that site

That looks good. At this stage I would be hooking up an oscilloscope, but..

i) make sure your grounds are all connected

ii) connect the esp32 -> ttl/rs232 converter -> hdmi matrix and then tap into the RS232 ttl/rs232 outgoing line line and connect it to the recieve line of the Rs232/usb and see what comes out on the pc, I.e. just the connect the gnd and the receive line of the Rs232/usb
If you have trouble working out which is the 'receive' line on the Rs323/usb, (I would) set up the pc connection and lift on line or the other until you loose the hdmi output on the pc

iii) if the output is as expected (compared to the working pc connection), change the receive tap to the output from the hdmi

iv) I would still check the cts/rts etc with a multimeter since the ttl/rs232 is not the same as the usb/rs232 device.

A quick visual test for your RS-232 signals it to use a RED LED in series with a 220 ohm resistor and place it across the TX data and ground lines. If wired correctly, the LED will light with no signal and will blink off-on with a signal. Do the same with the TX line from your device. Same light-no light should occur.
Paul

Save the LED and resistor for future data tests.

The problem with a simple led + resistor circuit is that the control voltages are

-3 to -25 OFF
+3 to +25 ON

Signal voltages are also +/- 25V
and and leds don't like reverse voltages above 5V.

A robust circuit would have two led + resistor + protection diode connected in parallel and reversed then one will light up for Off and the other for ON, and neither if no volts.
A multi-meter looked like an easier solution to me which is why I did not suggest using leds

drmpf:
iv) I would still check the cts/rts etc with a multimeter since the ttl/rs232 is not the same as the usb/rs232 device.

Oh i am onto something here.... i am measuring very different values when i compare the usb-rs232 to the ttl-rs232.

on the usb cable that works i measure:
RTS: 8,96V
CTS: 8,96V
TXD: -8,38V

on the ttl-rs232 i am measuring:
RXD: -6,08V
TXD: 1,16V

EDIT: i just measured the ttl-rs232 when connected the vcc line to 5V instead of 3.3 and now i am measuring this:
RXD: - 8,96V
TXD: 3.4V

so there is something quite wrong and i think i should look into that first :).
does anybody have an idea what i can do about this?

Since the ttl-rs232 appears to work when used pc USB -> esp32 -> ttl/rs232 converter -> rs232_to_usb_cable -> pc that suggests the converter works for at least some conditions. Others may be able to offer sugestions on the voltages. Did you get a reading for RXD on the usb cable?

Is the DB9 RS232 cable straight or crossover? - just wondering as if it was the wrong on you would see nothing which is what you report.

countrypaul:
Since the ttl-rs232 appears to work when used pc USB -> esp32 -> ttl/rs232 converter -> rs232_to_usb_cable -> pc that suggests the converter works for at least some conditions. Others may be able to offer sugestions on the voltages. Did you get a reading for RXD on the usb cable?

Is the DB9 RS232 cable straight or crossover? - just wondering as if it was the wrong on you would see nothing which is what you report.

no i did not get a reading for RXD cable. i checked every single pin.
i just looked up the description of the cable and it seems to be straight. this indeed sounds like my problem.

EDIT: i just found conflicting information about the cable... now i think its a crossed one...

RS232 voltages are +/-3 to +/-25 1.16 is not a valid signal voltage.
Being pulled down some where? Not enough drive current?
Tx to Tx connections might give you this problem

zen85:
Oh i am onto something here.... i am measuring very different values when i compare the usb-rs232 to the ttl-rs232.

on the usb cable that works i measure:
RTS: 8,96V
CTS: 8,96V
TXD: -8,38V

on the ttl-rs232 i am measuring:
RXD: -6,08V
TXD: 1,16V

EDIT: i just measured the ttl-rs232 when connected the vcc line to 5V instead of 3.3 and now i am measuring this:
RXD: - 8,96V
TXD: 3.4V

so there is something quite wrong and i think i should look into that first :).
does anybody have an idea what i can do about this?

ARE you measuring to the RS-232 ground pin?
Paul

Paul_KD7HB:
ARE you measuring to the RS-232 ground pin?
Paul

yes i am. i am connecting the black line (COM) to the pin 5 of the cable (GND) and test through all the other pins with the red line.

whats really weird about the 1,16V is that the communication with the computer works. makes me think that the way i am measuring is flawed?

I never thought that i would run in so much trouble with rs232... but i feel great about it since i learned so much already and that people like you help me out with so much knowledge.

I also just ordered a straight 1:1 cable and hope this fixes my problems magically. but i also want to know why i am measuring invalid values while they provenly work...

zen85:
no i did not get a reading for RXD cable. i checked every single pin.
i just looked up the description of the cable and it seems to be straight. this indeed sounds like my problem.

EDIT: i just found conflicting information about the cable... now i think its a crossed one...

You should be able to check the cable easily enough with a multimeter, of if you don't have a multimeter handy, you can use a battery and bulb (or led with resistor). Better to check it than rely on an assumption or worse information supplied by those that don't really know!

countrypaul:
You should be able to check the cable easily enough with a multimeter, of if you don't have a multimeter handy, you can use a battery and bulb (or led with resistor). Better to check it than rely on an assumption or worse information supplied by those that don't really know!

the supplier himself gave conflicting information in the amazon-question-section. the datasheet on the homepage did not say anything about it (i am not kidding)... my measurements told me that it indeed is a crossed one. so i ordered a straight 1:1 serial cable. Thank you so much!

... and it keeps being weird :frowning:

i put in a gender changer between my rs232 ttl and my hdmi matrix: no need for a cable and the thing is not crossed... no need for a cable anyway i thought.

now i measure -6V on RXD and thats it - no other values. as i understood this seems valid but does not work and i get no reaction from the matrix whatsoever?

i also tried 3 different ttl modules just to be sure.

EDIT: I still also measure the 1.1V on TXD... with my gender-changer adapter AND with my, what i supposed was a crossed, cable... which is not so afterall then... why is all of this so strange? :slight_smile:

After some research I think i need the signal on RTS.

On the site posted above it says:

Other RS-232 Connection Problems

  • Handshaking lines RTS and CTS not interconnected, DTR and DSR not interconnected. Swap as needed.
  • Programs may use the RTS/CTS connection to check that a device is ready to receive data and respond. If there is No CTS connection, the program will never send data, but wait a long time or timeout with an error. The RTS line may need to be looped back to the CTS input. Data errors can occur if the device actually requires handshaking.

but how would i do that with such a ttl converter? I can just connect VCC, RX, TX and GND?