I can't get my Arduino Mega or my ESP32 to properly send serial commands with my videoprojector. Same when replacing the videoprojector by a PC or Linux having a USB-to-RS232 connected to debug serial signals.
However when doing serial communication between two Arduino or ESP32 boards, all works fine.
In my troubleshooting steps, I tried to receive a known working signal with the Arduino Mega Serial1, to verify if it detects well the serial data as a receiver.
As controlling the videoprojector from a Linux machine using the USB-to-RS232 works fine, I'm replacing the videoprojector by an Arduino Mega serial RX1 and TX1 pins (wiring = GND to GND, Linux' TX to Arduino's RX1, Linux' RX to Arduino's TX1), and run the following sketch:
int receivedInt = 0;
char receivedChar = ' ';
void setup() {
Serial.begin(115200);
Serial.println("Serial Monitor started");
Serial1.begin(9600, SERIAL_8N1);
Serial.println("Serial1 connection to Linux's USB-RS232 started");
}
void loop() {
while(Serial1.available())
{
receivedInt = Serial1.read();
receivedChar = char(receivedInt);
Serial.print("hex: 0x");
Serial.print(receivedInt, HEX);
Serial.print(", char: '");
Serial.print(receivedChar);
Serial.print("'");
Serial.println();
}
}
On Linux, I run the following command, which would succesfully turn on the videoprojector if connected:
echo -n -e "~0000 1\r" > /dev/ttyUSB0
Let me add that the serial port on Linux has the proper default settings:
Linux# stty -F /dev/ttyUSB0 --all
speed 9600 baud; rows 0; columns 0; line = 0;
intr = ^C; quit = ^\; erase = ^?; kill = ^U; eof = ^D; eol = <undef>; eol2 = <undef>; swtch = <undef>; start = ^Q; stop = ^S; susp = ^Z; rprnt = ^R; werase = ^W; lnext = ^V; discard = ^O; min = 1; time = 0;
-parenb -parodd -cmspar cs8 hupcl -cstopb cread clocal -crtscts
-ignbrk -brkint -ignpar -parmrk -inpck -istrip -inlcr -igncr icrnl ixon -ixoff -iuclc -ixany -imaxbel -iutf8
opost -olcuc -ocrnl onlcr -onocr -onlret -ofill -ofdel nl0 cr0 tab0 bs0 vt0 ff0
isig icanon iexten echo echoe echok -echonl -noflsh -xcase -tostop -echoprt echoctl echoke -flusho -extproc
I'm expecting to receive each character on the command "~0000 1\r" (in hexa: 7E 30 30 30 30 20 30 0D) on the Arduino serial monitor.
Instead I can read the following stuff:
23:59:54.348 -> hex: 0xA0, char: '�'
23:59:54.348 -> hex: 0xF6, char: '�'
23:59:54.348 -> hex: 0xF6, char: '�'
23:59:54.394 -> hex: 0xF6, char: '�'
23:59:54.394 -> hex: 0xF6, char: '�'
23:59:54.394 -> hex: 0xEB, char: '�'
23:59:54.394 -> hex: 0xE5, char: '�'
23:59:54.394 -> hex: 0x0, char: ''
These hex values have nothing to do with the original message. It looks like a baud rate mismatch, however everything is set correctly.
I've tried to replace SERIAL_8N1 by other values, without success.
I've tried changing the baud rate on Arduino side with other values, without success.
The same problem happens the other way around, when I send serial data from Arduino to the USB-to-RS232 connected to a PC with PuTTY open with proper serial port settings. The same incorrect characters get printed out on the PuTTY console.
I'm starting to believe that the Arduino/ESP32 boards are not doing real 9600 8N1 serial, but something different that only works between Arduino/ESP32 boards. I wish I had an oscilloscope to analyze what the Arduino is outputting on its TX1 pin, but I don't have one.
Does anybody have a clue of what is going on or what I'm doing wrong?
Thanks a lot in advance for the help.
