hitec hs-81 control

hey. i bought one hs81 servo to play with it with arduino. i found out, that pulse of 1.5ms should keep the servo still and going from about 600 to about 2400 should move the servo from one end point to the other (approximately 180deg)

when i connected servo to power and arduino pin and send pulse (or pulses every 20ms) to the pin it starts to move but wont stop (nasty sound of plastic teeth grinding)i tried many pulse widths from 600 to 2400 but the direction and speed of servo looks just the same.

i tried servo library (via PWM pin on the board) and still no good.

can you help me with these questions?

  1. may the servo be faulty?
  2. i have to repeat pulses every 20ms or if i just want to move servo and keep it like that no more pulses necessary?
  3. what should servo do if there is no signal on the pin? return to start position? or to the center?
  1. may the servo be faulty?
    perhaps
  1. i have to repeat pulses every 20ms or if i just want to move servo and keep it like that no more pulses necessary?
    Try it with the distributed Servo library and the knob example. You do not need to repeat pulses with the Arduino library
  1. what should servo do if there is no signal on the pin? return to start position? or to the center?
    nothing (if a standard HS81 does something with no signal it is broken)
  1. what should servo do if there is no signal on the pin? return to start position? or to the center?
    nothing (if a standard HS81 does something with no signal it is broken)

Well in the servos I have played with, removing the signal pulse makes the servo stop at it's current position. However it also loses all holding torque and if there is a mechanical load on the servo it can in fact be moved easily by the external mechanical force.

Lefty

well i went to the RC store i bought servo at and the guy checked it, we connected it to some RC receiver and tried it and it worked. we tried other hs81 and it worked exactly the same, so it looks like i did something wrong (but i tried several times with different approaches). i have to check the code i used and paste it here, maybe you will find something terribly wrong in it. :slight_smile:

so here is one option i tried:
//servo variables
int servoPin = 2;

void setup() // run once, when the sketch starts
{
pinMode(servoPin, OUTPUT);

moveHS81(servoPin, 1500);
}

void loop() // run over and over again
{
}

void moveHS81(int pin, int pulse) {
int minPulse = 600;
int maxPulse = 2400;
digitalWrite(pin, HIGH);
delayMicroseconds(pulse);
digitalWrite(pin, LOW);
delay(18);
}

or the other one:
//servo variables
int servoPin = 3;

void setup() // run once, when the sketch starts
{
pinMode(servoPin, OUTPUT);
}

void loop() // run over and over again
{
moveHS81(servoPin, 2400);
}

void moveHS81(int pin, int pulse) {
int minPulse = 600;
int maxPulse = 2400;
digitalWrite(pin, HIGH);
delayMicroseconds(pulse);
digitalWrite(pin, LOW);
delay(18);
}

In one sketch you use pin 3, in the other pin 2.
One sketch has a pulse of 1500uS, the other 2400uS.
Any reason for this?

Did you try it with the standard library?

differences are because i tried various pins (with or without PWM capability) and various pulse width. i just attached two out of many variations i tried to upload to my arduino.

Did you try it with the standard library?

I also suggested this in reply #1

Miro.egres did you try to run the standard arduino servo library and test sketch? It would help us identify if you are having a software or hardware problem.

sorry, i missed that question in your replies guys.
yes i tried the servo lib that comes with arduino.

i tried KNOB example i just changed it the way i wont have to turn knob - instead of getting value for servo from pot i simply put it there. but i didnt get desired behaviour. i will have to try again, maybe i missed something. :frowning:

You really should try it with an unchanged test sketch. Did the sweep example sweep?

nope, it did the same - servo moved to endpoint and then it just kept jerking and making noise. today evening i will have to disassemble the wiring and put it back together again.

i altered the code because i didnt want to spend time with pot wiring (i found less thing that may go wrong better).

one thing came to my mind - what is difference between PWM and non PWM pin on arduino? i fi am right, servo library requires servo to be connected to PWM pin, right? is there something what non PWM pin cant do, like switching on/of rapidly thus making some PWM?

If you want to use pins other than the two PWM pins the current Arduino servo library uses, you can use the MegaServo library here: Arduino Playground - MegaServo

I posted a test sketch for that library that uses the serial monitor to position servos. you may want to try it to see if the problem only occurs when you drive your servos to extreme positions. See: http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1247570790/6#6

ok ,so i tried the default servo sweep example and then played with it for a while. it worked this way. so now i know at least, that arduino and hs81 can work together :slight_smile:

as for the angles. with default constructor - 544-2400 us i can use range of about 25 to 180deg.

i will play with simpy sending pulses later on.

thanks a lot for help guys.

one last question, is there any explanation of the libraries as to what exactly which part does? because when i checked the servo.cpp it contais a lot of stuff i dont understand.

Good to hear you have it going with the example code.

is there any explanation of the libraries as to what exactly which part does? because when i checked the servo.cpp it contais a lot of stuff i dont understand.

The purpose of the libraries is to provide functionality without the user needing to understand the implementation. There are some pages in the playground that has some background to library technology but you should be able to do everything you need through information contained in a libraries documentation. If you are looking to reduce the pulse range given to the servo, have a look at the documentation for the attach() methods. Is there something you would like to do that is not covered in the documentation?

no, there isnt anything i would miss, its just that i was curious to know how e.g. the interupts, or the way of sending pulses to servo.

The current Arduino library uses PWM (Pulse Width Modulation) driven from 16 bit timer1 to control the servo pulses. You can find information on this in the ATmega328 datasheet and other places online but this is complex stuff and perhaps not the best place to start learning about programming. What programming experience do you have?

i have MSc in elecrotechnic engineering - automation. :sunglasses: i havent done programming for living in past few years, but before i worked as PHP and web applications programmer. so from the past i have some background, but not with programming uC and low level HW. though i did some C/C++ programming, these things are quite a new thing for me, thats why i try to find out more.

Here are some resources on the timers used by Arduino:
http://www.avrfreaks.net/index.php?name=PNphpBB2&file=viewtopic&t=50106

also read the section in the ATmega328 datasheet on timers