日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

python arduino i2c1602_Arduino通过I2C(PCF8574T)驱动1602LCD

發布時間:2024/4/19 python 37 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python arduino i2c1602_Arduino通过I2C(PCF8574T)驱动1602LCD 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Arduino中使用I2C通信可直接調用Wire.h庫, 這個庫允許Arduino鏈接其他I2C設備, 鏈接線有兩條, 分別是SDA(數據行)和SCI(時鐘線). 各型號Arduino的I2C對應引腳:

Arduino Board:I2C / TWI pins

Arduino Uno/Ethernet:A4 (SDA), A5 (SCL)

Arduino Mega2560:20 (SDA), 21 (SCL)

Arduino Leonardo:2 (SDA), 3 (SCL)

Arduino Due:20 (SDA), 21 (SCL), SDA1, SCL1

一般購買到的是分開的兩個組件, 需要按下圖這樣將PCF8574T焊接到1602LCD上

PCF8574T模塊4pin(Gnd, Vcc, SDA i2c數據, SCL i2c時鐘)和Arduino接口的對應關系: Gnd -> Gnd, Vcc -> Vcc, SDA -> A4, SDL -> A5

獲取I2C地址

#include

voidsetup() {

Serial.begin (115200); //Leonardo: wait for serial port to connect

while (!Serial) { }

Serial.println ();

Serial.println ("I2C scanner. Scanning ...");byte count = 0;

Wire.begin();for (byte i = 8; i < 120; i++) {

Wire.beginTransmission (i);if (Wire.endTransmission () == 0) {

Serial.print ("Found address:");

Serial.print (i, DEC); Serial.print ("(0x");

Serial.print (i, HEX); Serial.println (")");

count++; delay (1); //maybe unneeded?

} //end of good response

} //end of for loop

Serial.println ("Done.");

Serial.print ("Found");

Serial.print (count, DEC);

Serial.println ("device(s).");

}//end of setup

void loop() {}

運行時, 打開Serial Monitor, 將波特率設為115200, 看到的輸出就是I2C地址

自帶LiquidCrystal_I2C顯示測試

在運行顯示測試前檢查是否已經安裝了library: LiquidCrystal, LiquidCrystal_I2C

#include #include

//I2C地址, 一般為0x3F, 0x20或0x27

LiquidCrystal_I2C lcd(0x27,16,2);voidsetup() {

lcd.init();

lcd.backlight();//打開背光

}voidloop() {

lcd.setCursor(0,0);

lcd.print("LCD1602 iic Test");

lcd.setCursor(0,1);

lcd.print("0123456789ABCDEF");

delay(1000);

}

如果屏幕亮但是無顯示, 可以調節背后的電位器讓字符顯示到合適的對比度.

第三方New LiquidCrystal顯示測試

#include #include#includeLiquidCrystal_I2C lcd(0x27,2,1,0,4,5,6,7); //0x27 is the I2C bus address for an unmodified backpack

void setup() { //activate LCD module

lcd.begin (16,2); //for 16 x 2 LCD module

lcd.setBacklightPin(3,POSITIVE);

lcd.setBacklight(HIGH);

}voidloop() {

lcd.home ();//set cursor to 0,0

lcd.print("HELLO WORLD....");

lcd.setCursor (0,1); //go to start of 2nd line

lcd.print(millis());

delay(1000);

lcd.setBacklight(LOW);//Backlight off

delay(1000);

lcd.setBacklight(HIGH);//Backlight on

}

供電和耗電測試

硬件是Arduino NANO + 擴展板 + PCF8574T + 1602LCD, 使用輸入電壓12V. 擴展板本身不帶IC, 只有一個電源LED, 功耗可以忽略. 在使用自帶的LiquidCrystal_I2C庫跑上面的測試代碼時, 測得的功耗僅為0.95W左右.

總結

以上是生活随笔為你收集整理的python arduino i2c1602_Arduino通过I2C(PCF8574T)驱动1602LCD的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。