O'Reilly logo

Mastering BeagleBone Robotics by Richard Grimmett

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Program to control DC motors using the BeagleBone Black

Now that you've connected your motor, here is a simple Python program to control one of the motors:

Program to control DC motors using the BeagleBone Black

Let's look at the details. Here are the individual command statements:

  • #!/usr/bin/python: As noted earlier, this command sets up the program to be executed without invoking Python
  • import Adafruit_BBIO.PWM as PWM: This library is used to communicate with the GPIO pins
  • motor1 = "P8_13": This sets the motor to PWM control P8_13—the 13th pin on the 8th connector
  • duty_stop = 9: This sets the duty cycle of the PWM that is needed to stop the motor
  • duty_forward = 12 # 12 max: This sets the duty cycle of the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required