Search Code

LCD1602를 I2C 인터페이스와 함께 사용하기 - Arduino 튜토리얼

LCD1602를 I2C 인터페이스와 함께 사용하기 - Arduino 튜토리얼

이 튜토리얼은 I2C 모듈을 사용하여 1602 LCD 디스플레이를 Arduino와 연결하는 방법을 보여줍니다. 기존의 병렬 배선 방식보다 연결이 더 쉽고 깔끔합니다. 단 네 개의 연결(VCC, GND, SDA, SCL)만으로 디스플레이를 완전히 제어하고 Arduino 프로젝트에서 텍스트나 센서 데이터를 표시할 수 있습니다.

LCD1602-I2C display module with 4 wires

필요한 모든 코드, 배선도 및 라이브러리 다운로드 링크는 이 문서 아래에 제공됩니다.

I2C가 있는 LCD1602란 무엇인가?

LCD1602는 임베디드 시스템에서 일반적으로 사용되는 16자 2줄 디스플레이입니다. 일반적으로 작동하려면 6~10개의 핀이 필요하지만, I2C 모듈을 추가하면 통신에 두 개의 데이터 라인(SDA 및 SCL)만 필요합니다. 이렇게 하면 배선이 크게 간소화되고 Arduino의 다른 구성 요소에 더 많은 핀을 사용할 수 있습니다.

LCD1602를 Arduino에 배선하기

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C

I2C 모듈이 있는 LCD1602를 Arduino Uno에 배선하는 방법은 다음과 같습니다:

  • VCC- 5V

  • GNDGND

  • SDAA4

  • SCL -A5

캡션: LCD1602가 4개의 전선만 사용하여 I2C를 통해 Arduino에 연결됨.

- LCD에 텍스트 표시하기 위한 코드 설명

아래 코드는 LCD를 초기화하고 백라이트를 켠 다음 루프에서 텍스트를 출력합니다.

cppCopyEdit#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// 16자 2줄 디스플레이의 LCD 주소를 0x27로 설정
LiquidCrystal_I2C lcd(0x27, 16, 2);

  • Wire.h: I2C 통신에 필요합니다.

  • LiquidCrystal_I2C.h: I2C를 사용하여 LCD를 제어하는 라이브러리입니다.

  • lcd(0x27, 16, 2): 주소 0x27, 16열 2행으로 LCD를 초기화합니다.

cppCopyEditvoid setup()
{
  lcd.begin();       // LCD 초기화
  lcd.backlight();   // 백라이트 켜기
}

  • lcd.begin()은 LCD를 사용할 준비를 합니다.

  • lcd.backlight()은 디스플레이의 백라이트를 켭니다.

cppCopyEditvoid loop()
{
  lcd.clear();                 // 이전 내용 지우기
  lcd.print("Robojax");        // 첫 번째 줄에 출력
  lcd.setCursor(0,1);          // 두 번째 줄의 시작으로 커서 이동
  lcd.print("Hello World!");   // 두 번째 줄에 출력
  delay(500);                  // 0.5초 대기
}

  • 화면은 0.5초마다 새로 고쳐집니다.

  • 시간이나 센서 값과 같은 다른 데이터도 표시할 수 있습니다.

필요한 라이브러리 설치

LiquidCrystal_I2C 라이브러리를 설치해야 합니다:

  1. Arduino IDE를 엽니다

  2. 스케치 > 라이브러리 포함 > 라이브러리 관리로 이동합니다

  3. LiquidCrystal_I2C를 검색합니다

  4. 설치를 클릭합니다

설치가 완료되면 코드를 컴파일하고 업로드할 준비가 된 것입니다.

비디오의 챕터

  • 00:00 - 시작

  • 00:35 -LCD1602 및 I2C 모듈 설명

  • 04:37 -배선 설명

  • 05:35 -LCD1602-I2C 라이브러리 다운로드

  • 07:13 -LCD1602용 코드 설명

 

 

이미지

Arduino wirng for LCD1602 with I2C
Arduino wirng for LCD1602 with I2C
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
LCD1602-I2C display module with 4 wires
63-This is code for an LCD1602 display with an I2C module.
언어: C++
/*
This is code for LCD1602 Display with I2C module
 * Watch the video for this code https://youtu.be/q9YC_GVHy5A
 
 * Permission granted to share this code given that this
 * note is kept with the code.
 * Disclaimer: this code is "AS IS" and for educational purposes only.
 * This library is based on work done by DFROBOT (www.dfrobot.com).
 */
/*
 *  This code has been modified from the Arduino library
 *  Updated by Ahmad Nejrabi on Jan 20, 2018 at 11:09
 *  in Ajax, Ontario, Canada
 *  for Robojax.com
 *  
 *  This is code for LCD1602 Display with I2C module
 *  which can display text on the screen.
 */
#include <Wire.h> 
#include <LiquidCrystal_I2C.h>

// Set the LCD address to 0x27 for a 16 chars and 2 line display
LiquidCrystal_I2C lcd(0x27, 16, 2);

void setup()
{
  // Robojax code for LCD with I2C
	// initialize the LCD, 
	lcd.begin();
 
	// Turn on the backlight and print a message.
	lcd.backlight();
  // Robojax code for LCD with I2C


}

void loop()
{
  
  //start of loop Robojax code for LCD with I2C
  lcd.clear();
  lcd.print("Robojax");
  lcd.setCursor (0,1); // go to start of 2nd line
 lcd.print("Hello World!");
  //lcd.print(millis() / 1000);
  delay(500);
 //end of loop Robojax code for LCD with I2C
}

필요할 수 있는 것들

파일📁

아두이노 라이브러리 (zip)

프리징 파일