Hi All,
I've got a simple sketch that reads the output from a Laptop's RS232 DB9 connector and then is meant to display the same character on a LCD connected to a Arduino Mega 2560.
Each character is also supposed to be sent from the software serial port, which I can read using the serial monitor on another PC which is connected to the Arduino via USB.
eg.
Laptop 1 ------------ ARDUINO <USB (com7)>----------- Laptop 2
|
|
Terminal Program LCD Serial Monitor
Every time I enter a character on Laptop 1's Terminal Program, I see a corresponding character on both the Arduino's LCD and Laptop 2's Serial Monitor.
The problem is that the character typed into Laptop 1's Terminal Program is not what is being displayed on the Arduino LCD and Laptop 2.
Somehow the data is being translated, however I haven't been able to identify how or why it's happening.
If I program the Arduino with a simple sketch to display "hello world" onto the LCD, it is displaying correctly on both the LCD and the Laptop 2 Serial Monitor.
An example of the translated data is as follows:
COM1 Input COM7 & LCD Display
HEX BINARY DECIMAL HEX BINARY DECIMAL
61 0110 0001 97 4F 0100 1111 79
62 0110 0010 98 27 0010 0111 39
63 0110 0011 99 4E 0100 1110 78
64 0110 0100 100 13 0001 0011 19
65 0110 0101 101 4D 0100 1101 77
66 0110 0110 102 26 0010 0110 38
67 0110 0111 103 4C 0100 1100 76
68 0110 1000 104 09 1001 1001 9
69 0110 1001 105 4B 0100 1011 75
6A 0110 1010 106 25 0010 0101 37
6B 0110 1011 107 4A 0100 1010 74
6C 0110 1100 108 12 0001 0010 18
6D 0110 1101 109 49 0100 1001 73
6E 0110 1110 110 24 0010 0100 36
6F 0110 1111 111 48 0100 1000 72
70 0111 0000 112 04 0100 0100 4
71 0111 0001 113 47 0100 0111 71
72 0111 0010 114 23 0010 0011 35
73 0111 0011 115 46 0100 0110 70
74 0111 0100 116 11 0001 0001 17
75 0111 0101 117 45 0100 0101 69
76 0111 0110 118 22 0010 0010 34
77 0111 0111 119 44 0100 0100 68
78 0111 1000 120 08 1000 1000 8
79 0111 1001 121 43 0100 0011 67
7A 0111 1010 122 21 0010 0001 33
The sketch is as follows:
#include<LiquidCrystal.h>
LiquidCrystal lcd(12,11,5,4,3,2);
byte ch;
int col=0;
int row=0;
void setup() {
Serial.begin(4800);
Serial1.begin(4800); //pins 18 TX ,19 RX
//Serial1.begin(4800,SERIAL_8N1); //pins 18 TX ,19 RX
lcd.begin(16,2);
lcd.clear();
}
void loop() {
if(Serial1.available()){
char ch=Serial1.read();
Serial.write(ch);
// Serial.println();
lcd.setCursor(col,row);
lcd.write(ch);
col++;
if(col>15){
row++;
col=0;
lcd.write(ch);
}
}
if(ch=='*' ||row==1&&col>=15){
lcd.clear();
col=0;
row=0;
}
}
I also have a serial port debugger program on both laptops and both debuggers are confirming that the correct code is leaving Laptop 1 Serial Port (Com1) and that the translated code is being sent from the Arduino Serial Port (Com7)
Any ideas or assistance would be welcomed.
Thanks in advance.