Pages: [1] 2   Go Down
Author Topic: Servo Program Help  (Read 1007 times)
0 Members and 1 Guest are viewing this topic.
Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I'm trying to make a very simple program to move my hs-422 servo, but my code is not working. It will only move the servo one time. It gets stuck on "delay" and will not move past that point. I know I'm making a noob mistake and any help would be greatly appreciated….

Thanks,
Drew Davis


#include <Servo.h>
 
Servo myservo;  
 
void setup()
{
  myservo.attach(9);  
}
 
void loop()
{
  
  myservo.write(10);
  
  delay(100);      

myservo.write(180); //* was previously set to 250 by mistake.

}
  
« Last Edit: October 29, 2012, 06:04:26 pm by drewdavis » Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this a continuous servo?

If not, servo.write() is limited from 0 to 180 degrees. Also, it sets a servo position, so if you send two commands with the same value you have no way of knowing if the second command is run.

Try this:

myservo.write(45);
delay(100);
myservo.write(135);

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It does not get stuck on delay(). It goes to 250 and stays there, because you never tell it to go to a different position.

Can your servo actually get to 250?
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

First off I did not mean to type 250 both times, and when I tested it it both were not at 250. Sorry for the confusion. Also, I was under the impression that I could use any numbers between 180 and 1023.

Kenth, I tried your code and it got stuck on the delay again.

Any more suggestions?
 
Thanks,
Drew Davis
« Last Edit: October 29, 2012, 05:58:44 pm by drewdavis » Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe you should read the docs before you use a command:
http://arduino.cc/en/Reference/ServoWrite

The argument should be the angle in degrees.
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The data sheet for that servo talks about needing a "servo stretcher".
http://www.servocity.com/html/hs-422_super_sport_.html

you may need to dig into the servo command to see if it can drive it with the Arduino's standard pulse width.

In any case for testing, try 0 and 45.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks for the link! I changed the program so that the value is not more than 180, but it still gets stuck on the delay.

Got any ideas?

Thanks,
Drew Davis
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Got any ideas?
Two. actually. One is for you to go look at the link that was posted. It shows that the servo should be positioned using writeMicroseconds(), rather than write().

The other is for you to add Serial.begin() and Serial.print() statements to your code to see what it is doing. It is NOT, unless you have royally hosed stuff up, getting stuck in delay().

How are you powering the servo? Not from the Arduino, I hope.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Just got your third post. I don't know what a stretcher is. Also how would I control it with PWM? This is one of my first sketches.


While writing this the servo just started flinching then went back to being locked . I don't know why.



Thanks,
Drew Davis
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read the datasheet for the servo, and then use writeMicroseconds() as Paul suggested to set two values. I am guessing this is a non-standard servo and the correspondence from degrees to microseconds is not working right when you use the servo.write() command.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1. I am powering it off the Arduino. Is there a better way? The book i'm reading told me to run it right off the arduino.

2. Where would I look at what ever it prints, and what would I put in the brackets after the serial.begin?

3. I did not see the writeMicroseconds(). Would I still use a value between o and 180?


Thanks,
Drew Davis
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 634
Posts: 50243
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
1. I am powering it off the Arduino. Is there a better way? The book i'm reading told me to run it right off the arduino.
Look at the link that was posted.

Quote
Current Drain (4.8V): 8mA/idle and 150mA no load operating
Current Drain (6.0V): 8.8mA/idle and 180mA no load operating
The Arduino digital pins are capable of 40mA MAX. The total output that the Arduino can manage is 200mA. Your servo is, with no load, taxing the Arduino.

Quote
2. Where would I look at what ever it prints, and what would I put in the brackets after the serial.begin?
In the Serial Monitor. Any value that the Arduino supports, between 9600 and 115200. Faster is better.

Quote
3. I did not see the writeMicroseconds(). Would I still use a value between o and 180?
No. Look at the link. There is a pretty picture showing the range of values that the servo expects. These values are not angles, so they are appropriate only for the writeMicroseconds() method.
Logged

Offline Offline
Edison Member
*
Karma: 33
Posts: 1468
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://arduino.cc/en/Reference/ServoWriteMicroseconds

No, because it is in microseconds, not degrees.

The servo you chose does not appear to be standard. It requires 600 us for -90 and 2400 us for +90. A standard servo only runs from 1000 - 2000.

You should always power the servo separately, they can draw a lot of current and put noise on the power supply.
Logged

Florida
Offline Offline
God Member
*****
Karma: 2
Posts: 559
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hello,

I changed "myservo.write();" to "myservo.writeMicroseconds()" but it still did not precede past the delay. Also, I put " Serial.begin(9600);
  Serial.print(9600);" in my void loop but this is what I got…

9600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096….

Also,
1. What is "noise"?

2. I did not really chose this servo. I was on a FTC robotics team and that is what came with all the robots. I just pulled it off and plugged it into the Arduino. I don't have a extra power supply but I will get one when I can.


Thanks for helping me,
Drew Davis
Logged

California
Offline Offline
Faraday Member
**
Karma: 92
Posts: 3435
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I changed "myservo.write();" to "myservo.writeMicroseconds()" but it still did not precede past the delay. Also, I put " Serial.begin(9600);
  Serial.print(9600);" in my void loop but this is what I got…

9600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096009600960096….
That means it is not getting "stuck on the delay"

It prints 9600 for every iteration of the loop.
« Last Edit: October 29, 2012, 06:53:05 pm by Arrch » Logged

Pages: [1] 2   Go Up
Jump to: