Pages: [1]   Go Down
Author Topic: How to stop tilt servo centering while booting up?  (Read 1147 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

i ripped the thread topic from a post on a related forum.
my servo centers on boot. its a problem as every time i reset/boot the arduino the servos jump  to mid-tilt position.

i tried
Code:
#include <Servo.h>

Servo panS;  
Servo tiltS;    

int tiltMin=60;
int panMin=0;


void setup()
{

  panS.attach(9);  // attaches the servo on pin 9 to the servo object
  tiltS.attach(10);

  //on wake up smoothly bring pan and tilt to start
  for(int pos = 93; pos>=panMin; pos--) {
    panS.write(pos);
    delay(33);
  }
  for(int pos = tiltS.read(); pos>=tiltMin; pos--) {
    tiltS.write(pos);
    delay(33);
  }
}
void loop()
{}

but if i try to servo.read() i always get 93. no matter the location.
i found this bit on an old documentation page
Quote
Safety Quirk

Even though you attach a servo, it won't receive any control signals until you send its first position with the write() method to keep it from jumping to some odd arbitrary value.
but what help is that?
im surprised it hadn't been mentioned.
if i haven't searched enough please enlighten.
keywords: servo, jerk, startup, boot
Logged

Massachusetts, USA
Offline Offline
Tesla Member
***
Karma: 212
Posts: 8976
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You can set the initial position of a servo before you attach it.  If you don't set the initial position I believe it defaults to centered. 

It's not clear from your code where you want the servos to start. 

Code:
#include <Servo.h>
Servo panS; 
Servo tiltS;
...

void setup()
{
  panS.write(panInitialPosition);
  panS.attach(9);  // attaches the servo on pin 9 to the servo object

  tiltS.write(tiltInitialPosition);
  tiltS.attach(10);
...


If you don't want them making any sudden moves you will need to remember where they were when you turned off the power. For that you will have to use some form of non-volatile memory like the built-in EEPROM.
Logged

Send Bitcoin tips to: 1L3CTDoTgrXNA5WyF77uWqt4gUdye9mezN
Send Litecoin tips to : LVtpaq6JgJAZwvnVq3ftVeHafWkcpmuR1e

0
Offline Offline
Jr. Member
**
Karma: 1
Posts: 91
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the code logic is:
on startup, read last resting place of servo position and from there write slowly to fixed start position

i will try the EEPROM way, thanks
Logged

Pages: [1]   Go Up
Jump to: