LCD Display장치

 본 프로젝트에서는 16문자 x 2줄 Text를 표시할 수 있고, I2C방식 Interface모듈이 부착되어 있는 다음과 같은 LCD디스플레이 장치를 사용한다.
 

 

 

 

 

LCD 라이브러리 설치
 - 아두이노와 LCD장치간 연결( I2C방식통신)을 하기 위해서는 전용 라이브러리를 추가로 설치해 주어야 한다.
 - IDE 스케치 메뉴 -> 라이브러리 포함하기 -> 라이브러리관리하기 화면에서  "LiquidCrystal I2C" 를 검색하여 설치한다.

 

아두이노와 연결

 


- I2C방식통신을 위해서 위와 같이 전원선과 아날로그 4번핀/5번핀에  연결해야 하나

- 프로토타이핑 보드에서는 편리를 위해 우측과 같이 별도의 핀으로 구성되어 있으므로 여기에 표시된 핀번호끼리 연결해도 되며 아날로그 4번핀/5번핀에 다른 I2C방식 장치를 추가로 연결할 수 있다.    


 

테스트프로그램

  1. #include <Wire.h>   
  2. #include <LiquidCrystal_I2C.h>  
  3. LiquidCrystal_I2C lcd(0x3F,16,2);    
  4.   
  5. void setup()  
  6. {  
  7.   lcd.init();     // initialize the lcd   
  8.   lcd.backlight();  
  9.   lcd.setCursor(0,0);  
  10.   lcd.print("Hello, everyone!");  
  11.   lcd.setCursor(2,1);  
  12.   lcd.print("I am Arduino.");  
  13. }  
  14. void loop()  
  15. {  
  16. }  

3 line: LiquidCrystal_I2C lcd(0x27,16,2);   0x27 Adress에 연결되는 16문자 2줄 짜리 I2C방식 LCD장치를  lcd라는 이름으로 선언
8 line:  lcd.backlight();  : 백라이트 켜기 
9 line: lcd.setCursor(col,line) 로 커서의 위치를 지정한다 ( 숫자는 0부터 시작함에 주의 )    
         예 ) (0,0) : 첫째 줄 첫째 문자,     (2,1) : 둘째 줄 세번째 문자,
10 line: lcd.print("Hello, everyone!"); 현재 커서위치에 지정하는 문자열을 출력

  
-lcd.clear();  : lcd 문자 모두 지우기

 

LCD화면에 문자가 표시 되지 않을 경우 
 - LCD 밝기 조절 볼륨을 돌려 화면 밝기을 조절 해 본다.  

 - LCD I2C장치의 Address는 통상 0x27  또는 0x3F 이므로 Address를 0x27 대신 0x3F를  지정한 후  다시 프로그램 업로드하여 테스트해 본다   (장치 제조사별로 다른 Address를 사용하는 경우도 있는데 아래의 장치 Address  Scan 프로그램으로 현재연결된 장치의 Address를 알아 낼 수 있다. )

참조: 장치 Address scan 프로그램 
 - 다음 소스코드를 아두이노로 업로드하여 실행시키고 툴->시리얼모니터화면에  표시되는 메세지를 보면 현재 연결된 장치의 Adress를 확인할 수 있다. 

  1. #include <Wire.h>   
  2. void setup() {  
  3.     Wire.begin();  
  4.     Serial.begin(9600);  
  5.     while (!Serial);   
  6.     Serial.println("\nI2C Scanner");  
  7. }  
  8. void loop() {   
  9.     byte error, address;   
  10.     int nDevices;   
  11.     Serial.println("Scanning...");   
  12.     nDevices = 0;   
  13.     for(address = 1; address < 127; address++ ) {  
  14.          Wire.beginTransmission(address);  
  15.          error = Wire.endTransmission();  
  16.          if (error == 0) {   
  17.              Serial.print("I2C device found at address 0x");  
  18.              if (address<16) Serial.print("0");   
  19.              Serial.print(address,HEX);   
  20.              Serial.println(" !");  
  21.              nDevices++;   
  22.          }  
  23.          else if (error==4) {   
  24.             Serial.print("Unknow error at address 0x");   
  25.             if (address<16) Serial.print("0");   
  26.             Serial.println(address,HEX);   
  27.          }   
  28.     }   
  29.     if (nDevices == 0)   
  30.          Serial.println("No I2C devices found\n");   
  31.      else Serial.println("done\n");   
  32.      delay(5000);   
  33. }  

+ Recent posts