Pages: [1] 2   Go Down
Author Topic: Driving a servo using brushed ESC  (Read 2531 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys, this is my first time on this forum and I don't really know how all this works. I just wanted to know if anyone here can help me out. What I am trying to get is a code which will control a servo through a brushed ESC through the arduino. Or perhaps it is doable without the ESC. I need it to be automatic though, so it spins the servo for about 30 degrees, waits 9 seconds, and spins it back to original position. Since I do not know any coding past that of blinking a few LEDs on the arduino using different patterns, I am asking for help from anyone that can do this. Thanks in advance for any responses  8-)
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25860
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Is this an R/C servo or an industrial one?
Do you have the spec?
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is a regular RC servo, came with my Futaba 6EXP radio system, an S3001 servo. http://www3.towerhobbies.com/cgi-bin/WTI0001P?I=LXH286&P=8

It's not big, but I think it would be dangerous to drain the power to run it from Arduino.

I also have the Arduino Duemilanove.

A few brushed ESCs....what else would you need, I think that's it?
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25860
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You don't need an ESC, just make sure you use a separate supply (join the grounds) and drive the signal (white, usually) wire using one of the Arduino pins, with an appropriate servo library.
have a look in the libraries section for example code.
« Last Edit: December 07, 2009, 08:04:18 am by AWOL » Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I did but did not understand how to do what I need to do. They have examples on how to drive the servo using a potentiometer, that is completely different from what I need. I need arduino to tell the servo to move 30 degress, wait 9 seconds, move back 30 degrees, wait for 9 sec, and repeat.
« Last Edit: December 06, 2009, 04:20:57 pm by feliksayk » Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25860
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The example simply took the input from a pot (0..1023), mapped that range to an angle (0..180) and wrote that angle to a servo object.
Cut out the pot, substitute some angle constants, add a few "delay" calls, and your program is written.
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Could I ask you to please write that code for me? Like I said, I do not know this stuff and it's seriously confusing for me. You explain it to me as if it is very simple, and it probably is, I just don't know the basics.  ;D
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 291
Posts: 25860
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't normally, but it is the season of goodwill
[uncompiled, untested)
Code:

void loop ()
{
  myservo.write (30); // move servo 30 degrees
  delay (1000 * 9); // wait nine seconds
  myservo.write (0); //moves servo back 30 degrees
  delay (1000 * 30); // wait 30 seconds.
}
Logged

"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.

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for this. How do you assign the pin for the servo signal though in the code? And does it have to be a digital or analog pin? I thank you once again. If you do not wish to answer, I guess I'll just have to spend some more time analyzing the tutorials.  smiley-wink
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Will this code work? I mean is it complete. Thanks

Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop ()
{
  myservo.write (30);   // move servo 30 degrees
  delay (1000 * 9);     // wait 9 seconds
  myservo.write (0);    //moves servo back 30 degrees
  delay (1000 * 9);     // wait 9 seconds.
}
 
« Last Edit: December 06, 2009, 05:11:04 pm by feliksayk » Logged

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

Only one way to find out. Plug in the servo, upload the code, and watch the servo.

It should, though.
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Awesome, absolutely awesome, thank you guys so much. It works smiley smiley smiley
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Alright, so to develop on this, my next question smiley >>> Is there a way to make the servo move through the 30 degrees smoothly or more slowly?
Here's the complete code that I am using.

Code:
#include <Servo.h>
 
Servo myservo;  // create servo object to control a servo
 
int pos = 0;    // variable to store the servo position
 
void setup()
{
  myservo.attach(9);  // attaches the servo on pin 9 to the servo object
}

void loop ()
{
  myservo.write (30);   // move servo 30 degrees
  delay (1000 * 9);     // wait 9 seconds
  myservo.write (0);    //moves servo back 30 degrees
  delay (1000 * 9);     // wait 9 seconds.
}

Thanks to all
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 19
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

what if I add more statements, such as 2 or 3 more saying to increase by 10 degrees, wait for 100ms and then increase again, and same for when decreasing. Hmmm, will try now, any other ideas welcome smiley
Logged

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

That is the correct way to do. Move the servo in small increments, as is done in one of the sample sketches provided with the servo library.
Logged

Pages: [1] 2   Go Up
Jump to: