Hi!!
I'm new to the forum and to the Arduino programming and I would like your help.
I'm trying to implement a communication protocol between a software runnig at the PC and Arduino.
I've written a code for getting/sending commands from/into the Arduino but I'm facing a strange problem.
The first request response must be:
request -> #:GS#
response->13:25:54#
My code is this:
void loop(){
int index = 0;//the incoming message length
while (Serial.available()){//check for incoming message
delay(20);// Each character does 1ms in order to transfer
cmd[index] = Serial.read();//Stores the word and decreases the buffer
delay(1);
index++;
}
if (index > 0){
//Serial.print(cmd);
if (strcmp(cmd, "#:GS#") == 0){
Serial.print("13:25:54#");
}
}
}
When I test this with the Serial monitor it works well but in the PC software I cannot get the response.
This is due to the fact that the cmd array stores strange chatacters because when I uncomment the Serial.print(cmd) I get strange characters and the comparisson inside the if fails.
Although this doesn't happen when I test it with Serial Monitor.
Do you know what cause the problem?
I'm getting crazy with this.
