How can I control Servo motor by angle information?

Hello, BB group~

I’m figuring out how to control Servo motor by angle information with my BB.

I made a tracking sound c++ code and this code get some angle(degree) information. And finally i got it with my BB.

The next step is controlling Servo motor by this angle information.

So I’m thinking of 2 methods.

First one is using Arduino(send angle information to Arduino from BB), and Second one is BB directly controls a Servo motor.

But I don’t know how to use gpio in BB and I wonder 2 methods I thought are possible to implement coding by just using c++ in Angstrom linux.

Please give me any comments.

It will be great help for me.

Thanks.

You can use a PWM output to drive your servo. Set the PWM cycle frequency to 50hz and the duty cycle to 1.5 ms (~7% = center position). Varying the duty cycle +/- 0.5ms should drive your servo to left and right.
Power the servo by an external power source not the GPIOs of the board.

Hi Leonard,

Wich drive are you using?

I try with python adafruit and did not work.

i can blink with gpio but pwm never work.

i use ubuntu precise, bbb,

root@ubuntu-armhf:/home/ubuntu# echo 51 > /sys/class/gpio/export
root@ubuntu-armhf:/home/ubuntu# echo “out” > /sys/class/gpio/gpio51/direction
/direction root@ubuntu-armhf:/home/ubuntu# echo “low” > /sys/class/gpio/gpio51/direction

but can i use the same step with pwm?

root@ubuntu-armhf:/home/ubuntu# ls /sys/class/pwm
export pwmchip0 pwmchip2 pwmchip3 pwmchip5 pwmchip7 unexport
root@ubuntu-armhf:/home/ubuntu# ls /sys/class/pwm/pwmchip0
base device npwm power subsystem uevent

I try

echo am33xx_pwm > /sys/devices/bone_capemgr.9/slots;

echo bone_pwm_P8_19 > /sys/devices/bone_capemgr.9/slots; # EHRPWM2A
echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.9/slots; # EHRPWM2B
echo bone_pwm_P9_14 > /sys/devices/bone_capemgr.9/slots; # EHRPWM1A
echo bone_pwm_P9_16 > /sys/devices/bone_capemgr.9/slots; # EHRPWM1B

but i get.

root@ubuntu-armhf:/home/ubuntu# ls /sys/devices/ocp.2/pwm_test_*
/sys/devices/ocp.2/pwm_test_P8_13.31:
modalias power subsystem uevent

/sys/devices/ocp.2/pwm_test_P8_19.30:
modalias power subsystem uevent

/sys/devices/ocp.2/pwm_test_P9_14.32:
modalias power subsystem uevent

/sys/devices/ocp.2/pwm_test_P9_16.33:
modalias power subsystem uevent

Hi Marcus,

I was only general speaking. I just got my BBB and I’m not jet familiar with the details of programming PWMs.
But google gave me this answer:

http://www.phys-x.org/rbots/index.php?option=com_content&view=article&id=106:lesson-3-beaglebone-black-pwm&catid=46:beaglebone-black&Itemid=81

my problem is that I cant install bonescript and a lot of ports do not exist like this port.
/sys/devices/ocp.2/helper.14/AIN5

I think i will go back to . or shuld be better debian?

root@ubuntu-armhf:/sys/kernel/debug/pinctrl/44e10800.pinmux# export SLOTS=/sys/devices/bone_capemgr.9/slots
root@ubuntu-armhf:/sys/kernel/debug/pinctrl/44e10800.pinmux# export PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
root@ubuntu-armhf:/sys/kernel/debug/pinctrl/44e10800.pinmux# echo $SLOTS
/sys/devices/bone_capemgr.9/slots
root@ubuntu-armhf:/sys/kernel/debug/pinctrl/44e10800.pinmux# echo $PINS
/sys/kernel/debug/pinctrl/44e10800.pinmux/pins

root@ubuntu-armhf:/home/ubuntu# cat $SLOTS
0: 54:PF—
1: 55:PF—
2: 56:PF—
3: 57:PF—
4: ff:P-O-L Bone-LT-eMMC-2G,00A0,Texas Instrument,BB-BONE-EMMC-2G
5: ff:P-O-L Bone-Black-HDMI,00A0,Texas Instrument,BB-BONELT-HDMI

root@ubuntu-armhf:/home/ubuntu/boneDeviceTree/overlay# dtc -O dtb -o DM-GPIO-Test-00A0.dtbo -b 0 -@ DM-GPIO-Test.dts

it get error and do not copile the line above

root@ubuntu-armhf:/home/ubuntu/boneDeviceTree/overlay# apt-get install bonescript
Reading package lists… Done
Building dependency tree
Reading state information… Done
E: Unable to locate package bonescript

root@ubuntu-armhf:/sys/devices/ocp.2# ls
44e07000.gpio 48046000.timer 49000000.edma nop-phy.6
44e09000.serial 48048000.timer 4a100000.ethernet nop-phy.7
44e0b000.i2c 4804a000.timer 53100000.sham nxptda@0.11
44e35000.wdt 4804c000.gpio 53500000.aes power
44e3e000.rtc 4819c000.i2c gpio-leds.8 rstctl.3
47400000.usb 481ac000.gpio hdmi.12 sound.13
48038000.mcasp 481ae000.gpio mmc.4 subsystem
48042000.timer 48200000.interrupt-controller mmc.5 uevent
48044000.timer 4830e000.fb modalias