I’ve recently bought an ESP32 C3 SuperMini from AliExpress to read RS232 data from an AIS transponder (it’s a ship position device). I set it up and got scrambled data from the serial. I then tried to connect the ESP32 directly to the COM-port of my computer and it seems like I get scrambled data regardless of my setup.
I’ve made sure that the RS232 connection is grounded.
I use the GPIO pin 20 as RX and GPIO pin 21 as TX. This is defined as "UART"-pins by the seller.
I have made sure that I use the same settings on both devices (Baud rate, parity, data bits, stop bits)
I have tested other pins with no luck.
I have tested choosing different boards like "Nologo ESP32C3" and "XIAO_ESP32C3" with no luck. "ESP32C3 Dev Module" was recommended by the seller.
My code:
void setup() {
Serial.begin(115200);
Serial1.begin(38400, SERIAL_8N1, 20, 21);
}
void loop() {
if (Serial1.available() > 0) {
Serial.println("Serial data is available!");
String str = Serial1.readString();
str.trim();
Serial.println(str);
}
}
If I send “test”, I get “QSt?” from the ESP32.
I’m a newbie at microcontroller programming and it feels like I’m doing some stupid mistake. Any help is appreciated.
Actually, the AIS device has two different ports, one RS232 and one RS422 for NMEA output. It's the RS422 port that i actually wanted to use, so I have a RS422 to TTL module. When testing with the module and the RS422 port i got scrambled data so I thought I would "simplify" the setup and test the RS232 port instead. As I could connect it directly to my computer, I just assumed that I could connect it directly to the ESP32
But even with using the TTL-module I get data like this:
Expected output:
!AIVDO,1,1,,,B0000003wk?8mP=18D3Q3wv5sP06,0*02
Output from ESP32:
o_[�W�������{�������)��%_���w�]��_���������
Returning to the basic test which you conducted using "open serial port monitor", which you described in post #1, can you explain what you connected to ESP32 C3 pins 20 and 21 and what device created port COM1 on your PC ?
I've not seen this method of integrating a PC directly with an ESP32 device and I can't comment on the validity of the choice of pins. I can just make the general comments that (a) it is usual to use a USB/UART adapter for such an integration and (b) the ESP32 pins are 3.3 volts (with a small tolerance).
Try a different set of pins for UART1 (Serial1). 20 and 21 appear to be dedicated to UART0 (Serial) as far as I can see which you are already using for the serial console.
Try pins 3 and 4 for example.
Turns out NMEA is 3,3V from the beginning. I tested to connect the NMEA negative output to the RX PIN 20 on the ESP32 and finally got this output:
12:00:45.388 -> Serial data is available!
12:00:46.403 -> !AIVDO,1,1,,,B0000003wk?8mP=18D3Q3wv5sP06,0*02
Thank you very much for pointing me in the right direction!!
But now I'm not sure if I still should get a 3,3V RS422 module? May I damage the ESP32 or the AIS device without it?
If it says RS232 and not 5V or 3V or TTL then it can be positive and negative voltages as high as 25V and that will certainly damage the ESP. I don't think NMEA specifies a voltage.
Can you post a datasheet or operators manual for your AIS device. Maybe we can see what it actually outputs.