Principle and application of L298N drive module (drive trolley)

Principle and application of L298N drive module (drive trolley)

L298N driver module, the main output is 4 parts;

 power supply pin;

  • VCC DC power supply pin (5~35v) In this experiment, we use a 12v battery box to power it
  • GND
  • 5V is the internal logic power supply pin of the drive chip. If a 5V jumper is installed, this pin can output 5V voltage to provide power for the microcontroller board or other circuits. If the 5V jumper is removed, an independent external 5V power supply is required pin;

Control pins:

  • IN1 & IN2  are the input pins of motor driver A to control the rotation and rotation angle of motor A
    • IN1 inputs high level HIGH, IN2 inputs low level LOW, corresponding to motor A forward rotation
    • IN1 input low level LOW, IN2 input high level HIGH, corresponding to motor A reverse
    • IN1 and IN2 input high level HIGH or low level LOW at the same time, the corresponding motor A stops rotating
    • Speed ​​regulation is to change the duty cycle of the high level of IN1 and IN2 (need to unplug the jumper at the ENA)

  • IN3 & IN4  are the input pins of motor driver B to control the rotation and rotation angle of motor B
    • IN3 input high level HIGH, IN4 input low level LOW, corresponding to motor B forward rotation
    • IN3 input low level LOW, IN4 input high level HIGH, corresponding to the reverse rotation of motor B
    • IN3 and IN4 input high level HIGH or low level LOW at the same time, the corresponding motor B stops rotating
    • Speed ​​regulation is to change the duty cycle of the high level of IN3 and IN4 (need to unplug the jumper at ENB)

output pin

  • OUT1 and OUT2  are the output pins of motor driver A, connected to A+ and A- of DC motor A or stepping motor
  • OUT3 and OUT3  output pins of motor driver B, connected to B+ and B- of DC motor B or stepping motor

Speed ​​control pin (this experiment does not involve speed control)

  • ENA  motor A speed control switch pin, unplug the jumper cap, use PWM to adjust the speed of motor A, plug in motor A to run at high speed
  • ENB  motor B speed control switch pin, unplug the jumper cap, use PWM to adjust the speed of motor B, plug in motor B to run at high speed

Experimental operation --- drive the car

1. Installation and connection

Pay attention to the positive and negative connection of 2 motors and out1-out4

 Note that the negative pole of the battery box should be connected with the corresponding GND of the Raspberry Pi

2. Python code---forward and backward (turning to realize single wheel rotation)

#小车之电机
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BOARD)        #选择物理引脚编码

IN1 = 11                        #设置对应引脚
IN2 = 12
IN3 = 13
IN4 = 15
#11,12,13,15设置为输出引脚
GPIO.setup(IN1,GPIO.OUT)
GPIO.setup(IN2,GPIO.OUT)
GPIO.setup(IN3,GPIO.OUT)
GPIO.setup(IN4,GPIO.OUT)
#进行循环实验
try:
    while True:                #实现小车三秒前进三秒后退
        #前进,11&13设置为高电平
        GPIO.output(IN1,1)
        GPIO.output(IN2,0)
        #
        GPIO.output(IN3,1)
        GPIO.output(IN4,0)        #注意注意连接电机和对应正负极
                    
        time.sleep(3)
        #后退
        GPIO.output(IN1,0)
        GPIO.output(IN2,1)

        GPIO.output(IN3,0)
        GPIO.output(IN4,1)
        time.sleep(3)

except KeyboardInterrupt:        #中断实验ctal+c
    pass

GPIO.cleanup()                    #释放资源--防止损坏树莓派

Guess you like

Origin blog.csdn.net/JLwwfs/article/details/125959779