:smiley-roll-sweat: I am really loozing it…
been working on this for a while and tought I had it nailed, but I am getting some really strange comm issue,
that looks like timming. Aint a programmer so please dont laugh to hard… :~
Application monitors serial port for known commands;
S = All Stop
C= Give me your bearing (format of response AZ=BBB, where BBB is the bearing in degrees with leading zeros)
MBBB = Move to Bearing (BBB)
when the PC application driving the Arduino starts up, it starts polling for Bearing every second by sending
C’s. But the Arduino doesnt always respond…
My original issue was that the Arduino and the PC app would not link, to resolve this I had to insert a;
Serial.println();
It looked like the Arduino did not respond fast enough to the first C request for the PC app thus the PC apps considered
the link as failed and terminated…
then I noticed that the Arduino wasnt responding at all to the C commands, So I decided to insert a delay between the READ
command and the firts IF command to make certain the Arduino would be ready to respond to the data from teh serial port…
This did help… But… after tweeking the delay the best I can come up with is a response every second C command every
When I test the code manual using the serial terminal it works 100%…
I am assuming I aint dealing with the serial port properly and it could be optimised a LOT…
so here is my CRY for HELP!
… HELP! …
thanks in advance…
Richard ve2dx
void GetSerialData() {
serialdata = Serial.read();
Serial.println();
delay (1000);
if (serialdata == 'C') {
if (AZreal > 99) {
String GS232Boutput = (AZ + AZreal);
Serial.println(GS232Boutput);
}
else {
if (AZreal < 10) {
String GS232Boutput = (AZ00 + AZreal);
Serial.println(GS232Boutput);
}
else {
String GS232Boutput = (AZ0 + AZreal);
Serial.println(GS232Boutput);
}
}
}
if (serialdata == 'M') {
digitalWrite(CCW1output, LOW);
digitalWrite(CW1output, LOW);
digitalWrite(CW1speed, LOW);
int X = 0;
String serialstring;
while (X < 3) {
//Serial.println(X);
serialdata = Serial.read();
//serialdata = byte (serialdata);
serialstring = String (serialstring + serialdata);
//Serial.println(serialdata);
//Serial.println(serialstring);
X = X++;
}
AZrequested = serialstring.toInt();
AZtemp = AZreal;
}
if (serialdata == 'S') {
digitalWrite(CCW1output, LOW);
digitalWrite(CW1output, LOW);
digitalWrite(CW1speed, LOW);
AZrequested = AZreal;
//Serial.println(AZrequested);
}
:smiley-roll-sweat: