Go Down

Topic: myservo.attach makes servo moving (Read 584 times) previous topic - next topic

bubplup

Hello everyone,

When I use myservo.attach() the servo makes a move to the center position at start. How to overcome this. I want no movement.

Kind regards and thanks in advance,
Jan

JCA34F

90 degrees is the default startup position, but you can change it. For example, you want to start at 30 degrees:
Code: [Select]
void setup()
{
   servo.write(30);
   servo.attach(9);
}

If you want it to start in the position it was in at shutdown, you will have to save that position in EEPROM at shutdown and recall it at next startup.

bubplup

Thanks a lot but this does not solve my problem because if I start up i have to use myservo.attach () command and get the same problem or am I wrong?
Can this be done an other way?

vinceherman

A hobby servo always moves to the position you are commanding it to go.
If you do nothing before the attach(), the servo will move to 90 when you attach it.
If you write another position than 90 before you attach, the servo will move to that position when you attach it.
Standard servos know nothing of their position before they power up.

Some servos come with a 4th wire for external position sensing.  And some people have modified standard servos to have this position wire.
With this, you could read the position, command the servo to go to that position and then attach.
With this solution, it would be a fairly small jump when you power up.

Here is an example from Pololu

What is it that you are trying to do?

MarkT

Thanks a lot but this does not solve my problem because if I start up i have to use myservo.attach () command and get the same problem or am I wrong?
Can this be done an other way?
The servo only goes where you tell it, and there is no way to know where it currently is, so you cannot
prevent movement at startup unless you have a way of knowing where it currently is such as the EEPROM
idea.  The point of a servo is to slave to the position instructed.

Perhaps all you need to do is not attach it till the first time you want to move it?  I wouldn't be surprised
if some servos do their own thing without any signal for a long period - this would be a fault condition
in their intended use.

Perhaps you need something other than a servo for what you are trying to do - ie this is an xyproblem
[ I will NOT respond to personal messages, I WILL delete them, use the forum please ]

bubplup

@vinceherman: Thanks! that might be the solution: first give the position and then attach. I will try that.
4fh wire is not for me. I want it to work with standard servos.
I want to control a railway gate, so at power up you don't want the gate to move to 90 degree

@markt: that is just the point at attach the servo moves to 90 degree, that not what i want. I will try what vinceherman suggested, anyway thanks for reply!

bubplup

Yes, it works! So first do a servo.write then the servo.attach.
Thanks all!

Go Up