아두이노
아두이노 LCD 디스플레이(I2C) 채널 알아보는 방법 및 글자 출력하기
놀이방사장님
2024. 1. 7. 19:26
728x90
반응형
안녕하세요 놀이방사장입니다.
이번 포스팅은 아두이노
LCD 디스플레이(I2C) 채널 알아보는 방법과
글자 출력하는 방법을 알아보겠습니다.
I2C를 사용하면 핀을 여러개 사용하지 않고
4개만 사용해도 출력이 가능합니다.
딱 이 LCD입니다. 뒤에 저렇게 핀이 4개 있어야 해요
일단 핀은 [I2C 모듈 - 아두이노 우노]
[VCC - 5V]
[GND - GND]
[SDA- A4]
[SCL - A5]
이렇게 세팅하였습니다.
LCD를 이용할려면
위에 라이브러리를 추가하여야합니다.
라이브러리 매니저에 LiquidCrystal_I2C 라고 치면 나옵니다.
세팅할 떄 채널주소, 글자수, 라인수를 적어줘야합니다.
#include<LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27, 16, 2);
//(채널주소, 글자수, 라인수)
void setup() {
//LCD 초기화
lcd.init();
//LCD 백라이트 켜기
lcd.backlight();
}
void loop() {
// put your main code here, to run repeatedly:
String firstStr = "Hello World";
String secondStr = "2024-01-07";
lcd.setCursor(2, 0);
lcd.print(firstStr);
lcd.setCursor(2, 1);
lcd.print(secondStr);
}
저기에 나오는 채널은 뒤에 나오는 소스를 적고 실행시킨 다음에 시리얼 모니터를 확인하면 나와요
저 소스를 우노에 업로드해주면
이렇게 나옵니다.
커서가 어디에 글자를 출력할 지 정해주는 메소드입니다.
이제 채널을 알아보는 방법은
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
/*
#include <Wire.h>
void setup()
{
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop()
{
byte error, address;
int nDevices;
Serial.println("Scanning...");
nDevices = 0;
for(address = 1; address < 127; address++ )
{
// The i2c_scanner uses the return value of
// the Write.endTransmisstion to see if
// a device did acknowledge to the address.
Wire.beginTransmission(address);
error = Wire.endTransmission();
if (error == 0)
{
Serial.print("I2C device found at address 0x");
if (address<16)
Serial.print("0");
Serial.print(address,HEX);
Serial.println(" !");
nDevices++;
}
else if (error==4)
{
Serial.print("Unknown error at address 0x");
if (address<16)
Serial.print("0");
Serial.println(address,HEX);
}
}
if (nDevices == 0)
Serial.println("No I2C devices found\n");
else
Serial.println("done\n");
delay(5000); // wait 5 seconds for next scan
}*/
이 소스를 복붙해서 사용하시면 됩니다!
반응형