python arduino i2c1602_Arduino通过I2C(PCF8574T)驱动1602LCD
Arduino中使用I2C通信可直接調(diào)用Wire.h庫, 這個庫允許Arduino鏈接其他I2C設(shè)備, 鏈接線有兩條, 分別是SDA(數(shù)據(jù)行)和SCI(時鐘線). 各型號Arduino的I2C對應(yīng)引腳:
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數(shù)據(jù), SCL i2c時鐘)和Arduino接口的對應(yīng)關(guān)系: 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() {}
運(yùn)行時, 打開Serial Monitor, 將波特率設(shè)為115200, 看到的輸出就是I2C地址
自帶LiquidCrystal_I2C顯示測試
在運(yùn)行顯示測試前檢查是否已經(jīng)安裝了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);
}
如果屏幕亮但是無顯示, 可以調(diào)節(jié)背后的電位器讓字符顯示到合適的對比度.
第三方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 + 擴(kuò)展板 + PCF8574T + 1602LCD, 使用輸入電壓12V. 擴(kuò)展板本身不帶IC, 只有一個電源LED, 功耗可以忽略. 在使用自帶的LiquidCrystal_I2C庫跑上面的測試代碼時, 測得的功耗僅為0.95W左右.
總結(jié)
以上是生活随笔為你收集整理的python arduino i2c1602_Arduino通过I2C(PCF8574T)驱动1602LCD的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: python连接池框架_python p
- 下一篇: vector 查找_同样是Excel中的