您好,登錄后才能下訂單哦!
這篇文章主要介紹了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進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。