I'm trying to send the Servo position of my Robot arm simulator from iPad.
I'm currently using and arduino Leonardo and a RedBearLab BLEMini dongle.
The thing is, i want to keep sending the Servos values every .01 seconds -or when the servo value changes (almost every .01 seconds)-. I have 4 servos, and i'm trying to find the best way to move them.
I've tried with one servo every .01 seconds, but the arduino got stucked. I also tried on refreshing every .05 seconds and the servo did move as expected. I think there might be a problem with the servo.write routine that delays the micro so much and the servo didn't get to move. I also think that the problem may be the baudrate or something that makes the serial module to have a problem. Do you guys have any ideas?
The code looks like this
#include <ble_mini.h>
#include <Servo.h>
Servo myservo;
Servo myservo2;
Servo myservo3;
Servo myservo4;
void setup()
{
BLEMini_begin(57600);
myservo.attach(9);
myservo2.attach(10);
myservo3.attach(11);
myservo4.attach(13);
}
void loop()
{
// If data is ready
while ( BLEMini_available() == 2 )
{
//read out command and data
byte data0 = BLEMini_read(); //the servo that is going to move
byte data1 = BLEMini_read();
if (data0 == 0x01)
{
myservo.write(data1);
}
if (data0 == 0x02)
{
myservo2.write(data1);
}
else if (data0 == 0x03)
{
myservo3.write(data1);
}
else if (data0 == 0x04)
{
myservo4.write(data1);
}
else if (data0 == 0x05) // Command is to reset
{
myservo.write(90);
myservo2.write(90);
myservo3.write(90);
myservo4.write(90);
}
}
}