Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
17 views7 pages

ESP32如何控制LCD

This document provides a guide on how to use the LCD_I2C library for Arduino, including downloading the library, installation steps, wiring diagrams, and example code for displaying messages and using custom characters. It also includes code snippets for various functionalities such as autoscrolling, scrolling left and right, and cursor operations. Additionally, it mentions a tutorial link for using DHT-11/DHT-22 temperature sensors.

Uploaded by

yuxinzhang1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views7 pages

ESP32如何控制LCD

This document provides a guide on how to use the LCD_I2C library for Arduino, including downloading the library, installation steps, wiring diagrams, and example code for displaying messages and using custom characters. It also includes code snippets for various functionalities such as autoscrolling, scrolling left and right, and cursor operations. Additionally, it mentions a tutorial link for using DHT-11/DHT-22 temperature sensors.

Uploaded by

yuxinzhang1107
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 7

一、如何使用 LCD_I2C:

1、下載 LCD_I2C 函式庫,網址如下:


https://www.arduino.cc/reference/en/libraries/lcd_i2c/
點選最近版本的程式庫,即可下載程式庫的安裝檔

2、(1)將程式庫解壓縮後,整個資料夾複製或剪下至 Arduino 資料夾裡--


>libraries 底下,即完成程式庫的安裝。
(2)或是從程式庫管理員裡搜尋並安裝:

(3)搜尋 LCD_I2C,進行安裝或確認已安裝

3、接線圖
4、程式碼:
(1)HELLO WORLD
#include <LCD_I2C.h>

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change
according

void setup()
{
lcd.begin(); // If you are using more I2C devices using the Wire library use
lcd.begin(false)
// this stop the library(LCD_I2C) from calling Wire.begin()
lcd.backlight();
}

void loop()
{
lcd.print(" Hello"); // You can make spaces using well... spaces
lcd.setCursor(5, 1); // Or setting the cursor in the desired position.
lcd.print("World!");
delay(500);

// Flashing the backlight


for (int i = 0; i < 5; ++i)
{
lcd.backlight();
delay(50);
lcd.noBacklight();
delay(50);
}

lcd.backlight();
lcd.clear();
delay(500);
}

(2)Function
#include <LCD_I2C.h>

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change
according
/*
* When using lcd.print() (and almost everywhere you use string literals),
* is a good idea to use the macro F(String literal).
* This tells the compiler to store the string array in the flash memory
* instead of the ram memory. Usually you have more spare flash than ram.
* More info:
https://www.arduino.cc/reference/en/language/variables/utilities/progmem/
*/

void setup()
{
lcd.begin();
lcd.backlight();
}

void loop()
{
//Autoscroll
lcd.setCursor(5, 0);
lcd.print(F("Autoscrolling"));
lcd.setCursor(10, 1);
lcd.autoscroll();

for (int i = 0; i < 10; i++)


{
lcd.print(i);
delay(200);
}

lcd.noAutoscroll();
lcd.clear();

// Scroll left and right


lcd.setCursor(10, 0);
lcd.print(F("To the left!"));
for (int i = 0; i < 10; i++)
{
lcd.scrollDisplayLeft();
delay(200);
}
lcd.clear();
lcd.print(F("To the right!"));
for (int i = 0; i < 10; i++)
{
lcd.scrollDisplayRight();
delay(200);
}
lcd.clear();

//Cursor
lcd.setCursor(0, 0);
lcd.cursor();
lcd.print(F("Cursor"));
delay(3000);
lcd.clear();

//Cursor blink
lcd.setCursor(0, 0);
lcd.blink();
lcd.print(F("Cursor blink"));
delay(3000);
lcd.clear();

//Blink without cursor


lcd.setCursor(0, 0);
lcd.noCursor();
lcd.print(F("Just blink"));
delay(3000);
lcd.noBlink();
lcd.clear();
}

(3)Custom_Chars
#include <LCD_I2C.h>

LCD_I2C lcd(0x27, 16, 2); // Default address of most PCF8574 modules, change
according

uint8_t happy[8] =
{
0b00000,
0b10001,
0b00000,
0b00000,
0b10001,
0b01110,
0b00000,
0b00000,
};

uint8_t wow[8] =
{
0b00000,
0b10001,
0b00000,
0b01110,
0b10001,
0b01110,
0b00000,
0b00000,
};

uint8_t anchor[8] =
{
0b01110,
0b01010,
0b01110,
0b00100,
0b10101,
0b10101,
0b01110,
0b00100
};

uint8_t snow[8] =
{
0b01000,
0b11101,
0b01011,
0b00001,
0b00100,
0b01110,
0b00100,
0b10000
};
void setup()
{
lcd.begin();
lcd.backlight();

lcd.createChar(0, happy);
lcd.createChar(1, wow);
lcd.createChar(2, anchor);
lcd.createChar(3, snow);

lcd.write(0);
lcd.write(1);
lcd.write(2);
lcd.write(3);
}

void loop()
{
}

二、DHT-11/DHT-22 溫度感測器
教學網址
https://randomnerdtutorials.com/esp32-dht11-dht22-temperature-humidity-sensor-
arduino-ide/

You might also like