Pages: [1]   Go Down
Author Topic: getting servo going  (Read 996 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've read some on servos and connected one I had lying around. Only problem is I can't get it working with arduino. I also trying plugging it into an external power supply and just connecting the signal wire.

Here's my current code.
Code:
#include <WProgram.h>
#include <Servo.h>

Servo servo1;


void setup() {

  pinMode(1,OUTPUT);
  servo1.attach(15); //analog pin 0
  //servo1.setMaximumPulse(2000);
  //servo1.setMinimumPulse(700);
  Serial.begin(19200);
  Serial.println("Ready");

}

void loop() {
  //Servo::refresh(); this gave me errors
  delay(1000);
  servo1.write(0);
  delay(1000);
  servo1.write(180);
  delay(1000);
  servo1.write(90);
  delay(1000);

}
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I believe pins 9 and 10 are the only two pins you can use with that servo library functions.

http://www.arduino.cc/en/Reference/Servo

PS: It is normally best to use an external power supply for servos but just remember that the servo power supply's ground must also be wired to the Arduino's ground pin.

Lefty
« Last Edit: April 22, 2009, 04:30:28 pm by retrolefty » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome, that worked great. Also can't I use pin number 12 as thats also PWM, same with pins 6, 5 and 3.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Awesome, that worked great. Also can't I use pin number 12 as thats also PWM, same with pins 6, 5 and 3.

Great that it works. Not sure what you mean about pin 12. PWM pins which are supported by internal hardware timers, are not the same as servo signals (servos use PPM signalling) generated by software functions.

What pins support which internal hardware functions and what pins are supported by which software library functions are something you have to research in the various reference sources. Also now with the Arduino Mega board out some of the pin functions have changed from the orginial Arduino board and in some cases the reference documents have not kept up with the latest changes.

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

Info is kind of scatterd around and it's easy to get confused between hardware features and optional software library functions. But after giving it your best shot like you did, then just ask on the forum and your sure to get help.
« Last Edit: April 22, 2009, 04:51:32 pm by retrolefty » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok, so PPM pins are different from just PWM pins.

Another question, could I hook this up the an electronic speed controller the same way (esc from a rc car, same wire hookups)? I would think it would work as I can put ether a servo or a esc in the same slot on the receiver in a rc car and it will work the same way.

Final question, if I have a continuous rotation servo how do I get it to keep rolling instead of stopping at 180 degrees?
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Yes you can wire a ESC same as a servo and control a motor. Keep im mind some ESC require that you start at 0 degrees software servo command before it will 'arm' the motor to run, this is a safety feature to keep you from lopping off a finger with a motor driven prop on initial powering up.

Not sure I completely understand your question on controlling modified continous turning servos but from a software point of view 0 degrees would be full speed in one direction, 90 degrees would be stopped and 180 degrees would be full speed in the opposite direction.

Lefty
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

seth556, if you want to drive more than two servos (or speed controllers) you can use this library: http://www.arduino.cc/playground/Code/MegaServo

Its used like the Arduino servo library but any digital pin can be used.
« Last Edit: April 23, 2009, 01:53:54 am by mem » Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

^ Thanks for that library.

Are you sure 0 degrees for the esc wouldn't be reverse? Or can you do negative degrees for that? Ether way I'll figure it out after I get home from school. Just better to know as the only esc's and motors I have sitting around are brushless with a LOT of power.
Logged

London
Offline Offline
Faraday Member
**
Karma: 8
Posts: 6240
Have fun!
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You need to check the specs for your ESC, but most designed for aircraft use do not have reverse. If you use the MegaServo library you can write speed values using microseconds instead of degrees if you prefer, most ESCs expect a range from 1000 to 2000 microseconds, so that may be a good place to start.  

Be careful when you test it to ensure the motor is securely mounted, there is enough torque from a decent brushless motor to spin it out of control even if nothing is attached to the shaft.
Logged

Left Coast, CA (USA)
Offline Offline
Brattain Member
*****
Karma: 331
Posts: 16514
Measurement changes behavior
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Are you sure 0 degrees for the esc wouldn't be reverse? Or can you do negative degrees for that? Ether way I'll figure it out after I get home from school. Just better to know as the only esc's and motors I have sitting around are brushless with a LOT of power.

No, you are getting two different subjects confused and combined. You asked one question about ESC interfacing and one question about interfacing to modified servos.
 A servo modified for continous rotation has nothing to do with interfacing a servo software command to a ESC module. My 0-90-180 degrees commands have to do with interfacing to a modified servo. The software degree commands given to a ESC module depends on the design and purpose of the ESC. There are several kinds of ESC, some for DC motors, some for brushless DC motors, some for bi-directional and some for unidirectional only. You really have to be specific about these things when you start to write the interface code.

Lefty


Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I got that about the servo.

About the esc and motor (all the ones I have around here) are for rc cars. So forward, break, reverse. All brushless and handle voltages ranging from 7 to 14v depends on how long you want to spin the tires.
Logged

0
Offline Offline
Jr. Member
**
Karma: 0
Posts: 59
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So I started messing around with it, for the esc (has reverse) 90 was the middle and 0 degrees is reverse but it gets tricky as it's in forward, break and then you have to give it a break signal again to go into reverse. So I would put 0 degrees and it would stop but then if I put in 45 degrees it would go into reverse and then keep in reverse when it looped back around to 0 degrees. Took me a minute to figure out what was going on. I think I'll just reprogram the esc so it doesn't have the reverse lock out.  

So if anyone is wondering for an ESC its 0 degrees is break or reverse, 90 degrees is no power, and 180 is full power straight ahead.
Logged

Pages: [1]   Go Up
Jump to: