[Moved] Controlling a servo with GPIO

Status
Not open for further replies.

icemetal

Member level 2
Joined
Sep 2, 2009
Messages
51
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,288
Activity points
1,615
Controlling a servo with GPIO in Embedded Linux

I want to improve my skills controlling the GPIO of a linux embedded board, is there a site for beginner or where can I start with basic programs like controlling a servo motor? do I need to create the driver or I can just create the program to control a servo?
 
Last edited:

I want to improve my skills controlling the GPIO of a linux embedded board, is there a site for beginner or where can I start with basic programs like controlling a servo motor?

Possibly. However, it would be helpful to know the exact development board which you are working with and its MCU or processor.

do I need to create the driver or I can just create the program to control a servo?

Linux has a protected kernel, therefore you will most likely need to write a kernel driver to handle the low level interface with the GPIO pins. Also a kernel driver may already exist or the code for an existing driver could possibly be ported, however here again the exact development board and its MCU or processor will need to be know.

BigDog
 

I'm using the Mini2440 S3C2440 ARM9 Board and also I had tried on the DM365 from TI, I was able to turn ON/OFF LEDs using this commands:

echo "1" > gpio32/value
echo "0" > gpio32/value

My next step would be controlling a RC servo, but from your information, I would need to write a driver, is there a guide line of how to write GPIO drivers? or as you said if there is a driver for it where I should look?
 


Maybe not. It appears you have low level access to the ports via the shell. Most servos require a PWM of 50Hz or 20ms period and a duty cycle ranging from 1ms to 2ms. You could attempt to write a C program generating a PWM at one of the GPIO pins, like you demonstrated with the LED.

BigDog
 

Thanks BigDog, so my question is :
is there a site for beginner or where can I start with basic programs like controlling a servo motor using the GPIO?
 

Here is a very informative servo tutorial using a PIC microcontroller with C language programming:

Basic Servo Motor Controlling with Microchip PIC Microcontroller

While I realize it is not based on the ARM architecture, the tutorial does do an excellent job explain the basics of PWM control of a servo motor.

I'll see what else I have pertaining more to the ARM architecture.

BigDog
 

Thanks, I already know how to control a servo with PIC, I just want to know how to do it with the GPIO in Linux I had previously wrote this basic program:
Code:
int i;

void main()
{
while(1)
{
   for(i=0;i<100;i++)               // 0 degrees
   {
         output_high(PIN_A2);
         delay_us(700);             // delay 1
         output_low(PIN_A2);
         delay_us(19300);           //delay 2  
   }                                // delay 1 + delay 2 = 20000us
   
   for(i=0;i<100;i++)               //180 degrees
   {
         output_high(PIN_A2);
         delay_us(2000);
         output_low(PIN_A2);
         delay_us(18000);
   }

}
}
 

Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…