Obtenga entrega gratuita en todas las órdenes más de £20!

Usando el BTS7960 con la Raspberry Pi

Using the BTS7960 with the Raspberry Pi

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

  1. Raspberry Pi (cualquier modelo con capacidades GPIO, p. ej., Pi 3, Pi 4)
  2. BTS7960 Motor Driver Module
  3. DC Motor (adecuado para tu proyecto)
  4. External Power Supply (que coincida con los requisitos de voltaje y corriente de tu motor)
  5. 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

  1. Connect the motor terminals to the Motor+ (M+) and Motor- (M-) pins.
  2. Connect the external power supply’s positive terminal to VIN.
  3. 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

  1. Open the terminal and run:
    sudo raspi-config
    
  2. Navigate to Interface Options > P5: I2C, and enable I2C.
  3. 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

  1. Connect the motor and power supply.
  2. Run the Python script:
    python3 bts7960_control.py
    
  3. Observe the motor changing speed and direction as programmed.

Troubleshooting

  1. Motor Not Running:

    • Check wiring connections.
    • Verify the external power supply.
  2. PWM Not Working:

    • Ensure GPIO18 and GPIO19 are configured for PWM.
    • Check the duty cycle values in the script.
  3. Overheating Module:

    • Ensure the motor’s current draw does not exceed the BTS7960’s rating.

Applications of the BTS7960 with Raspberry Pi

  1. Controlling high-current DC motors in robotics
  2. Building automated vehicles or robots
  3. Creating motorized systems for industrial applications
  4. 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!

Notice an Issue? Have a Suggestion?
If you encounter a problem or have an idea for a new feature, let us know! Report a problem or request a feature here.

Escribir un comentario