The Adafruit DC+Stepper Motor HAT is a versatile motor driver board designed for use with the Raspberry Pi. This HAT (Hardware Attached on Top) allows users to control up to four DC motors or two stepper motors, as well as two servo motors, making it an ideal choice for a wide range of robotics and automation projects. With its easy-to-use Python library, users can quickly get their motors running without having to deal with complex wiring or intricate motor control algorithms.
Pin Number | Description |
---|---|
1-4 | Motor/Stepper Outputs |
5-6 | Servo Motor Outputs |
SDA, SCL | I2C Data and Clock lines |
GND | Ground |
5V | 5V Power for logic |
6-16V | Motor Power Supply (VMOT) |
Q: Can I control more than two stepper motors with this HAT? A: No, the HAT is designed to control up to two stepper motors at a time.
Q: Is it possible to stack multiple HATs to control more motors? A: Yes, you can stack multiple Motor HATs on top of a Raspberry Pi, assigning unique I2C addresses to each.
Q: Can I power the Raspberry Pi through the Motor HAT? A: No, the Motor HAT does not provide power to the Raspberry Pi. You need to power the Raspberry Pi separately.
Below is an example Python code snippet for controlling a DC motor with the Adafruit DC+Stepper Motor HAT. Ensure you have installed the Adafruit Motor HAT Python library before running this code.
from Adafruit_MotorHAT import Adafruit_MotorHAT, Adafruit_DCMotor
mh = Adafruit_MotorHAT(addr=0x60)
myMotor = mh.getMotor(3)
myMotor.setSpeed(150)
myMotor.run(Adafruit_MotorHAT.FORWARD)
Remember to wrap up your code with proper cleanup to ensure that the motor stops when your script ends or is interrupted.
```python
def turnOffMotors(): mh.getMotor(1).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(2).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(3).run(Adafruit_MotorHAT.RELEASE) mh.getMotor(4).run(Adafruit_MotorHAT.RELEASE)
import atexit atexit.register(turnOffMotors)
This documentation provides a starting point for working with the Adafruit DC+Stepper Motor HAT. For more detailed information, refer to the official Adafruit documentation and the Python library's API.