Go Down

Topic: what is code of continuous servo ? (Read 503 times) previous topic - next topic

TomGeorge

Hi'
? ? ? ?
Looking at your problem, all the sketches you have tried are for 0 to 180Deg servos, using
servo.write(x), where x is the angle in degrees.
You need to use  
servo.writeMicroseconds(x) where x is between 800 and 2200uS, corresponding to your servo stop position.
800 = start, 2200 = 6 turns CCW

try
Code: [Select]
myservo.writeMicroseconds(800);// goto start position
delay(3000);
myservo.writeMicroseconds(2200);// goto full 6 turns
delay(3000);
myservo.writeMicroseconds(800);// go back to start position
delay(3000);


But make sure you are powering the servo off a separate power supply to the arduino, please!!!
Just make sure that the gnd of the servo supply is connected to the gnd of the arduino.

Tom.... :)
Everything runs on smoke, let the smoke out, it stops running....

Yahia_Elsaeed

i'll tell u .. when write delay(5000); in any where ... it change the angle ... the only code give me the desired angle

void loop()
{
myservo.write(65);
               
myservo.write(0);

myservo.write(20);            
}

this code give me 40 degree in ccw and cw but i cant make any delay coz it change the range .. and if tried to remove   myservo.write(0); and use delay it make cw and ccw but i cant control the angle

AWOL

Quote
coz if any one told me that problem i'll feel he dont understand any thing about servo
It's a bit like if you say to someone "don't think of an elephant"

What's the first thing that pops into your mind? Yes, that's right . . . a big, grey pachyderm.

So, your thread title reads "what is code of continuous servo ?

What do you imagine most people here are going to think?
"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.

Yahia_Elsaeed


#include <Servo.h>
 
Servo myservo; 
 
void setup()
{
  myservo.attach(9); 
}
 
void loop()
{
 myservo.writeMicroseconds(960);
delay(5000);
myservo.writeMicroseconds(1000);
delay(5000);

}

thx tom your code is very good i just make a bit of changes and it work good as i want
but the problem only it make the wanted angle and delay time but it still go and back dont stop
i want it go and back only one time

AWOL

Put all the code in "setup()" if you only want something done once.
"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.

Yahia_Elsaeed

thx awol .. the final code is work as i wanted .. but how to stop the loop ? i wanna it work just one not a loop

AWOL

thx awol .. the final code is work as i wanted .. but how to stop the loop ? i wanna it work just one not a loop
Read reply #34
"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.

Yahia_Elsaeed

thx alot awol it work good now ... thx tom thx all answer and helped me :) ... Greeting

zoomkat

Just a couple of points to consider. Make sure you have an external power supply for the servo like in the attached picture. Below is info on your servo, and a sail winch servo with dual functions. Bottom is basic servo test code you should be able to use with the serial monitor to determine just how your servo operates.

Data sheet for your servo:

http://www.vigorprecision.com.hk/uploadfile/20120530/20120530163246912.pdf

Sail winch servo with both servo and continuous rotation features:

http://www.robotshop.com/ca/en/hitec-hs785hb-servo-motor.html

Servo test code:

Code: [Select]

// zoomkat 3-28-14 serial servo incremental test code
// using serial monitor type a character (s to increase or a
// to decrease) and enter to change servo position
// (two hands required, one for letter entry and one for enter key)
// use strings like 90x or 1500x for new servo position
// for IDE 1.0.5 and later
// Powering a servo from the arduino usually *DOES NOT WORK*.

#include<Servo.h>
String readString;
Servo myservo;
int pos=1500; //~neutral value for continous rotation servo
//int pos=90;

void setup()
{
  myservo.attach(7, 400, 2600); //servo control pin, and range if desired
  Serial.begin(9600);
  Serial.println("serial servo incremental test code");
  Serial.println("type a character (s to increase or a to decrease)");
  Serial.println("and enter to change servo position");
  Serial.println("use strings like 90x or 1500x for new servo position");
  Serial.println();
}

void loop()
{
  while (Serial.available()) {
    char c = Serial.read();  //gets one byte from serial buffer
    readString += c; //makes the string readString
    delay(2);  //slow looping to allow buffer to fill with next character
  }
  if (readString.length() >0) {
    if(readString.indexOf('x') >0) {
      pos = readString.toInt();
    }

    if(readString =="a"){
      (pos=pos-1); //use larger numbers for larger increments
      if(pos<0) (pos=0); //prevent negative number
    }
    if (readString =="s"){
      (pos=pos+1);
    }

    if(pos >= 400) //determine servo write method
    {
      Serial.println(pos);
      myservo.writeMicroseconds(pos);
    }
    else
    {   
      Serial.println(pos);
      myservo.write(pos);
    }
  }
  readString=""; //empty for next input
}



Google forum search: Use Google Advanced Search and use Http://forum.arduino.cc/index in the "site or domain:" box.

Go Up