Translate

2023年4月17日 星期一

使用tinkercad模擬arduino 控制LCD 16X2(I2C) PCF8574

 tinkercad 預設的LCD I2C範例係使用MCP23008型

電路接線

將LCD的VCC接到Arduino板上的5V、GND(LCD)接GND(Arduino)、SCL(LCD)接A5或Aref左邊第2腳(Arduino)、SDA(LCD)接A4或Aref左邊第1腳(Arduino)


但因為自已係使用PCF8574型,範例程式沒辦法使用。網路上找了一些資料如下面範例。

點選LCD可以將類型改成PCF8574型,地址用預設的32,也可以改成您想要的,但呼叫元件時第1個參數記得改您最後設定值。


#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(32,16,2);  //設定參數(地址,行數,列數)

void setup()
{
  lcd.init();                      // initialize the lcd 
  // Print a message to the LCD.
  lcd.backlight();
  lcd.setCursor(0,0);
  lcd.print("Hello, world!");
  lcd.setCursor(0,1);
  lcd.print("2023/04/17");
  lcd.setCursor(0,2);
}

void loop()
{

}