Cotrol a servo with Orangutan Lv?

Hello,

I’m new in robot world. I have a little robot with an orangutan lv, i know how to control motor and use inputs to control it. But now I’m trying to control a servo with this board. i Know hot to conect the servo but when i try several exemples codes form arduino librarys but my servo doesn’t move. I tried these:

#include <Servo.h>

Servo myservo; // create servo object to control a servo

int potpin = 7; // analog pin used to connect the potentiometer
int val; // variable to read the value from the analog pin

void setup()
{
myservo.attach(4); // attaches the servo on pin 4 to the servo object
}

void loop()
{
val = analogRead(potpin); // reads the value of the potentiometer (value between 0 and 1023)
val = map(val, 0, 1023, 0, 179); // scale it to use it with the servo (value between 0 and 180)
myservo.write(val); // sets the servo position according to the scaled value
delay(15); // waits for the servo to get there
}

i tried to put the servo in a digital I/O but it doesn’t works.

And this :
#include <Servo.h>

Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created

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

void setup()
{
myservo.attach(0); // attaches the servo on pin 0 to the servo object
}

void loop()
{
for(pos = 0; pos < 180; pos += 1) // goes from 0 degrees to 180 degrees
{ // in steps of 1 degree
myservo.write(pos); // tell servo to go to position in variable 'pos’
delay(15); // waits 15ms for the servo to reach the position
}
for(pos = 180; pos>=1; pos-=1) // goes from 180 degrees to 0 degrees
{
myservo.write(pos); // tell servo to go to position in variable 'pos’
delay(15); // waits 15ms for the servo to reach the position
}
}

Please help, i don’t know how to cotrol it .

thanks see you

Hello.

How are you connecting the servo to your Orangutan, and how are you powering it?

- Ben

Hello BEn,

ok here i left you an image how i conect it, but in the pin nº 5, analogic, i’m not sure but I think that my servo is analogic. i tried in digital output but it didn’t works.
tell me there are something wrong?

Hello,

Do you have a ground connection between your 7.5V and 4.5V power supplies? Without a shared ground, there is no way for the servo to measure the voltage of its control line.

-Paul

Hello,

No i haven’t a ground betwen my 7v and 4,5 power suplies.

Are you telling me that it is the problem?

I will try it… i hope that works

thanks

-Biel

There are potentially a few other problems with your setup. First, analog and digital servos typically respond to the same control signals. The descriptor “analog” or “digital” refers to the internal electronics that take care of the servo’s positioning feedback loop. You do not need to us an analog input pin to send signals to an analog servo (analog pins on the Orangutan can only be used to read analog voltages; they are still digital lines when used as outputs).

Second, your code implies that the servo is connected to Arduino pin 4, which corresponds to mega168 pin PD4, a pin that isn’t even brought out to the 3x8 female I/O header on the Orangutan LV-168. The I/O header has pins PD0, PD1, and PC0 - PC5. In terms of Arduino pin numbering, these would be pins 0, 1, and 14 - 19 respectively. In your diagram, you are connecting to pin PC5, which is Arduino digital pin 19.

I don’t know the details about how the Arduino servo library works; can it control a servo on any digital output pin, or does it require connection to a hardware PWM output?

- Ben

Ok thanks for the informatio, i didn’t know it.
The second problem is solved, mistake mine. :blush:

About the question, "how the Arduino servo library works; can it control a servo on any digital output pin, or does it require connection to a hardware PWM output?"
I don’t know, i was trying to learn and understand how it works… :unamused:

is there another way to cotroll the servo with orangutan? :question:

I didn’t think that control servo with orangutan was so dificult

I assume the Arduino servo library documents how it works and what its limitations are, so that would be a good place to start looking for information.

Controlling servos isn’t that difficult, especially if you can use delays to achieve the pulse timing. If you need to be doing other things while generating the pulses, then it becomes more challenging, especially if you want to control multiple servos.

If you want some sample servo control code, please take a look at the example in our Pololu AVR library, which you can download here.

The servo control sample program can be found at:

libpololu-avr/examples/atmega168/simple_servo_control

- Ben

Hi,

I had the same problem, but I found this library much easier to use.
It’s been designed so that you can run many servos at once but it works just as well with one.

arduino.cc/playground/Code/MegaServo

Once you’ve installed the library, it’s easy! Here’s some code for an easy test I wrote. You turn the trimpot and it turns the servo.

It’s not pretty code but I hope this helps anyone else with the same problem.

#include <OrangutanAnalog.h>
#include <MegaServo.h>
#include <OrangutanLCD.h>
#define NBR_SERVOS 1  // the number of servos, up to 48 for Mega, 12 for other boards
#define FIRST_SERVO_PIN 0

OrangutanLCD lcd;
OrangutanAnalog analog;
MegaServo servo;

int pot=0;
int deg=0;

void setup()                    // run once, when the sketch starts
{
  servo.attach( FIRST_SERVO_PIN,700,1800);
  analog.setMode(MODE_10_BIT);    // 10-bit analog-to-digital conversions
  lcd.clear();
}

void loop()                     // run over and over again
{
  pot=analog.toMillivolts(analog.readTrimpot());
  deg=map(pot, 0,5000,180,0);
  servo.write(deg);
  lcd.gotoXY(0,0);
  lcd.print(deg);
  lcd.print("  ");
  delay(50);
}

-Aaron