Pages: [1]   Go Down
Author Topic: perhaps a little help with servo control??  (Read 699 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
architecture | media | computing
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello everyone,

Here's my goal, its pretty simple - just a little prototype for a larger project....

I need to be able to control 9 servo's from one board (Decimilia) independently.  I'm a bit new at writing code however, so my approach was to write separate functions for each servo, and then call those functions in a main loop in whatever order was necessary to achieve the desired effect.  

I have some code that simply runs all of them at once, (just a test to see if my power supply was sufficient) -
how could I modify this or re-write the code to get independent control and get to a choreographed sequence of actuations?

Code:

#define SERVOa 13
#define SERVOb 12
#define SERVOc 11
#define SERVOd 10
#define SERVOe 9
#define SERVOf 8
#define SERVOg 7
#define SERVOh 6
#define SERVOi 5


#define MIN_PULSE 600
#define MAX_PULSE 2400
#define DELTA 1800


int lastPulse = 0;
int refreshTime = 20;

long randNumber;

void setup()
{
  int i;
  pinMode(SERVOa, OUTPUT);
  pinMode(SERVOb, OUTPUT);
  pinMode(SERVOc, OUTPUT);
  pinMode(SERVOd, OUTPUT);
  pinMode(SERVOe, OUTPUT);
  pinMode(SERVOf, OUTPUT);
  pinMode(SERVOg, OUTPUT);
  pinMode(SERVOh, OUTPUT);
  pinMode(SERVOi, OUTPUT);
  
  digitalWrite(SERVOa, LOW);
  digitalWrite(SERVOb, LOW);
  digitalWrite(SERVOc, LOW);
  digitalWrite(SERVOd, LOW);
  digitalWrite(SERVOe, LOW);
  digitalWrite(SERVOf, LOW);
  digitalWrite(SERVOg, LOW);
  digitalWrite(SERVOh, LOW);
  digitalWrite(SERVOi, LOW);

  
  Serial.begin(9600);
  for (i=0; i<10; i++)
  {
    digitalWrite(SERVOa, HIGH);
    digitalWrite(SERVOb, HIGH);
    digitalWrite(SERVOc, HIGH);
    digitalWrite(SERVOd, HIGH);
    digitalWrite(SERVOe, HIGH);
    digitalWrite(SERVOf, HIGH);
    digitalWrite(SERVOg, HIGH);
    digitalWrite(SERVOh, HIGH);
    digitalWrite(SERVOi, HIGH);
    
    delayMicroseconds((MIN_PULSE + MAX_PULSE)/2);
    
    digitalWrite(SERVOa, LOW);
    digitalWrite(SERVOb, LOW);
    digitalWrite(SERVOc, LOW);
    digitalWrite(SERVOd, LOW);
    digitalWrite(SERVOe, LOW);
    digitalWrite(SERVOf, LOW);
    digitalWrite(SERVOg, LOW);
    digitalWrite(SERVOh, LOW);
    digitalWrite(SERVOi, LOW);
    
    delay(20);
  }
  Serial.println("servo should be at center");

  delay(20);
}

void loop()

{
  int i;
  static int pulse_width;
  
  randNumber = random(600, 2400);
  delay(3000);
  
  pulse_width = randNumber;
  Serial.println(pulse_width, DEC);
  
 /*
  if (millis() - lastPulse >= refreshTime) {
    digitalWrite(SERVOa, HIGH);
    digitalWrite(SERVOb, HIGH);
    digitalWrite(SERVOc, HIGH);
    digitalWrite(SERVOd, HIGH);
    digitalWrite(SERVOe, HIGH);
    digitalWrite(SERVOf, HIGH);
    digitalWrite(SERVOg, HIGH);
    digitalWrite(SERVOh, HIGH);
    digitalWrite(SERVOi, HIGH);
    
    delayMicroseconds(pulse_width);
    
    digitalWrite(SERVOa, LOW);
    digitalWrite(SERVOb, LOW);
    digitalWrite(SERVOc, LOW);
    digitalWrite(SERVOd, LOW);
    digitalWrite(SERVOe, LOW);
    digitalWrite(SERVOf, LOW);
    digitalWrite(SERVOg, LOW);
    digitalWrite(SERVOh, LOW);
    digitalWrite(SERVOi, LOW);
    
    delay(20);
    
    lastPulse = millis();
  }
}
*/
  
    for (i=0; i<100; i++)
 {
      digitalWrite(SERVOa, HIGH);
      digitalWrite(SERVOb, HIGH);
      digitalWrite(SERVOc, HIGH);
      digitalWrite(SERVOd, HIGH);
      digitalWrite(SERVOe, HIGH);
      digitalWrite(SERVOf, HIGH);
      digitalWrite(SERVOg, HIGH);
        digitalWrite(SERVOh, HIGH);
        digitalWrite(SERVOi, HIGH);

      delayMicroseconds(pulse_width);

      digitalWrite(SERVOa, LOW);
      digitalWrite(SERVOb, LOW);
      digitalWrite(SERVOc, LOW);
      digitalWrite(SERVOd, LOW);
      digitalWrite(SERVOe, LOW);
      digitalWrite(SERVOf, LOW);
      digitalWrite(SERVOg, LOW);
        digitalWrite(SERVOh, LOW);
        digitalWrite(SERVOi, LOW);

      delay(20);
  }
}
 


thanks in advance !!
« Last Edit: September 02, 2007, 04:07:40 pm by daidalos » Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 731
skcor oniudrA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Q. Was the supply adequate to power all 9 servo's ?
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
architecture &#124; media &#124; computing
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Q. Was the supply adequate to power all 9 servo's ?


well .. somewhat ... smiley-wink

I'm running a 9v 500Ma power supply - it pushes them all at once, however there is a slight lag time on some of them, and I could see that they're not running at full speed or power.

Leads me to believe that it could be two things - the refresh time in the code is too long for this amount of motors, or I need more amperage.
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

running that many servos on so little current is goign to spell trouble.
You need at least a couple amps to power 9 servos properly.... they draw 1/4A easy.
They should be on a separate power supply too-- not on the Arduino supply.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 28
architecture &#124; media &#124; computing
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
running that many servos on so little current is goign to spell trouble.
You need at least a couple amps to power 9 servos properly.... they draw 1/4A easy.  
They should be on a separate power supply too-- not on the Arduino supply.  

ok thanks, I'll look for another power supply
Logged

Daniel
Guest
 Bigger Bigger  Smaller Smaller  Reset Reset

yes try and run them separately... feeding the servos with a 6V battery would be perfect.
Logged

Pages: [1]   Go Up
Jump to: