Hi,
My project involves using two sail winch servos (HITEK HS-785 HB, apparently 3.5 rotations possible). I am waiting for the servo's to turn up but just wondered if anyone has any experience using/programming for these?
I need to control the exact position of the servos all the way round the 3.5 turns, just wondered how this works on the programming (microseconds) side of things? Is this possible?
For example, what happens when the servo reaches 360 degrees rotation, do I have to program it to go to 361 degrees to continue rotating or do I have to then tell it to go to 1 degree on the servo.
Or is it similar to a normal servo where 1000ms is 'zero position' and 2000ms would be 3.5 rotations clockwise?
The below shows some propertys of the HS 785HB servo. Note that the servo library has some built in min/max us values that may need to be changed to get full use from the servo.
I came across this thread, looking for information about HS-785 servo. Driving this servo is a bit tricky, so I developed some sample code to check things out. Here is the sample Arduino program that will help figure out the PWM required to drive the servo for specific end points, hope it helps. It may be used with any other RC servos as well.
// SweepByNumPad by Umesh Ghodke, K6VUG
// This example code is in the public domain.
// Author assumes no responsibility whatsoever.
#include <Servo.h>
#define PWM1_MIN 700
#define PWM1_MID 1500
#define PWM1_MAX 2300
#define PWM2_MIN 700
#define PWM2_MID 1500
#define PWM2_MAX 2300
#define PWM_STEP 1
Servo servo1, servo2; // create servo objects to control servos
int pwm1 = 1500; // global stores value of PWM in microseconds
int pwm2 = 1500; // global stores value of PWM in microseconds
char inByte; // Byte input from command prompt
void setup()
{
// initialize servo 1
servo1.attach(6, PWM1_MIN, PWM1_MAX); // attaches the servo on pin 9 to the servo object
servo1.writeMicroseconds(pwm1); // set servo to mid-point
// initialize servo 2
servo2.attach(9, PWM2_MIN, PWM2_MAX); // attaches the servo on pin 9 to the servo object
servo2.writeMicroseconds(pwm2); // set servo to mid-point
// initialize serial port
Serial.begin(4800);
Serial.println("SweepByNumPad -- Ready");
Serial.flush();
}
void loop()
{
// Input serial information:
if (Serial.available() > 0){
inByte = Serial.read();
// use numpad keys, use ASCII values in decimal format
// "2" = 32H (50D)
if ((inByte == 50)) {
if (pwm1 > PWM1_MIN) pwm1 -= PWM_STEP;
moveServo1();
}
// "8" = 38H (56D)
else if ((inByte == 56)) {
if (pwm1 < PWM1_MAX) pwm1 += PWM_STEP;
moveServo1();
}
// "4" = 34H (52D)
else if ((inByte == 52)) {
if (pwm2 > PWM2_MIN) pwm2 -= PWM_STEP;
moveServo2();
}
// "6" = 36H (54D)
else if ((inByte == 54)) {
if (pwm2 < PWM2_MAX) pwm2 += PWM_STEP;
moveServo2();
}
// "5" = 35H (53D)
else if ((inByte == 53)) {
if (pwm1 != PWM1_MID) pwm1 = PWM1_MID;
moveServo1();
if (pwm2 != PWM2_MID) pwm2 = PWM2_MID;
moveServo2();
}
// ignore the rest, just echo the byte back
else {
Serial.println(inByte, DEC);
}
inByte = 0;
}
}
// helper function: set servo1 pwm
void moveServo1() {
servo1.writeMicroseconds(pwm1);
Serial.print("Servo1 - ");
Serial.println(pwm1);
}
// helper function: set servo2 pwm
void moveServo2() {
servo2.writeMicroseconds(pwm2);
Serial.print("Servo2 - ");
Serial.println(pwm2);
}
Turn off NUMLOCK and use the keys on the NumPad to control the 2 servos.
Use a serial terminal program like Windows HyperTerminal etc. so the key strokes are sent immediately to the Arduino. (the Arduino's Serial Monitor does not send until you click the SEND button)
Increase the value of PWM_STEP a little, for faster motion.
Almost forgot, the baud rate is set to 4800 in the code, so set your terminal program to 4800 baud, and no handshake.
Once you get the hang of it, you can modify the program to include other keystrokes and other actions.
Enjoy!
(note to self: need to get this sample code up in the Examples section)