Offline
Newbie
Karma: 0
Posts: 9
|
 |
« on: January 07, 2013, 04:58:10 pm » |
I am trying to run a VEX servo motor (3-wire) with my Arduino. No matter what I try, I can only get it to run infinitely. Here are two programs I created to try and get it to work... #include "Servo.h" Servo motor; void setup() { motor.attach(9); for(int t=0;t<=3000;t+1000){ motor.write(80); } } void loop(){ } and... #include "Servo.h" Servo mtr; void setup(){ mtr.attach(9); mtr.write(80); delay(1000); } void loop(){ } The circuit I am using is attached below.
|
|
|
|
« Last Edit: January 09, 2013, 12:18:40 am by DCengineer »
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 2
Posts: 199
|
 |
« Reply #1 on: January 07, 2013, 09:09:01 pm » |
I think that the 9-volt battery is too weak to power VEX motors. You'll need 7.2V RC battery pack.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #2 on: January 07, 2013, 11:25:46 pm » |
I don't see how a 9V would provide less power than a 7.2V, and the battery I had was brand new.
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Edison Member
Karma: 17
Posts: 2207
Per aspera ad astra.
|
 |
« Reply #3 on: January 07, 2013, 11:54:53 pm » |
Not sure, if I understand your question, but I spot an error could cause "hang-up": void setup() { motor.attach(9); for(int t=0;t<=3000;t += 1000){ // <- "=" sign is missing motor.write(80); } } void loop(){ }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #4 on: January 08, 2013, 12:10:21 am » |
I'm wanting to add 1000 to t, does += add a specific value?
|
|
|
|
|
Logged
|
|
|
|
|
Montreal
Offline
Edison Member
Karma: 17
Posts: 2207
Per aspera ad astra.
|
 |
« Reply #5 on: January 08, 2013, 01:21:16 am » |
t += 1000 is equivalent to t = t + 1000 You need add, and save, so next run in cycle variable would progressively increasing.
|
|
|
|
« Last Edit: January 08, 2013, 01:23:23 am by Magician »
|
Logged
|
|
|
|
|
Offline
Sr. Member
Karma: 12
Posts: 327
The last thing you did is where you should start looking.
|
 |
« Reply #6 on: January 08, 2013, 02:14:16 am » |
|
|
|
|
|
Logged
|
|
|
|
|
South Texas
Offline
God Member
Karma: 8
Posts: 976
|
 |
« Reply #7 on: January 08, 2013, 09:57:55 am » |
Yep, the VEX servo is a continuous rotation servo. That is why they have the 2" diameter wheel with a black o-ring around the outside. As compared to a normal servo - 90 degrees is stop. and you have direction control as you move away from 90 degrees along with "some" speed control.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #8 on: January 08, 2013, 12:35:16 pm » |
Mine is the one in the middle of the picture on the first link.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #9 on: January 08, 2013, 12:35:48 pm » |
Is it possible that it is broken?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #10 on: January 09, 2013, 12:17:13 am » |
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #11 on: January 09, 2013, 12:18:16 am » |
NEW QUESTION: Now that I got the motor to run the way I want, how can I get 2 motors to run at the same time?
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #12 on: January 09, 2013, 09:53:11 pm » |
without seeing the code that you have working I can only guess based on what you posted before.
You have to initialize another servo:
Servo motor2;
Then initialize it to the pin of the second motor, something like this (assuming this code works for your first servo
void setup() { motor2.attach(XX); // where XX is the pin of the other servo. for(int t=0;t<=3000;t += 1000){ motor.write(80); } } void loop(){ }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #13 on: January 09, 2013, 10:56:02 pm » |
Here is the code I got to work. The question I was asking was a little more general... it can be worded as "How can I run two lines of code at the same time?" This is my current code to run one servo, based on a library I found online. I just want to run two servos at once, and thought I might be able to get two lines of code to execute AT THE SAME TIME. #include <ContinuousRotationServo.h>
ContinuousRotationServo Servo; int distance;
void setup() { Servo.begin(2); // port 2, this library works without PWM }
void loop() { Servo.rotateLeft(50,100); Servo.noMovement(500); Servo.rotateRight(50,100); Servo.noMovement(500); }
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Newbie
Karma: 0
Posts: 9
|
 |
« Reply #14 on: January 09, 2013, 11:50:32 pm » |
Not to my knowledge, the processor on the Arduino is only capable of handling one instruction at any given moment in time. But that is a extremely small amount of time. Unless there is a delay or sleep between the 2 calls to the servos will start at the same (human percevable) time.
|
|
|
|
|
Logged
|
|
|
|
|
|