The BTS7960 motor driver es un potente módulo en puente H capaz de manejar altas corrientes, lo que lo hace ideal para controlar motores de CC en proyectos de robótica y automatización. En este tutorial, aprenderás cómo conectar y controlar el BTS7960 con una Raspberry Pi para accionar un motor.
What You Will Need
- Raspberry Pi (cualquier modelo con capacidades GPIO, p. ej., Pi 3, Pi 4)
- BTS7960 Motor Driver Module
- DC Motor (adecuado para tu proyecto)
- External Power Supply (que coincida con los requisitos de voltaje y corriente de tu motor)
- Breadboard and Jumper Wires
Step 1: Understanding the BTS7960 Motor Driver
El BTS7960 module incluye dos semipuentes de alta potencia capaces de accionar motores con corrientes de hasta 43A. Cuenta con:
- PWM input pins for speed control
- Direction control pins
- Overcurrent and thermal protection
Pinout
| Pin | Description |
|---|---|
| VCC | 5V logic power input |
| GND | Ground |
| RPWM | PWM input for forward motion |
| LPWM | PWM input for reverse motion |
| R_EN | Enable pin for forward motion |
| L_EN | Enable pin for reverse motion |
| Motor+ (M+) | Motor positive terminal |
| Motor- (M-) | Motor negative terminal |
| VIN | External motor power supply |
| GND (Power) | Ground for motor power supply |
Step 2: Wiring the BTS7960 to the Raspberry Pi
Connections
| BTS7960 Pin | Raspberry Pi Pin |
|---|---|
| VCC | 5V |
| GND | GND |
| RPWM | GPIO18 (PWM channel 0) |
| LPWM | GPIO19 (PWM channel 1) |
| R_EN | GPIO23 |
| L_EN | GPIO24 |
Motor and Power Supply Connections
- Connect the motor terminals to the Motor+ (M+) and Motor- (M-) pins.
- Connect the external power supply’s positive terminal to VIN.
- Connect the external power supply’s ground to the GND (Power) pin.
Note: Asegúrate de que la fuente de alimentación externa coincida con los requisitos de voltaje y corriente de tu motor.
Step 3: Enabling PWM on the Raspberry Pi
To control motor speed, you’ll use PWM (Pulse Width Modulation). Raspberry Pi GPIO pins 18 and 19 support hardware PWM.
Enable PWM via Raspberry Pi Configuration
- Open the terminal and run:
sudo raspi-config - Navigate to Interface Options > P5: I2C, and enable I2C.
- Save and reboot the Raspberry Pi:
sudo reboot
Step 4: Writing Python Code to Control the Motor
Install the RPi.GPIO library to control GPIO pins if not already installed:
pip install RPi.GPIO
Example Python Code
This example demonstrates how to control the motor’s speed and direction using the BTS7960.
import RPi.GPIO as GPIO
import time
# Pin Definitions
RPWM_PIN = 18
LPWM_PIN = 19
REN_PIN = 23
LEN_PIN = 24
# GPIO Setup
GPIO.setmode(GPIO.BCM)
GPIO.setup(RPWM_PIN, GPIO.OUT)
GPIO.setup(LPWM_PIN, GPIO.OUT)
GPIO.setup(REN_PIN, GPIO.OUT)
GPIO.setup(LEN_PIN, GPIO.OUT)
# PWM Setup
frequency = 1000 # PWM frequency in Hz
rpwm = GPIO.PWM(RPWM_PIN, frequency)
lpwm = GPIO.PWM(LPWM_PIN, frequency)
# Start PWM with 0% duty cycle (off)
rpwm.start(0)
lpwm.start(0)
try:
while True:
# Enable Forward Motion
GPIO.output(REN_PIN, GPIO.HIGH)
GPIO.output(LEN_PIN, GPIO.LOW)
# Set forward speed (50% duty cycle)
rpwm.ChangeDutyCycle(50)
lpwm.ChangeDutyCycle(0)
time.sleep(2)
# Enable Reverse Motion
GPIO.output(REN_PIN, GPIO.LOW)
GPIO.output(LEN_PIN, GPIO.HIGH)
# Set reverse speed (30% duty cycle)
rpwm.ChangeDutyCycle(0)
lpwm.ChangeDutyCycle(30)
time.sleep(2)
except KeyboardInterrupt:
print("Stopping motor...")
finally:
rpwm.stop()
lpwm.stop()
GPIO.cleanup()
Step 5: Testing Your Setup
- Connect the motor and power supply.
- Run the Python script:
python3 bts7960_control.py - Observe the motor changing speed and direction as programmed.
Troubleshooting
-
Motor Not Running:
- Check wiring connections.
- Verify the external power supply.
-
PWM Not Working:
- Ensure GPIO18 and GPIO19 are configured for PWM.
- Check the duty cycle values in the script.
-
Overheating Module:
- Ensure the motor’s current draw does not exceed the BTS7960’s rating.
Applications of the BTS7960 with Raspberry Pi
- Controlling high-current DC motors in robotics
- Building automated vehicles or robots
- Creating motorized systems for industrial applications
- Developing remote-controlled systems
Conclusion
The BTS7960 motor driver es una solución robusta y eficiente para accionar motores de alta corriente. Combinado con las capacidades GPIO de la Raspberry Pi, abre numerosas posibilidades para proyectos de robótica y automatización. Siguiendo esta guía, puedes configurar y controlar el BTS7960 para crear sistemas motorizados potentes. ¡Experimenta con diferentes frecuencias PWM y ciclos de trabajo para optimizar el rendimiento en tu aplicación específica!
