Hi,
I have a serial device connected to serial1 on my mega.
I uploaded the multiple serial example to my mega.
If i type in the arduino ide serial terminal the command: PS=1
The device connected to serial 1 responds as it is supposed to. So far so good.
Next step: dont type the command in the serial window, but put it in the sketch.
This is the sketch i have made:
void setup() {
// initialize both serial ports:
Serial.begin(9600); // PC
Serial1.begin(9600); // OTG
Serial.print("Program started: ");
// Enable print summary
delay(1000);
Serial1.write('PS=1\r\n');
}
void loop() {
// read from port 1, send to port 0:
if (Serial1.available()) {
int inByte = Serial1.read();
Serial.write(inByte);
}
// read from port 0, send to port 1:
if (Serial.available()) {
int inByte = Serial.read();
Serial1.write(inByte);
}
}
The problem is, the slave device does not responds to this command while it does when i type the same command in the terminal.
I have tried serial1.println, serial1.write("PS=1")
serial1.write("PS=1\r\n") etc etc. It does not seem to work. I think it has something to do with NL and CR
Can someone please help me with this problem? This is the first time i try to work with multiple serial devices.
So the summary of my question:
How do i send the same data over the serial1 port using code, as what's send when i type in PS=1 with NL and CR enabled.