Go Down

Topic: Two servo pins doesn't work at the same time (Read 1 time) previous topic - next topic

Scionar

Oct 05, 2010, 05:13 pm Last Edit: Oct 05, 2010, 08:10 pm by Scionar Reason: 1
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: [Select]

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

Senso

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.

Scionar

#2
Oct 05, 2010, 05:42 pm Last Edit: Oct 05, 2010, 05:43 pm by Scionar Reason: 1
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.

Groove

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

Any reason not to use the libraries?
Per Arduino ad Astra

AWOL

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.
"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.

Scionar

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.

Korman

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

Grumpy_Mike

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.

Scionar

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?

Grumpy_Mike

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.

Scionar

#10
Oct 05, 2010, 09:27 pm Last Edit: Oct 05, 2010, 09:28 pm by Scionar Reason: 1
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.

Go Up