您好,登录后才能下订单哦!
这篇文章主要介绍了Raspberry PI+L298N怎么用,具有一定借鉴价值,感兴趣的朋友可以参考下,希望大家阅读完这篇文章之后大有收获,下面让小编带着大家一起了解一下。
L298N 是一种双H桥电机驱动芯片,可以通过树莓派的GPIO的高低电平来控制L298N的行为。
L298N:
root@raspberrypi:~# gpio readall +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | | | 3.3v | | | 1 || 2 | | | 5v | | | | 2 | 8 | SDA.1 | IN | 1 | 3 || 4 | | | 5V | | | | 3 | 9 | SCL.1 | IN | 1 | 5 || 6 | | | 0v | | | | 4 | 7 | GPIO. 7 | IN | 1 | 7 || 8 | 1 | ALT0 | TxD | 15 | 14 | | | | 0v | | | 9 || 10 | 1 | ALT0 | RxD | 16 | 15 | | 17 | 0 | GPIO. 0 | IN | 0 | 11 || 12 | 0 | IN | GPIO. 1 | 1 | 18 | | 27 | 2 | GPIO. 2 | IN | 0 | 13 || 14 | | | 0v | | | | 22 | 3 | GPIO. 3 | IN | 0 | 15 || 16 | 1 | IN | GPIO. 4 | 4 | 23 | | | | 3.3v | | | 17 || 18 | 0 | IN | GPIO. 5 | 5 | 24 | | 10 | 12 | MOSI | IN | 0 | 19 || 20 | | | 0v | | | | 9 | 13 | MISO | IN | 0 | 21 || 22 | 0 | IN | GPIO. 6 | 6 | 25 | | 11 | 14 | SCLK | IN | 0 | 23 || 24 | 1 | IN | CE0 | 10 | 8 | | | | 0v | | | 25 || 26 | 1 | IN | CE1 | 11 | 7 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | 28 | 17 | GPIO.17 | IN | 0 | 51 || 52 | 0 | IN | GPIO.18 | 18 | 29 | | 30 | 19 | GPIO.19 | IN | 0 | 53 || 54 | 0 | IN | GPIO.20 | 20 | 31 | +-----+-----+---------+------+---+----++----+---+------+---------+-----+-----+ | BCM | wPi | Name | Mode | V | Physical | V | Mode | Name | wPi | BCM | +-----+-----+---------+------+---+-Model B2-+---+------+---------+-----+-----+
12V:12V输入正极
GND:电源地,接电源负极
5V:5V输入,暂时不太明白这个的作用
ENA:A通道使能
IN1:A通道逻辑输入1
IN2:A通道逻辑输入2
OUT1: A通道输出
OUT2: A通道输出
ENB:B通道使能
IN3:B通道逻辑输入1
IN4:B通道逻辑输入2
OUT3: B通道输出
OUT4: B通道输出
树莓派和L298N的接线:
GPIO.0 -- IN1
GPIO.1 -- IN2
GPIO.4 -- ENA
L298N 输入12v供电 OUT1,OUT2接马达
代码如下:
import RPi.GPIO as GPIO import time GPIO.setmode(GPIO.BOARD) INTA = 16 INT1 = 11 INT2 = 12 GPIO.setup(INTA,GPIO.OUT) GPIO.setup(INT1,GPIO.OUT) GPIO.setup(INT2,GPIO.OUT) # 使能信号 GPIO.output(INTA,GPIO.HIGH) # 控制转动方向及制动,参考上图表格 GPIO.output(INT2,GPIO.HIGH) GPIO.output(INT1,GPIO.LOW) time.sleep(10) GPIO.cleanup()
感谢你能够认真阅读完这篇文章,希望小编分享的“Raspberry PI+L298N怎么用”这篇文章对大家有帮助,同时也希望大家多多支持亿速云,关注亿速云行业资讯频道,更多相关知识等着你来学习!
免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。