Hello Guys,
i have a working system with 2x Arduino Uno. The first one sends continously values to the second one. It works fine (testing with Serial.print).
My Issue:
I want to write the values to servos. But if the servo begins to move, Arduino doesnt receive new message. It looks like he stuck in the function "myServo.write()".
For my application, it is necessary to receive as much as possible messages. So its not okay. Do you Guys know a solution?
P.s: I use "ServoTimer2.h" instead of "Servo.h" because of library-conflict with Virtualwire.
Necessary receive Code:
if (vw_get_message(buf, &buflen)) //Einlesen des Wertes und in buf speichern
{
for (int i = 0; i < buflen; ++i) //Checking what the buffer holds
{
if(i<buflen-2) //nur die ersten 4 Zeichen auslesen; 2 weglassen (.0)
{
rx_data = buf[i] - '0'; //Umwandeln des ASCII-Wertes in reele Zahl {z.B. '9' = 57(ascii), '0' = 48(ascii) --> rxdata = 57 - 48 = 9}
value += rx_data * pow(10,3-i); //Potenzieren der einzelnen Werte mit 10^3, 10^2, 10^1 bzw. 10^0
}
}
//Auswerten des Streams
value -= 2000; //2000 Offset subtrahieren
if(value <= 360) //Abfrage ob Compassdata
{
value_comp = value; //Abspeichern in value_comp
}
else //Wenn nicht Compassdata, dann Neigungsdata
{
value -= 1000; //weitere 1000 Offset subtrahieren, da sicher Neigungsdata
value_neig = value; //Abspeichern in value_neig
}
//Kompass-Ausrichtung
if(value_comp > -90 && value_comp <90){
send_comp = map(value_comp, -90, 90, 750, 2250); //Servo Skalierung
if(oldCompass < send_comp){
for(oldCompass; oldCompass <= send_comp; oldCompass+=5){
servo1.write(oldCompass);
delay(10);
}
}
else if(oldCompass > send_comp){
for(oldCompass; oldCompass >= send_comp; oldCompass-=5){
servo1.write(oldCompass);
delay(10);
}
}
oldCompass = send_comp;
}
else if (value_comp <= -90){
servo1.write(750);
}
else if (value_comp >= 90){
servo1.write(2250);
}
else{
servo1.write(750);
}
I think this guy has the same issue:
http://forum.arduino.cc/index.php?topic=261310.0
Well, i build a 1 meter cable, so the servo is far away from the RX-Module. it doesnt make a difference to the normal 5cm cable.
So "electrical noise" can't be the reason..