I'm writing a project where an Arduino board that is connected to a servo engine receives commands from another Arduino. The possible commands are:
- Move 10 degrees
- Reset position
- Sweep until you're told to stop
My problem is with the sweep-mode, when I get the sweep command, I get into a while loop, that first checks for a sweep-terminator and then sweeps.
} else if (message == sweep) {
Serial.println("sweep");
while (msg1 != sweep_term) {
// set the direction for the servo to move
if (val == 750){
val = 2250;
} else {
val = 750;
}
// move the servo
myservo.write(val);
// wait for the servo to move
delay(15);
// wait for a message
if (vw_get_message(buf1, &buflen1)) {
buf1[buflen1] = '\0';
msg1 = (char*)buf1;
memset(buf1,'0',VW_MAX_MESSAGE_LEN);
Serial.print(buflen1);
Serial.print(" [sweep] Got: ");
Serial.println(msg1);
}
}
}
For some reason, when I'm in this loop I don't get the sweep terminator message, or I get a part of it. I suspect that the servo is responsible for this, since when I run the same program without myservo.write()
s I do receive those terminators.
memset(buf1,'0',VW_MAX_MESSAGE_LEN);
does?String
, notchar *
msg1
andbuf1
.I suspect that the servo is responsible for this
- can you run the code, with themyservo.write()
but without the servo physically connected. This will eliminate a possible electrical problem.