adafruit_motor.motor

Simple control of a DC motor. DC motors have two wires and should not be connected directly to the PWM connections. Instead use intermediate circuitry to control a much stronger power source with the PWM. The Adafruit Stepper + DC Motor FeatherWing, Adafruit TB6612 1.2A DC/Stepper Motor Driver Breakout Board and Adafruit Motor/Stepper/Servo Shield for Arduino v2 Kit - v2.3 do this for popular form factors already.

Note

The TB6612 boards feature three inputs XIN1, XIN2 and PWMX. Since we PWM the INs directly its expected that the PWM pin is consistently high.

  • Author(s): Scott Shawcroft
class adafruit_motor.motor.DCMotor(positive_pwm, negative_pwm)[source]

DC motor driver. positive_pwm and negative_pwm can be swapped if the motor runs in the opposite direction from what was expected for “forwards”.

Parameters:
  • positive_pwm (PWMOut) – The motor input that causes the motor to spin forwards when high and the other is low.
  • negative_pwm (PWMOut) – The motor input that causes the motor to spin backwards when high and the other is low.
deinit()[source]

Stop using the motor.

throttle

Motor speed, ranging from -1.0 (full speed reverse) to 1.0 (full speed forward), or None. If None, both PWMs are turned full off. If 0.0, both PWMs are turned full on.

adafruit_motor.servo

Servos are motor based actuators that incorporate a feedback loop into the design. These feedback loops enable pulse width modulated control to determine position or rotational speed.

  • Author(s): Scott Shawcroft
class adafruit_motor.servo.ContinuousServo(pwm_out, *, min_pulse=750, max_pulse=2250)[source]

Control a continuous rotation servo.

Parameters:
  • min_pulse (int) – The minimum pulse width of the servo in microseconds.
  • max_pulse (int) – The maximum pulse width of the servo in microseconds.
deinit()[source]

Stop using the servo.

throttle

How much power is being delivered to the motor. Values range from -1.0 (full throttle reverse) to 1.0 (full throttle forwards.) 0 will stop the motor from spinning.

class adafruit_motor.servo.Servo(pwm_out, *, actuation_range=180, min_pulse=750, max_pulse=2250)[source]

Control the position of a servo.

Parameters:
  • pwm_out (PWMOut) – PWM output object.
  • actuation_range (int) – The physical range of motion of the servo in degrees, for the given min_pulse and max_pulse values.
  • min_pulse (int) – The minimum pulse width of the servo in microseconds.
  • max_pulse (int) – The maximum pulse width of the servo in microseconds.

actuation_range is an exposed property and can be changed at any time:

servo = Servo(pwm)
servo.actuation_range = 135

The specified pulse width range of a servo has historically been 1000-2000us, for a 90 degree range of motion. But nearly all modern servos have a 170-180 degree range, and the pulse widths can go well out of the range to achieve this extended motion. The default values here of 750 and 2250 typically give 135 degrees of motion. You can set actuation_range to correspond to the actual range of motion you observe with your given min_pulse and max_pulse values.

Warning

You can extend the pulse width above and below these limits to get a wider range of movement. But if you go too low or too high, the servo mechanism may hit the end stops, buzz, and draw extra current as it stalls. Test carefully to find the safe minimum and maximum.

actuation_range

The physical range of motion of the servo in degrees.

angle

The servo angle in degrees. Must be in the range 0 to actuation_range.