I am trying to control this servo from a RaspberryPi.
I sort of figured out that a servo needs a specific pulse for a specific degree. www.youtube.com/watch?v=ddlDgUymbxc
I am using this https://github.com/hybridgroup/pi-blaster for PWM.
I already confirmed this PWM works as expected by lighting an LED, but no matter what pulse I give to my servo, it just goes wild.
It goes like either keep moving from left to right or shakes at one point continuously.
The youtube's servo moves +/- 90 degree, but my servo does +/- 60 degree. so maybe the pulse I need to give is different from 0.5ms/1.5ms/2.5ms?
Has anybody used this servo with RaspberryPi? What are the pulses to give?
I changed the source code to have 50Hz frequency.
diff --git a/pi-blaster.c b/pi-blaster.c index 2e15ee1..d7d8af2 100644 --- a/pi-blaster.c +++ b/pi-blaster.c @@ -70,8 +70,8 @@ static uint8_t pin2gpio; // will use too much memory bandwidth. 10us is a good value, though you // might be ok setting it as low as 2us. -#define CYCLE_TIME_US 10000 -#define SAMPLE_US 10 +#define CYCLE_TIME_US 20000 +#define SAMPLE_US 20 #define NUM_SAMPLES (CYCLE_TIME_US/SAMPLE_US) #define NUM_CBS (NUM_SAMPLES*2)
and now pi-blaster shows this.
$ sudo /usr/sbin/pi-blaster Using hardware: PWM Number of channels: 9 PWM frequency: 50 Hz PWM steps: 1000 Maximum period (100 %): 20000us Minimum period (0.100%): 20us
but my servo still goes wild. Since
Minimum period (0.100%): 20us, to have
0.5ms, I did this.
0.5ms(500us) / min period(20us) = 25
0.1% * 25 = 2.5% = 0.025
$ echo "17=0.025" > /dev/pi-blaster
It seems it is always going back to 0 degree point whichever the % I give it to.
It goes like this.
For 180 degree, it is 2.5ms. When I give
$ echo "17=0.125" > /dev/pi-blaster
servo goes to the 180 degree point, and it soon goes back to 0 degree point. It goes like this back and forth, back and forth, as long as I give the power to it. same goes to any degree.