Arduino yun moving servo motor via wifi

hi..i'm using the example code of arduino --> http://arduino.cc/en/Tutorial/Bridge

and i added instructions to move a servo motor.. as you can see:

void digitalCommand(YunClient client) {
int pin, value;
Servo servo;

pin = client.parseInt();

if (client.read() == '/') {
value = client.parseInt();
digitalWrite(pin, value);
Serial.println("servo write 0");
delay(1000);
servo.attach(11);
servo.write(0);
delay(1000);
servo.write(90);
delay(1000);
servo.detach();
}
else {
value = digitalRead(pin);
}

client.print(F("Pin D"));
client.print(pin);
client.print(F(" set to "));
client.println(value);

String key = "D";
key += pin;
Bridge.put(key, String(value));
}

this code work once time..and effectively move the servomotor when i send "http://192.168.1.53/arduino/digital/13/1", but few second after move, the program stop the execution and the internet conection get down..so if i try send a new request the browser show me: "Could not connect to YunServer 146 Connection refused".
finally if i delete the servo instruction the program work perfectly...what would be the problem???? i hope yours answer . thank youuu

I don't have experience with the servo library, but I notice that the examples all use a global servo object instance and keep it attached. On the other hand, yours is local to the function so on each pass the servo object is created, attached, detached, and destroyed. Maybe it doesn't like that? Have you tried making the servo object global, attaching it in setup(), and then just updating the position in digitalCommand() with no detach?

Another reason for doing that: I assume that when the servo object is detached, the output pulse stream stops. With no input signal, a servo might be susceptible to input noise which could cause random movement. Whenever I've used a servo, I try to make it a point that it always receives a valid pulse stream.

I had the same problem but with 2 servo moteur in a moteur shield and this disconnect because of the power...

Indeed after every step you need to release your moteur more a little delay... It's the only thing I have find

like this (I use AFMotor librairie):
void gauche(YunClient client)
{
int nombreTour = client.parseInt();
int pasMoteur = 0;
for(pasMoteur=0;pasMoteur<=nombreTour;pasMoteur++)
{
client.println(pasMoteur);
//Mes moteurs sont montés a l'envers donc pour que mon robot aille tout droit il faut que les moteurs tournent dans 2 sens différents
motor1.step(1, BACKWARD, DOUBLE);
motor1.release(); // On release les moteurs pour pas qu'ils prennent trop de puissance.
delay(20);
motor2.step(1, BACKWARD, DOUBLE);
motor2.release();
delay(20);
}
}

robotLabo:
I had the same problem but with 2 servo moteur in a moteur shield and this disconnect because of the power...

It looks like you might be using stepper motors and not servo motors? When stopped, a stepper motor will still use a significant amount of power to hold its position, unless you de-energize the motor coils. From your description it sounds like you have a limited power supply that can't power both motors at once, so it makes sense that you wold have to release one motor, wait a bit for the current to stabilize, and then turn on the other other motor.

But a servo motor is different: it shouldn't be drawing a lot of power when the position is stable and the motor isn't turning. Furthermore, it has some intelligent control electronics in it looking for a variable width pulse stream -- if the servo is powered up, and the input is floating, it could pick up noise on the input that could lead to erratic behavior.

Yes you have right a little confusion... I am ashamed. And all you have said is just and I know but I do with what I have and it's difficult ^^

But a reason of a crash of Yun server is the lack of electric power maybe that can help if the servo doesn't work with 5 volts.

I fine the especify problem..i changed my setup as you can see:

void setup()
{
// servo.attach(9); --> problem line
delay(1000);

Serial.begin(9600);
delay(1000);
Bridge.begin();
delay(1000);
server.listenOnLocalhost();
delay(1000);
server.begin();
}

and the program stops when i execute de comand "servo.attach".. if i comment that line the program run correctly..what would be the reason?

robotLabo:
I am ashamed.

I'm sorry about that. It was not my intention to make you feel bad. Please accept my sincere apologies.

But a reason of a crash of Yun server is the lack of electric power maybe that can help if the servo doesn't work with 5 volts.

A very good point. Servos typically draw less power than a stepper motor, but they can still draw too much power from a small voltage regulator, and such power draws can cause strange program behavior. If the Yun is powered through the USB, and the Yun is powering the servos, that could be too much current for the USB power supply.

If it isn't done that way already, the servo(s) should be powered by their own 5v supply, with the a Yun powered separately. Just make sure the grounds of the two supplies are tied together.

@#5: I am having the same problem. But turning off the servo is not a solution.
I guess Arduino Yun is a good idea, but right now it is just not there. This is obviously a nasty bug making the product look bad. I have to switch back to Arduino Uno Wifi.

jiejunkong:
This is obviously a nasty bug making the product look bad.

I don't see how this is in any way a bug with the Yun.

The discussion in this thread is about not supplying a system with enough power. Powering a board through the USB connector limits you to a total power budget of 500 mA. That's not enough to power the Yun with it's Linux processor and WiFi interface and also heavy draw loads like servo and stepper motors.

When driving heavy draw loads, it is prudent to give those loads their own power supply, and not try to power them directly from the development board, and certainly not through a USB port. This is not unique to the Yun, it's simply good electrical design. You may get away with powering your motors from the board with lower power development boards, but that doesn't make it a good technique, and doesn't mean that a higher power board has a bug when you run out of power.

The Yun does indeed draw more power than an Arduino Uno Wifi - that's not a bug, it's a feature: it's a side effect of having all of the additional capabilities from the Linux processor, extra memory, SD card storage, USB interface, Ethernet port, etc - it takes power to drive all of that stuff that the Arduino Uno WiFi doesn't have. TANSTAFL - there is no such thing as a free lunch.