Hi every body, not sure it s the right place for this post.
I have an uno board, and i would like to pilot more than 2 servos, but i read that servo.h can only pilot 2 servos!!!
So i would like to know if it's possible to do it another way.
i thought about use a simple analog write but didn't work... here what i ve tried:
setup()
{pinMode(5,OUTPUT);}
loop()
{
analoWrite(5,120);
delay(1000);
analogWrite(5,255);
delay(1000);
}
Hi,
And here is why analogWrite didn't work for you (see link), the post refers to reading a signal from an RC Receiver and outputting it to an electronic speed controller, but signal is the same as a servo signal, in fact I use the servo library to drive the electronic speed controller.
thx a lot obviously i didin't read well, it was for old version or arduino!
i saw people pluging servo's pwm pin in an alalog in, how it could be works? are analog in able to generate a pwm signal???
here where i found this strange thing: http://arduino.cc/playground/Learning/SingleServoExample
The analogue input pins can be used as digital input / output pins. They can not generate PWM through the arduino's hardware but there is nothing to stop you using a software PWM sketch to drive these pins.
It uses software, you have to keep calling this function:-
static void refresh(); // must be called at least every 50ms or so to keep servo alive
// you can call more often, it won't happen more than once every 20ms
That keeps updating the pulses. A servo uses PPM Pulse Position modulation not PWM (Pulse width modulation)
By the way pilot is the word used to fly an aircraft or navigate a ship, you drive servos.
WAOH!!! i didn't know that!! so it's not pwm but ppm really interresting!!! so thanks a lot!!!
so any i/o digital pin can drive a servo an arduino?
thank s a lot!!!!
Hi,
I might be wrong, but shouldn't the original poster be using the Servo library rather than softwareServo ?
As far as I can see, Servo is a fire and forget library which uses the hardware timers to ensure your servo signal is generated in the background using the hardware timers, you only need to interact with the library whenever you want to update the servo positions.
So for clarity, there are two servo libraries, softwareServo and Servo. Servo uses the built in hardware timers and it provides the fire and forget functionality, whereas softwareServo requires the periodic refresh to be built into the users code.
Does Servo supersed softwareServo or are there still advantages to softwareServo in particular applications ?
EDIT - On reading this entry from the documentation my understanding is that Servo supersedes softwareServo.
Simple servo test code you can try with the serial monitor.
// zoomkat 12-13-11 serial servo (2) test
// for writeMicroseconds, use a value like 1500
// for IDE 1.0
// Powering a servo from the arduino usually DOES NOT WORK.
// two servo setup with two servo commands
// send eight character string like 15001500 or 14501550
#include <Servo.h>
String readString, servo1, servo2;
Servo myservo1; // create servo object to control a servo
Servo myservo2;
void setup() {
Serial.begin(9600);
myservo1.attach(6); //the pin for the servo control
myservo2.attach(7);
Serial.println("two-servo-test-1.0"); // so I can keep track of what is loaded
}
void loop() {
while (Serial.available()) {
delay(3); //delay to allow buffer to fill
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
readString += c; //makes the string readString
}
}
if (readString.length() >0) {
Serial.println(readString); //see what was received
// expect a string like 07002100 containing the two servo positions
servo1 = readString.substring(0, 4); //get the first four characters
servo2 = readString.substring(4, 8); //get the next four characters
Serial.println(servo1); //print to serial monitor to see results
Serial.println(servo2);
int n1 = servo1.toInt();
int n2 = servo2.toInt();
myservo1.writeMicroseconds(n1); //set servo position
myservo2.writeMicroseconds(n2);
readString="";
}
}