Motor drive module --L298N

Recently doing something with the Raspberry Pi, uses L298N module, there are some pits recorded

I use this almost long way
Here Insert Picture Description

This section introduces the L298N module

L298N motor drive module is a module, doing with it is that if we want the motor to rotate, we know, need to add the appropriate voltage to the motor on it, but if we drive more than one motor, or to use the microcontroller or raspberry pie program to control the motor, it is possible to achieve power plug we use, we deserved select "switch" to achieve, and the use of high and low truth table agreed to tell the switch to open Shashi Shashi Hou close. Used to do this thing we call middleware motor drive module, L298N is a commonly used

There are four L2898N for receiving an input of high and low, as shown below

Here Insert Picture Description

Power input terminal

Of course, the light receiving end of the signal, but does not work, L298N two power input, as shown below, is theoretically 7-12V input, I tested, less than 6v greater than and less than 7V, one input is supplied no problem, just turn the motor a bit strenuous. If the voltage is higher than 12v, according to this argument is that Taobao shop outside to take a voltage divider circuit, I have not tried. The output of the next input is the output of a 5v, using the output of the pull down when needed interfaces over the jumper
Here Insert Picture Description

Then output

We have four inputs are in1, in2, in3, in4 two outputs corresponding to the left and right, out1, out2, out3, out4 , twenty-two them together. Then the truth table is very simple
one high and one low, so there is a potential difference, it will work properly
Here Insert Picture Description

Rotating speed

L298N function not only control Shashi Hou start, you can also control the speed, by means of pwm
it is doing, and I did not know the specific principles. Simply know how to use it, we know the number of electric school that is called a periodic function of the square wave, pwm cycle is by changing inside a high duty cycle, that is, the high level of the total cycle time to achieve specific speed changes, internal implementation details I'm not sure. Pwm how to use this feature. As long as the jumper is removed and then next in an end to the control end of the line. We control the two outputs, the two pwm control terminal, the left and right sides of the input
Here Insert Picture Description

Raspberry Pi is then implemented some code

import RPi.GPIO as GPIO
import time
#设置gpio端口编码方式
GPIO.setmode(GPIO.BOARD)
#设置不显示警告
GPIO.setwarnings(False)
#gpio端口定义,方便以后改接线方式
#pwm控制端定义
int1=11
int2=12
int3=13
#初始化函数
GPIO.setup(int2,GPIO.OUT)
GPIO.setup(int3,GPIO.OUT)
GPIO.setup(int1,GPIO.OUT)
#普通输出方式,此时pwm口应该接跳线帽,不然不工作
GPIO.output(int2,GPIO.HIGH)
GPIO.output(int3,GPIO.LOW)
time.sleep(10)
#定义pwm输出model,第一个参数是gpio口,第二个是频率
pwm=GPIO.PWM(int1,80)
pwm.start(90)
while True:
    #改变占空比输出,此时为90
    pwm.ChangeDutyCycle(90)
    time.sleep(10)
    #此时为30
    pwm.ChangeDutyCycle(30)
    time.sleep(10)
#此函数用来释放端口资源,不然电机会一直转下去
#GPIO.cleanup()

Here are some pit

1) Raspberry Pi needs and L298N common ground. It is good to understand, is that you no common ground, then who knows what that level is a low level that is high ah, common ground way is very simple tree gpio of berry pie gnd and power supply together like a negative
2) pull down jumpers use pwm, and if not, must take the jumper caps back, or not work
3) a problem how to do, I way is to use a multimeter, the first test output gpio raspberry pie, and then measuring the motor, so soon be able to determine where the problem lies

Published 15 original articles · won praise 6 · views 3313

Guess you like

Origin blog.csdn.net/weixin_43906877/article/details/104089512