Pages: 1 2 [3]   Go Down
Author Topic: 10 servos, 10 potentiometers, issues  (Read 2299 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 14
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I just had another question come to mind. I've read somewhere that you can use a servo as a sensor. If thats the case, then with a SDcard shield would I be able to record live readings from the servos and play them back?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24450
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've read somewhere that you can use a servo as a sensor
Not without opening it up and doing some soldering (assuming we're talking R/C servo here) - do you have a link?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I've read somewhere that you can use a servo as a sensor.

That depends on what you want to sense. As AWOL says, if you want to get the physical position you would need to modify the servo. But if you want to play back a sequence of servo movements its much easier to either store the values (and time) that are written to the servos, or to regularly read and store the servo position using servo.read().

What is it you want to achieve.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi, my name is Guzz and i'm new on the arduino world. I'm having some trouble to write a code to control 4 servos with a arduino, and i dont know what can be wrong with my code, i'm not a programmer (yet). I wrote this code based on de sweep code from the arduino examples. The code compiles fine, but when i try to upload to the board it crashes. Im using the arduino duemilanove with atmega 328. The code is like this...

#include <Servo.h>
 
Servo myservo0;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos0 = 0;    // variable to store the servo position

Servo myservo1;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos1 = 0;    // variable to store the servo position

Servo myservo2;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos2 = 0;    // variable to store the servo position

Servo myservo3;  // create servo object to control a servo
                // a maximum of eight servo objects can be created
 
int pos3 = 0;    // variable to store the servo position
 
void setup()
{
  myservo0.attach(9);  // attaches the servo on pin 9 to the servo object
  myservo1.attach(smiley-cool;  // attaches the servo on pin 8 to the servo object
  myservo2.attach(7);  // attaches the servo on pin 7 to the servo object
  myservo3.attach(5);  // attaches the servo on pin 5 to the servo object
}
 
 
void loop()
{
  for(pos0 = 0; pos0 < 180; pos0 += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo0.write(pos0);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos0 = 180; pos0>=1; pos0-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo0.write(pos0);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos1 = 0; pos1 < 180; pos1 += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos1 = 180; pos1>=1; pos1-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo1.write(pos1);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos2 = 0; pos2 < 180; pos2 += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo2.write(pos2);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos2 = 180; pos2>=1; pos2-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo2.write(pos0);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos3 = 0; pos3 < 180; pos3 += 1)  // goes from 0 degrees to 180 degrees
  {                                  // in steps of 1 degree
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
  for(pos3 = 180; pos3>=1; pos3-=1)     // goes from 180 degrees to 0 degrees
  {                                
    myservo3.write(pos3);              // tell servo to go to position in variable 'pos'
    delay(5);                       // waits 15ms for the servo to reach the position
  }
}

If someone could please take a look and tell me what could be wrong i'd be most greatfull.

PS: I wasnt sure if i should create a new post, but since we are discussing servos and arduino here i was hoping no one would mind.

Thanks everybody
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24450
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you're powering the four servos from the Arduino, it is likely that the crash is due to the excessive current being drawn, pulling down the voltage to the processor and causing it to brown-out or reset.

Power the servos from a separate supply (4 AA batteries should do it), and remember to common the grounds.

I can't see anything obvious in your code that would cause a crash.

Please use the Code (#) button when posting code, and it is best not to hijack other threads.
« Last Edit: November 11, 2009, 08:20:09 am by AWOL » Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 5
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks, and sorry, not gonna do it again smiley
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 240
Posts: 24450
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

No worries.
We programmers are lazy types, so I re-wrote your sketch to make it a bit shorter: [uncompiled, untested]
Code:
#include <Servo.h>

Servo myservo [4];  // create servo object to control four servos

int pos [4] = 0;    // variable to store the servo position

void setup()
{
  myservo[0].attach(9);  // attaches the servo on pin 9 to a servo object
  myservo[1].attach(8);  // attaches the servo on pin 8 to a servo object
  myservo[2].attach(7);  // attaches the servo on pin 7 to a servo object
  myservo[3].attach(5);  // attaches the servo on pin 5 to a servo object
}

void loop()
{
  for (int i = 0; i < 4; ++i) {
      for(pos[i] = 0; pos[i] < 180; pos[i] += 1)  
    {                                  
       myservo[i].write(pos[i]);
       delay(5);                       // waits 5ms for the servo to reach the position
    }
    for(pos[i] = 180; pos[i]>=1; pos[i]-=1)     // goes from 180 degrees to 0 degrees
    {                                
       myservo[i].write(pos[i]);              // tell servo to go to position in variable 'pos'
       delay(5);                       // waits 5ms for the servo to reach the position
    }
  }    
}
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Pages: 1 2 [3]   Go Up
Jump to: