Go Down

Topic: Driving a servo using brushed ESC (Read 2951 times) previous topic - next topic

feliksayk

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-)

AWOL

Is this an R/C servo or an industrial one?
Do you have the spec?
"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.

feliksayk

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?

AWOL

#3
Dec 06, 2009, 09:59 pm Last Edit: Dec 07, 2009, 02:04 pm by AWOL Reason: 1
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.
"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.

feliksayk

#4
Dec 06, 2009, 10:17 pm Last Edit: Dec 06, 2009, 10:20 pm by feliksayk Reason: 1
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.

AWOL

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

feliksayk

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

AWOL

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


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

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

feliksayk

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.  ;)

feliksayk

#9
Dec 06, 2009, 11:09 pm Last Edit: Dec 06, 2009, 11:11 pm by feliksayk Reason: 1
Will this code work? I mean is it complete. Thanks

Code: [Select]

#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.
}

PaulS

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

It should, though.

feliksayk

Awesome, absolutely awesome, thank you guys so much. It works :) :) :)

feliksayk

Alright, so to develop on this, my next question :) >>> 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: [Select]
#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

feliksayk

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 :)

PaulS

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.

Go Up