(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« on: October 29, 2012, 05:37:44 pm » |
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
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #1 on: October 29, 2012, 05:52:03 pm » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #2 on: October 29, 2012, 05:52:08 pm » |
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
|
|
|
|
|
(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« Reply #3 on: October 29, 2012, 05:56:22 pm » |
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
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #4 on: October 29, 2012, 06:00:39 pm » |
Maybe you should read the docs before you use a command: http://arduino.cc/en/Reference/ServoWriteThe argument should be the angle in degrees.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #5 on: October 29, 2012, 06:05:19 pm » |
The data sheet for that servo talks about needing a "servo stretcher". http://www.servocity.com/html/hs-422_super_sport_.htmlyou 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
|
|
|
|
|
(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« Reply #6 on: October 29, 2012, 06:06:47 pm » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #7 on: October 29, 2012, 06:12:02 pm » |
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
|
|
|
|
|
(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« Reply #8 on: October 29, 2012, 06:13:50 pm » |
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
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #9 on: October 29, 2012, 06:18:38 pm » |
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
|
|
|
|
|
(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« Reply #10 on: October 29, 2012, 06:19:35 pm » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #11 on: October 29, 2012, 06:25:46 pm » |
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. 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. 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. 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
Sr. Member
Karma: 7
Posts: 386
|
 |
« Reply #12 on: October 29, 2012, 06:27:30 pm » |
http://arduino.cc/en/Reference/ServoWriteMicrosecondsNo, 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
|
|
|
|
|
(USA)
Offline
Full Member
Karma: 0
Posts: 191
|
 |
« Reply #13 on: October 29, 2012, 06:44:41 pm » |
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
Edison Member
Karma: 37
Posts: 1827
|
 |
« Reply #14 on: October 29, 2012, 06:50:36 pm » |
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
|
|
|
|
|
|