Pages: [1]   Go Down
Author Topic: Two servo pins doesn't work at the same time  (Read 784 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I have found somekind of explanation to my problem in here, but I can't solve it.

If have realized that when I define two servo pins with pinMode()-function, my arduino does just blink once the ledlight, waits some time and blinks again.

Here's my code:

Code:
int ledPin = 13;

void roller(int servoPin, int pulseLen) {
  digitalWrite(servoPin, HIGH);
  delayMicroseconds(pulseLen);
  digitalWrite(servoPin, LOW);
  delay(20);
}

void setup() {
  Serial.begin(115200);
  pinMode(2, OUTPUT);
  pinMode(3, OUTPUT);
  pinMode(ledPin, OUTPUT);
  digitalWrite(ledPin, HIGH);
}

void loop() {
   for (int i = 0; i <= 15; i++) {
   roller(2, 1800);
   roller(3, 1200);
   }
}

So if I define two pins with pinMode(), the servos doesn't work. Otherwise if I delete another of these defines, the arduino doesn't work. It doesn't matter wich one I delete. If I delete that one wich defines pin 2, the arduino works and servo in pin 3 works. If I delete define wich defines pin 3, the other servo works.

This is a little bit weird. Anyone have an answer or any questions?

Edit. I use Arduino Bluetooth ATMEGA 328
« Last Edit: October 05, 2010, 01:10:49 pm by Scionar » Logged

Portugal
Offline Offline
God Member
*****
Karma: 5
Posts: 962
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

How are you powering the servos, if it is trough the usb cable you are pulling to much current and that pull the voltage so low that the arduino keeps being reset.
Logged

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

Quote
How are you powering the servos, if it is trough the usb cable you are pulling to much current and that pull the voltage so low that the arduino keeps being reset.

I have 4,5 volts battery and my servos which I'm using are SM-S4303R -models. (http://www.pololu.com/catalog/product/1248)

But problem doesn't depend on am I trying to run the servos. Even if I just define them the arduino doesn't work and led just blinks one again.
« Last Edit: October 05, 2010, 10:43:29 am by Scionar » Logged

UK
Offline Offline
Faraday Member
**
Karma: 16
Posts: 2883
Gorm deficient
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe the servos don't like the 40ms+ frame length?

Any reason not to use the libraries?
Logged

Per Arduino ad Astra

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

Quote
I have 4,5 volts battery and my servos which I'm using are SM-S4303R -models

The link shows those to be ex-servos, ie they've been modified for continuous rotation.

Are you running the servos and the Arduino off the 4.5V battery?
The fact that the LED blinks suggests a brown-out, with the processor resetting.
Try running the servos off a battery, and the Arduino off the USB.
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: 7
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe the servos don't like the 40ms+ frame length?
Maybe, but if I can't even define two servos with pinMode()-functions what's the point?

Quote
Are you running the servos and the Arduino off the 4.5V battery?
The fact that the LED blinks suggests a brown-out, with the processor resetting.
Try running the servos off a battery, and the Arduino off the USB.

Yes, I'm trying to run it with 4,5V battery.
I forget to say that arduino what I use is Arduino BT. So I can't use USB.
Logged

Central Europe
Offline Offline
Edison Member
*
Karma: 6
Posts: 1220
Use the Source, Luke.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Maybe, but if I can't even define two servos with pinMode()-functions what's the point?

What's the point of doing it wrong? Not much I agree. As you've been told before, use the Servo library instead.

Korman
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31332
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
If I delete that one wich defines pin 2, the arduino works and servo in pin 3 works. If I delete define wich defines pin 3, the other servo works.
Your problem is either:-
1) Your battery can't supply enough current for two servos.
2) Your servos are generating so much noise on the power rail you are resetting the arduino.
Possible Solutions:-
1) Use a separate battery to power the motor and the arduino (but connect the grounds together)
2) Add some large decoupling capacitors across the supply, 47uF or larger along with a 0.1uF ceramic in parallel.
Logged

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

Quote
Your problem is either:-
1) Your battery can't supply enough current for two servos.
2) Your servos are generating so much noise on the power rail you are resetting the arduino.
Possible Solutions:-
1) Use a separate battery to power the motor and the arduino (but connect the grounds together)
2) Add some large decoupling capacitors across the supply, 47uF or larger along with a 0.1uF ceramic in parallel.

Ok. I have to test those options tomorrow. But I am amazed. Because can even defining of ports with pinMode()-functions took so much power?
Logged

Manchester (England England)
Offline Offline
Brattain Member
*****
Karma: 505
Posts: 31332
Solder is electric glue
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Because can even defining of ports with pinMode()-functions took so much power?
Once a pin is defined as an output it is driving the pin at a zero or a one, so defining the pin to be an output not only makes it an output but also drives it to one level.

Note there is absolutely no need for the line:-
for (int i = 0; i <= 15; i++) {
because loop() repeats the code, all it will do is add a bit of jitter to the motion.
Logged

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

I did get for my servos another batteries and now they work kind of. I have lots of bugs to fix.

Quote
Once a pin is defined as an output it is driving the pin at a zero or a one, so defining the pin to be an output not only makes it an output but also drives it to one level.

Ok. I try to understand. My english isin't the best possible and thease things are so new and mystical for me.

Quote
Note there is absolutely no need for the line:-
for (int i = 0; i <= 15; i++) {
because loop() repeats the code, all it will do is add a bit of jitter to the motion.

That's true. I copypasted it from my bigger source and forget to remove that.
« Last Edit: October 05, 2010, 02:28:01 pm by Scionar » Logged

Pages: [1]   Go Up
Jump to: