Try   HackMD

LCD 1602 顯示器 (I2C)

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

基礎小知識

LCD 1602 顯示器 (I2C)

技術規格

  • 顯示字符:16 * 2 (一行 16 個 字符 , 共有 2 行可輸出)
  • 字元尺寸:2.95mm × 4.35mm
  • 工作電壓:4.5-5.5V

簡單實作

接線圖:

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

GND GND
VCC 5V
SDA Pin A4
SCL Pin A5

程式碼:

#include <LCD_I2C.h> //引用LCD_I2C.h 函式庫

LCD_I2C lcd(0x27, 16, 2); // 0x3F 也可


void setup()
{
    Serial.begin(115200); // 設定序列埠通訊頻率
    lcd.begin(); // 用於手動輸入文字
    for(int i = 0; i < 3; i++) {
        lcd.backlight();  // 開啟背光
        delay(250);
        lcd.noBacklight(); // 關閉背光
        delay(250);
    }
    lcd.backlight();
    lcd.setCursor(0, 0); // 設定游標位置在第一行行首
    lcd.print("Hello, world!");
    delay(1000);
    lcd.setCursor(0, 1); // 設定游標位置在第二行行首
    lcd.print("Nice, Meet You");
    delay(8000);
    lcd.clear();
    }
void loop()
{
    // 當使用者手動輸入訊息
    if (Serial.available()) {
        delay (100); // 等待一小段時間,確認資料都接收下來了
        lcd . clear(); // 清除舊訊息
        lcd.setCursor(0, 0);
        while ( Serial.available() > 0 ) { // 讀取新訊息
            char ch = Serial.read() ; // 將訊息顯示在 LCD 上
            lcd.write(ch);
        }
    }
}

延伸實作