0
votes

Background: Bought a BBB and experimenting a bit, managed to control LEDS and relays. Problem: can't get the expected behaviour from the servo, it keeps spinning CCW Cause: don't know, whey I'm asking here :)

Facts: BBB with Angstrom External 5V DC to both BBB and servo Servo: Tower Pro sg90 (very common servo) AND it's working as I tried it in my RC car.

Procedure: following som tutorials on the web (and used Adafruit_BBIO library), I'm trying to make my servo work, e.g. turn 0, 90, 180 etc so here's what I'm doing:

echo am33xx_pwm > /sys/devices/bone_capemgr.8/slots
echo bone_pwm_P8_13 > /sys/devices/bone_capemgr.8/slots
echo 20000000 > /sys/devices/ocp.2/pwm_test_P8_13.15/period (this is 50Hz,also tried 60Hz)
echo 10000000 > /sys/devices/ocp.2/pwm_test_P8_13.15/duty
echo 1 > /sys/devices/ocp.2/pwm_test_P8_13.15/run

Doing the above the servo spins CCW with no stop. I can read 50Hz (60Hz) and 1.66V and even tried to use level shifter so I get ~ 2.5V I don't know what I'm doing wronge (if I am) or am I missing something?

3

3 Answers

0
votes

I also struggled to get a servo working with the Beaglebone Black.

Ultimately, I was able to get good results by exactly following this tutorial: http://learn.adafruit.com/controlling-a-servo-with-a-beaglebone-black?view=all

As I understand it, the most recent versions of the Adafruit_BBIO library handle the pin muxing stuff completely, so your only interface to the BBB can be through a Python script, rather than having to do the command line stuff in your question.

The Adafruit_BBIO library has changed significantly in the last 30 days, so it's worth doing these steps in order:

  • reboot BBB
  • run pip install Adafruit_BBIO --upgrade
  • Try a simple Python script like the one in the tutorial from Adafruit.

I hope this helps!

Update in response to poster's comment:

Hmmm, sorry to hear that my steps didn't work! If your code is resulting in 13% duty cycle at 50 or 60Hz, that makes me think the code is fine, and the servo is having trouble.

I know you've probably checked it a dozen times, but is the 5v you're sending to the servo checking out? As in, is it coming from P9_5 or P9_6, which are from the high-current 5v supply?

Also, re-reading your question, you say the servo keeps spinning CCW - if it doesn't reach a limit and stop moving at some point, there's your problem: continuous-rotation servos aren't able to reach specific set points because they lack the feedback system that 0-180 servos have...

0
votes

the voltage for the pinuots is 3.3v (except ADC 0-1.8V range (do not exceed!) ) not 5v, so is correct read 1.66v with duty cycle of 50%.

0
votes

Valid pulse width for "Tower Pro sg90" is 500-2400 µs, so valid values for "duty" are 500000-2400000.

This should turn your servo in CW direction:

// On my BBB, polarity is inverted by default
echo 0 > /sys/devices/ocp.2/pwm_test_P8_13.15/polarity

echo 20000000 > /sys/devices/ocp.2/pwm_test_P8_13.15/period 
echo 500000 > /sys/devices/ocp.2/pwm_test_P8_13.15/duty
echo 1 > /sys/devices/ocp.2/pwm_test_P8_13.15/run