'가변저항'에 해당되는 글 2건

  1. 2019.11.19 Hardware | LCD2004 를 arduino 로 컨트롤 해보기 - 2
  2. 2019.10.08 Hardware | LCD2004 를 arduino 로 컨트롤 해보기 - 1

Hardware | LCD2004 를 arduino 로 컨트롤 해보기 - 2

|

이 글은, 먼저 LCD 20x4 를 처음 사용해 본 글의 후편입니다.


* Hardware | LCD2004 를 arduino 로 컨트롤 해보기 - 1

https://chocoball.tistory.com/entry/Hardware-LCD2004-arduino-control-1




1. 이론적 배경


LCD2004 및 HD44780 을 사용하는 LCD 에 대해서는 아래 웹사이트에서 거의 완벽하게 설명하고 있습니다.


* Arduino with HD44780 based Character LCDs

http://www.martyncurrey.com/arduino-with-hd44780-based-lcds/


위의 글은 전반적인 이야기 이고, 아래에 보이는 글 두 개는, 커스텀 글짜에 대한 좀 더 자세한 이야기 입니다.


* How to generate and display self made Custom characters on 16×2 lcd

https://www.engineersgarage.com/knowledge_share/making-custom-characters-on-16x2-lcd/


An internal ​CG-RAM(character generated ram) in which we can generate or place our custom character. CG-RAM size is 64 bytes. We can generate/place 8 characters of size 5×8 at a time in CG-RAM.


* Making and displaying Custom characters on lcd with Arduino Uno and 16×2 lcd

https://www.engineersgarage.com/arduino/making-custom-characters-on-lcd-using-arduino/


CG-RAM is the main component in making custom characters. CG stands for custom generated and RAM you all know random access memory. This CG-RAM stores our custom characters once we declare them in our code. I will come on it later. As you know once we write any type of code we need a memory to store it and a controller to run it. In the 16×2 lcd custom character case its same. We write code(arrays) of character’s which we want to display on lcd. Then we store them in a memory on lcd. In our case this memory is named as CG-RAM(Character generated RAM). 


CG-RAM size is 64 Bytes. You can create 8 characters at a time and load them in cg-ram. Each character occupies 8-bytes. Eight characters each of eight byte (8-characters * 8-Bytes) is equal to 8×8=64 Bytes. CG-RAM address in lcd memory starts from 0x40(Hexadecimal) or 64 in decimal.


위의 글들을 요약하자면 다음과 같습니다.


- HD44780 을 사용하는 LCD 에서는 커스텀 글자를 만들 수 있다.

- 64 Bytes 메모리 한계로, 커스컴 글자는 8개까지만 가능.

- 어드레스는, 0x00~0x07 로 접근 가능.




2. 한땀 한땀 만들어 보기


Custom Character 제작 시, 어떤 형식으로 메모리에 올리는지를 자동으로 소스까지 생성해 주는 페이지 입니다.

이 페이지에서, 8x5 형상에 원하는 모양을 마우스로 클릭해 보면, 대충 감을 잡을 수 있습니다.


* LCD Custom Character Generator

http://maxpromer.github.io/LCD-Character-Creator/


위의 페이지를 따라해 보면, Parallel 연결 + Binary 조합으로 소스 작성은 다음과 같이 됩니다.

대문자 B 로 시작하여, 각 cell 값에 따라 도식처럼 보여줍니다.


이 블로그의 마스코트인 초코볼을 본따 봤습니다. (도트의 한계로 거의 뭐...)



Hexadecimal 로 표현할 때에는, 5자리 2진수를 Hex 코드로 만들어 줍니다. 예를 들면 아래처럼요...


B10111 = 0x17


내 머리로 계산하지 않더라도 Hexadecimal 인 "0x..." 로 표현할 수 있습니다.

코드적으로 보면, 아무래도 Hex 를 사용하는 것이 코드상 더 간결하게 됩니다.



Arduino 연결을 I2C 로 바꾸어 주면,

include 구문과 LiquidCrystal_I2C 를 I2C 접근 주소와 함께 선언할 수 있도록 소스가 추가됩니다.



소스까지 생성해 주니, 이해하기 쉽습니다.

위의 페이지를 통하여, custom character 는 어떻게 해서 생성되는 지를 감각적으로 배워볼 수 있네요.




3. 끝판 왕


한땀 한땀이 아니라, 8개 생성 가능한 메모리를 한번에 만들 수 있는 소개 자료 입니다.


* Alphanumeric LCD HD44780 - big font, big digits generator (excel sheet)

https://www.avrfreaks.net/forum/alphanumeric-lcd-hd44780-big-font-big-digits-generator-excel-sheet



EXCEL 을 이용하여, 마우스 클릭만으로 폰트를 제작할 수 있게 되어 있습니다.


* dblachut/LCD-font-generator

https://github.com/dblachut/LCD-font-generator

LCD-font-generator.xlsm


Custom Character 는 8개까지 가능하니,

all 흑백, all 흰색을 제외하면 7개를 만들고, 추가적으로 하나 더 만들 수 있는 여유가 있습니다.




4. 메모리 들여다 보기


아래 장표는 HD44780 에 기억되어 있는 코드들 입니다.

왼쪽이 아시아 버전 (일본어 가다가나가 미리 들어가 있슴) 과, 오른쪽이 유럽 버전 (뭔가 더 다채로움) 입니다.



그럼, 실제로 커스텀 글짜를 입력해 보고, 메모리에 어떤 문자가 기억되어 있는지 알아 볼 수 있는 소스가 있습니다.

해당 소스를 사용하려면 아래처럼, 관련 Library 를 인스톨 하면 됩니다.


Tools > Manage Libraries... > LiquidCrystal I2C by Frank de Brabander



위의 library 를 인스톨 하면, 예제코드를 받을 수 있습니다.


File > Examples > LiquidCrystal I2C > CustomChars



소스는 다음과 같습니다.


//YWROBOT
//Compatible with the Arduino IDE 1.0
//Library version:1.1
#include "Wire.h"
#include "LiquidCrystal_I2C.h"

#if defined(ARDUINO) && ARDUINO >= 100
#define printByte(args)  write(args);
#else
#define printByte(args)  print(args,BYTE);
#endif

uint8_t bell[8]  = {0x4,0xe,0xe,0xe,0x1f,0x0,0x4};
uint8_t note[8]  = {0x2,0x3,0x2,0xe,0x1e,0xc,0x0};
uint8_t clock[8] = {0x0,0xe,0x15,0x17,0x11,0xe,0x0};
uint8_t heart[8] = {0x0,0xa,0x1f,0x1f,0xe,0x4,0x0};
uint8_t duck[8]  = {0x0,0xc,0x1d,0xf,0xf,0x6,0x0};
uint8_t check[8] = {0x0,0x1,0x3,0x16,0x1c,0x8,0x0};
uint8_t cross[8] = {0x0,0x1b,0xe,0x4,0xe,0x1b,0x0};
uint8_t retarrow[8] = {	0x1,0x1,0x5,0x9,0x1f,0x8,0x4};
  
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x27 for a 16 chars and 2 line display

void setup() {
	lcd.init(); // initialize the lcd
	lcd.backlight();
	
	lcd.createChar(0, bell);
	lcd.createChar(1, note);
	lcd.createChar(2, clock);
	lcd.createChar(3, heart);
	lcd.createChar(4, duck);
	lcd.createChar(5, check);
	lcd.createChar(6, cross);
	lcd.createChar(7, retarrow);
	lcd.home();
	
	lcd.print("Hello world...");
	lcd.setCursor(0, 1);
	lcd.print(" i ");
	lcd.printByte(3);
	lcd.print(" arduinos!");
	delay(5000);
	displayKeyCodes();
}

// display all keycodes
void displayKeyCodes(void) {
	uint8_t i = 0;
	
	while (1) {
		lcd.clear();
		lcd.print("Codes 0x"); lcd.print(i, HEX);
		lcd.print("-0x"); lcd.print(i+16, HEX);
		lcd.setCursor(0, 1);
		for (int j=0; j<16; j++) {
			lcd.printByte(i+j);
		}
		
		i+=16;
		
		delay(4000);
	}
}

void loop() {

}


위의 소스를 arduino 에 올리고, LCD 20x4 와 I2C 연결해서 얻은 결과 입니다.



Custom Character 가 잘 올라가서 표현되었습니다.

0x00 부터 0xff 까지, 내부 글짜를 모두 훑는 결과는 다음과 같습니다.



확실히 아시아 버전임을 알 수 있네요.

버전이 다르지만, 구동은 같은 HD44780 칩 이므로, 해킹을 통하여 비어있는 address 에도 쓰기가 가능할 것 같은데,

복잡할 듯 하여 그만 두기로 합니다.




5. 큰 폰트


여기까지 해 보면, 큰 폰트 사용하여 시계 등을 표현하는 방법을 대강 생각해 낼 수 있습니다.

이 글의 원래 목적이었던, 아래 그림처럼 표현해 보고자 함이었으니, 이제 커스텀 폰트를 만들어 봅니다.



위의 숫자 들을 잘 살펴 보면, 몇 가지 모양을 조합하여 큰 폰트를 만들어 낸 것을 알 수 있습니다.



유니크한 영역을 살펴 보면, 아무것도 적혀있지 않은 모양까지 포함하면, 모두 8개가 됩니다.

이렇게 딱 맞게 만들다니...


열씸히 만들어 보려고 여러가지 검색하던 중, 좋은 소스를 발견합니다.


* 4-Line LCD Big Numbers

http://woodsgood.ca/projects/2015/02/27/4-line-lcd-big-numbers/



Software RTC 를 이용하여, 시간 데이터를 가져오고, custom / big font 로 시계를 표현해 주는 소스 입니다.


//************************************************************
//             BIG FONT (4-line) LCD CHARACTERS 
//                Adrian Jones, February 2015
//************************************************************

// Build 1
//   r1 150214 - initial build with glyphs and big font character table in program memory
//   r2 150227 - added RTC support
//************************************************************
#define build 1
#define revision 2
//************************************************************

#include "avr/pgmspace.h" // for memory storage in program space

#include "Wire.h" 
#include "LiquidCrystal_I2C.h" // library for I@C interface

LiquidCrystal_I2C lcd(0x27, 20, 4);

const char custom[][8] PROGMEM = {
	{0x00, 0x00, 0x00, 0x00, 0x01, 0x07, 0x0f, 0x1f}, // char 1: top left triangle
	{0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x1f}, // char 2: upper block
	{0x00, 0x00, 0x00, 0x00, 0x10, 0x1c, 0x1e, 0x1f}, // char 3: top right triangle
	{0x1f, 0x0f, 0x07, 0x01, 0x00, 0x00, 0x00, 0x00}, // char 4: bottom left triangle
	{0x1f, 0x1e, 0x1c, 0x10, 0x00, 0x00, 0x00, 0x00}, // char 5: bottom right triangle
	{0x1f, 0x1f, 0x1f, 0x1f, 0x00, 0x00, 0x00, 0x00}, // char 6: bottom block
	{0x1f, 0x1f, 0x1e, 0x1c, 0x18, 0x18, 0x10, 0x10}  // char 7: full top right triangle
	                                                  // room for another one!
};

const char bn[][30] PROGMEM = { // organized by row
//         0               1               2               3               4              5               6                7               8               9
    {0x01,0x02,0x03, 0x01,0x02,0xFE, 0x01,0x02,0x03, 0x01,0x02,0x03, 0x02,0xFE,0x02, 0x02,0x02,0x02, 0x01,0x02,0x03, 0x02,0x02,0x02, 0x01,0x02,0x03, 0x01,0x02,0x03},
    {0xff,0xfe,0xff, 0xFE,0xFF,0xFE, 0x01,0x02,0xFF, 0xFE,0x02,0xFF, 0xFF,0x02,0xFF, 0xFF,0x02,0x02, 0xFF,0x02,0x03, 0xFE,0x01,0x07, 0xFF,0x02,0xFF, 0xFF,0xFE,0xFF},
    {0xff,0xfe,0xff, 0xFE,0xFF,0xFE, 0xFF,0xFE,0xFE, 0xFE,0xFE,0xFF, 0xFE,0xFE,0xFF, 0xFE,0xFE,0xFF, 0xFF,0xFE,0xFF, 0xFE,0xFF,0xFE, 0xFF,0xFE,0xFF, 0x04,0x06,0xFF},
    {0x04,0x06,0x05, 0xFE,0x06,0xFE, 0x06,0x06,0x06, 0x04,0x06,0x05, 0xFE,0xFE,0x06, 0x04,0x06,0x05, 0x04,0x06,0x05, 0xFE,0x06,0xFE, 0x04,0x06,0x05, 0xFE,0xFE,0x06}
};

byte col, row, nb=0, bc=0; // general
byte bb[8]; // byte buffer for reading from PROGMEM

#include "RTClib.h"
RTC_Millis RTC;
byte hr, mn, se, osec;

//*********************** INITIAL SETUP ***********************
void setup() {
	randomSeed(analogRead(0));
	RTC.begin(DateTime(__DATE__, __TIME__));
	
	lcd.init(); // initialize the LCD
	lcd.backlight();
	lcd.begin(20, 4);
	
	for (nb=0; nb<7; nb++ ) { // create 8 custom characters
		for (bc=0; bc<8; bc++) bb[bc]= pgm_read_byte( &custom[nb][bc] );
		lcd.createChar( nb+1, bb );
	}
	
	lcd.clear();
	lcd.setCursor(4, 0);
	lcd.print(F("4-Line LARGE"));
	lcd.setCursor(4, 1);
	lcd.print(F("TIME DISPLAY"));
	lcd.setCursor(5, 3);
	lcd.print(F("V"));
	lcd.print(build);
	lcd.print(F("."));
	lcd.print(revision);
	lcd.print(F(" "));
	lcd.print(freeRam());
	lcd.print(F("B"));
	printNum(random(0,10),0);
	printNum(random(0,10),17);
	delay(5000);
	lcd.clear();
}

//************************* MAIN LOOP ************************
void loop() {
	DateTime now = RTC.now();
	hr = now.hour();
	mn = now.minute();
	se = now.second();
	
	if(se != osec) {
		printNum(hr/10,0);
		printNum(hr%10,3);
		printColon(6);
		printNum(mn/10,7);
		printNum(mn%10,10);
		printColon(13);
		printNum(se/10,14);
		printNum(se%10,17);
		osec = se;
	}
	delay(50); // not strictly necessary
}

...


소스가 좀 길어서, SyntaxHighLighter 가 커버하지 못합니다. 따로 소스파일을 올립니다.


4line_LCD_clock.txt


참고로, 사이트에 올라와 있는 소스 그대로 사용할 수가 없습니다.

제작된지 시간도 좀 흘렀고, 사용한 library 가 조금 다른 것이 원인일 듯 하네요.

그래서 소스에서 몇가지 살짝 수정하였습니다.


	lcd.init(); // initialize the LCD
	lcd.backlight();
	lcd.begin(20, 4);


debug 시, 특히 가장 시간을 많이 잡아 먹은 부분은, 위의 LCD 초기화 부분이었습니다.

원 소스에는 위의 부분이 없거나, 실행 위치가 달라 그대로 사용하면 이상한 폰트들을 마구 뿌립니다.

특히, "lcd.init()" 는 custom character 를 메모리에 입히는 전단계에서 실행되어야 합니다.


추가로, Software RTC 라이브러리가 필요합니다.


Tools > Manage Libraries... > RTClib by Adafruit




모든 준비가 완료되면 arduino 에 업로드 합니다.



역시 삽질 끝에 맛보는 행복. 동영상도 올려봅니다.



참고로, 다른 custom character 들은 숫자들 끼리 공유가 되지만, 7 숫자의 중간 꺾이는 부분에 할당된 character 는 7에서만 사용됩니다.

위의 동영상에서 7 나오는 부분을 잘 보시면 됩니다.



7에서만 사용되는 문자 형상은 위와 같습니다. 공유되기 애매한 모양이죠?

메모리 한개가 여유 있으니, 소스 원작자가 여유를 부린 듯 합니다 :-)



사무실 책상 위에, laptop 옆에 위치 시켰더니, 가독성도 좋고 시간 보는 재미가 있습니다.

사진에는 잘 표현되지 못했지만, 검은색 글씨라 눈도 편안합니다.


모두 Happy Arduino~!


And

Hardware | LCD2004 를 arduino 로 컨트롤 해보기 - 1

|

1. 시작


흠흠흠~ 하면서 인터넷을 보던 중, arduino 로 컨트롤 하는 Liquid Crystal Display 를 보게 됩니다.

이게 흔히 말하는 LCD 이죠.


OLED 와 비교하여 부피도 크고, 명암 조절을 수동으로 해줘야 하는 등, 불편한 device 라고 생각하고 있던 중,

LCD 의 푸른색 색감을 보고 반해버렸습니다.


Display 부품을 늘이고 싶지 않았지만, 이제 구입할 때가 된것 같아 구입합니다.


* LCD2004+I2C 2004 20x4 2004A blue screen HD44780 Character LCD /w IIC/I2C Serial Interface Adapter Module For Arduino

https://www.aliexpress.com/item/32831845529.html



결코 싼 가격은 아니지만, 이왕 구입하는 김에 보편적으로 많이 사용하는 녹색과 색감에 반한 푸른색, 두 개를 삽니다.





2. 도착


한 2주만에 재품을 받았습니다.

무료 배송이 점점 없어지고 배송비 책정이 되면서 배송 기간이 점점 짧아지고 있는 듯 합니다.



푸른색, 녹색 두개가 와서 PCB 를 비교해 보니, 서로 동일한 듯 하나 살짝 다른 모습 입니다.



I2C 컨트롤러의 칩 한쪽은 마킹이 너무 얇아 fake 제품처럼 보입니다.

조금이라도 진품처럼 보이는 쪽은 파란색 버전 입니다.



납땜도 녹색보다는 파란색이 잘 되어 있습니다.



PCB 마킹도, 파란색은 동판에 미리 새겨져 있고, 녹색은 프린팅 되어 있네요.



뭐, 생산하다가 점점 원가절감 하면서 변화된 것 일 수도 있습니다.

보통 녹색을 많이 사용하니, 녹색이 원가절감이 더 된 것 일수도 있구요.





3. Pin


Pin 수는 16개로, 아래와 같은 사양을 가집니다.


-------------------------------------------------------------------
|  pin  |                        function                         |
-------------------------------------------------------------------
|  VSS  | connected to ground                                     |
-------------------------------------------------------------------
|  VDD  | connected to a +5V power supply                         |
-------------------------------------------------------------------
|   V0  | to adjust the contrast                                  |
-------------------------------------------------------------------
|   RS  | A register select pin that controls where in the LCD's  |
|       | memory you are writing data to. You can select either   |
|       | the data register, which holds what goes on the screen, |
|       | or an instruction register, which is where the LCD's    |
|       | controller looks for instructions on what to do next.   |
-------------------------------------------------------------------
|  R/W  | A Read/Write pin to select between reading and writing  |
|       | mode                                                    |
-------------------------------------------------------------------
|   E   | An enabling pin that reads the information when HIGH    |
|       | level(1) is received. The instructions are run when the |
|       | signal changes from HIGH level to LOW level.            |
-------------------------------------------------------------------
| D0-D7 | to read and write data                                  |
-------------------------------------------------------------------
|   A   | Pins that control the LCD backlight. Connect A to 3.3V. |
-------------------------------------------------------------------
|   K   | Pins that control the LCD backlight. Connect K to GND.  |
-------------------------------------------------------------------


대충 훑어 보면, back light 전원, 본체 전원, 명암 조절, data 통신과 컨트롤 라인 등이 있습니다.

제가 구매한 제품은 I2C 모듈인 "PCF8574" 컨트롤러가 달린 제품입니다.

그러니, 일일이 모두 연결할 필요 없이 I2C 를 통해, 단 4가닥 선으로 컨트롤 할 수 있습니다.


이 chip 의 생산은 Philips, TI, NXP 등에서 생산되고 있네요. PDF 사양서를 올려 놓습니다.


LCD2004

TC2004A-01.pdf

Systronix_20x4_lcd_brief_data.pdf

RK-10290_410.pdf

50586.pdf


HD44780

HD44780.pdf

LCD Interfacing using HD44780 Hitachi chipset compatible LCD.pdf


PCF8574

PCF8574_PCF8574A.pdf

PCF8574T.pdf

pcf8574.pdf





4. I2C


Arduino 와 연결은 I2C 이므로, 4가닥으로 처리됩니다.



Liquid Crystal I2C 라이브러리가 필요합니다.

일반 Liquid Crystal I2C 라이브러리를 설치해도 되나, 궂이... 궂이 PCF8574 용 라이브러리를 찾아서 설치해 봅니다.

(범용 Liquid Crystal I2C 라이브러리가 아님)



위의 라이브러리를 설치하면 아래처럼 sample code 를 사용할 수 있습니다.


File > Examples > LiquidCrystal_PCF8574 > LiquidCrystal_PCF8574_test



I2C 활용시에는 항상 address 를 확인해 봐야 합니다.

Arduino 와 I2C 로 연결 후, i2cdetect 소스를 돌려 봅니다.



0x27 로 잡혀 있네요.

참고로 다른 I2C 센서들과 연동 시에 address 충돌이 일어나면, 아래 사진의 A0, A1, A2 쇼트 조합으로 주소를 바꿀 수 있습니다.






5. I2C 소스


친절하게도 example 소스가 충분히 잘 만들어져 있는지라, 그냥 돌려 봅니다.


#include "LiquidCrystal_PCF8574.h"
#include "Wire.h"

LiquidCrystal_PCF8574 lcd(0x27); // set the LCD address to 0x27 for a 16 chars and 2 line display
int show = -1;

void setup() {
	int error;
	
	Serial.begin(115200);
	Serial.println("LCD...");
	
	// wait on Serial to be available on Leonardo
	while (!Serial)
		;
	Serial.println("Dose: check for LCD");
	
	// See http://playground.arduino.cc/Main/I2cScanner how to test for a I2C device.
	Wire.begin();
	Wire.beginTransmission(0x27);
	error = Wire.endTransmission();
	Serial.print("Error: ");
	Serial.print(error);
	
	if (error == 0) {
		Serial.println(": LCD found.");
		show = 0;
		lcd.begin(20, 4); // initialize the lcd
	} else {
		Serial.println(": LCD not found.");
	} // if
} // setup()

void loop() {
	if (show == 0) {
		lcd.setBacklight(255);
		lcd.home();
		lcd.clear();
		lcd.print("Hello LCD");
		delay(1000);
		
		lcd.setBacklight(0);
		delay(400);
		lcd.setBacklight(255);
	} else if (show == 1) {
		lcd.clear();
		lcd.print("Cursor On");
		lcd.cursor();
	} else if (show == 2) {
		lcd.clear();
		lcd.print("Cursor Blink");
		lcd.blink();
	} else if (show == 3) {
		lcd.clear();
		lcd.print("Cursor OFF");
		lcd.noBlink();
		lcd.noCursor();
	} else if (show == 4) {
		lcd.clear();
		lcd.print("Display Off");
		lcd.noDisplay();
	} else if (show == 5) {
		lcd.clear();
		lcd.print("Display On");
		lcd.display();
	} else if (show == 7) {
		lcd.clear();
		lcd.setCursor(0, 0);
		lcd.print("*** first line.");
		lcd.setCursor(0, 1);
		lcd.print("*** second line.");
		lcd.setCursor(0, 2);
		lcd.print("*** third line.");
		lcd.setCursor(0, 3);
		lcd.print("*** forth line.");
	} else if (show == 8) {
		lcd.scrollDisplayLeft();
	} else if (show == 9) {
		lcd.scrollDisplayLeft();
	} else if (show == 10) {
		lcd.scrollDisplayLeft();
	} else if (show == 11) {
		lcd.scrollDisplayRight();
	} else if (show == 12) {
		lcd.clear();
		lcd.print("write-");
	} else if (show > 12) {
		lcd.print(show - 13);
	} // if
	
	delay(1400);
	show = (show + 1) % 16;
} // loop()


Serial Monitor 에서 확인해 보니, 잘 인식 되었네요.



너무 쉽게 되어서 살짝 김이 빠지는 정상적인 결과.



동영상도 올려 봅니다. (동영상은 16x2 버전으로 돌린 결과. 수정된 위의 소스로 20x4 로 변경된 소스를 사용하면 4줄 다 사용.)






6. Direct 연결


여기서 끝내면 너무 재미 없는지라, 한땀한땀 직접 연결해 봅니다.

워낙 오래된 부품이라, 아래 arduino 정식 사이트에서 자세히 소개되어 있습니다.


* TUTORIALS > Examples from Libraries > LiquidCrystal > HelloWorld

https://www.arduino.cc/en/Tutorial/HelloWorld?from=Tutorial.LiquidCrystal


각 Pin 의 정보는 다음과 같습니다.



실제 arduino 와 연결은 다음과 같습니다.


--------------------------------
| LCD2004 |    Arduino Nano    |
--------------------------------
|   VSS   |         GND        |
|   VDD   |         5V         |
|   V0    | S of potentiometer |
|   RS    |         D12        |
|   R/W   |         GND        |
|   E     |         D11        |
|  D0-D3  |    no connected    |
|   D4    |         D5         |
|   D5    |         D4         |
|   D6    |         D3         |
|   D7    |         D2         |
|   A     |         3.3V       |
|   K     |         GND        |
--------------------------------


Diagram 으로도 그려 봤습니다. (Digital pin 은 실제와 살짝 틀림)






7. Potentiometer


여기서 필요한 것이 potentiometer 입니다. 가변 저항이죠.

다이얼을 돌려서 저항값을 변화시키는 부품이죠. 구입을 미뤄 오다가, 이번 기회에 사용하고자 구입 했습니다.


* 5 PCS/Lot Potentiometer Resistor 1K 10K 20K 50K 100K 500K Ohm 3 Pin Linear Taper Rotary Potentiometer for Arduino with Cap

https://www.aliexpress.com/item/32948875673.html



구입한 버전은 10K Ohm.



글의 문맥상 뜬금 없지만, 도착샷 입니다. 빠질 수 없죠.



요런 모양 입니다.




8. Direct 연결 구동


직접 연결하는 방법은 Arduino IDE 에서 기본 제공합니다.



소스는 다음과 같구요.

기본 16x2 버전으로 되어 있으니, 20x4 버전으로 살짝 수정해 줍니다.


/*
  LiquidCrystal Library - Hello World
 
 Demonstrates the use a 16x2 LCD display.  The LiquidCrystal
 library works with all LCD displays that are compatible with the
 Hitachi HD44780 driver. There are many of them out there, and you
 can usually tell them by the 16-pin interface.
 
 This sketch prints "Hello World!" to the LCD
 and shows the time.
 
  The circuit:
 * LCD RS pin to digital pin 12
 * LCD Enable pin to digital pin 11
 * LCD D4 pin to digital pin 5
 * LCD D5 pin to digital pin 4
 * LCD D6 pin to digital pin 3
 * LCD D7 pin to digital pin 2
 * LCD R/W pin to ground
 * LCD VSS pin to ground
 * LCD VCC pin to 5V
 * 10K resistor:
 * ends to +5V and ground
 * wiper to LCD VO pin (pin 3)
 
 Library originally added 18 Apr 2008
 by David A. Mellis
 library modified 5 Jul 2009
 by Limor Fried (http://www.ladyada.net)
 example added 9 Jul 2009
 by Tom Igoe
 modified 22 Nov 2010
 by Tom Igoe
 
 This example code is in the public domain.
 
 http://www.arduino.cc/en/Tutorial/LiquidCrystal
 */
 
// include the library code:
#include "LiquidCrystal.h"
 
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
 
void setup() {
  // set up the LCD's number of columns and rows:
  lcd.begin(20, 4);
  // Print a message to the LCD.
  lcd.setCursor(0, 0);
  lcd.print(" Chocoball's Tech");
  lcd.setCursor(0, 2);
  lcd.print(" chocoball.tistory");
}
 
void loop() {
  // set the cursor to column 0, line 1
  // (note: line 1 is the second row, since counting begins with 0):
  lcd.setCursor(0, 3);
  // print the number of seconds since reset:
  lcd.print(millis() / 1000);
}


전부 연결하면 아래와 같습니다.



동영상도 올려 봅니다.



hello, world! 를 저의 블로그명으로 바꿔 봤습니다.



단순한 표시 방법과 오랜 기간 수정된 라이브러리 덕으로, 정말 스트레스 없이 구동 시켰습니다.




9. I2C 와 Direct 연결시 명령어 차이


I2C 를 통한 함수와, 직접 연결했을 시에 사용할 수 있는 명령어 구성이 살짝 다릅니다.

고맙게도 아래 사이트에서 잘 정리된 테이블이 있어서 여기에 올려 봅니다.


* LCD Display Tutorial for Arduino and ESP8266

https://diyi0t.com/lcd-display-tutorial-for-arduino-and-esp8266/






10. 커스텀 폰트


명령어 차이를 자세하게 올려준 사이트에서 폰트 커스텀에 대해서도 내용이 있어서 따라해 봤습니다.

이 때, 사용하는 LiquidCrystal_I2C 라이브러리는 범용을 사용하는 지라, 아래 라이브러리를 설치합니다.



소스는 아래와 같습니다. 폰트라기 보단 캐릭터 입니다.


#include "Wire.h"
#include "LiquidCrystal_I2C.h"

// Set the LCD address to 0x27 in PCF8574 by NXP and Set to 0x3F in PCF8574A by Ti
LiquidCrystal_I2C lcd(0x27, 20, 4);

byte customChar1[] = {
  B01110,
  B01110,
  B00100,
  B11111,
  B00100,
  B01110,
  B01010,
  B01010
};

byte customChar2[] = {
  B01110,
  B01110,
  B10101,
  B01110,
  B00100,
  B00100,
  B01010,
  B10001
};

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

void loop() {
  lcd.createChar(0, customChar1);
  lcd.home();
  lcd.write(0);
  delay(1000);
  lcd.createChar(0, customChar2);
  lcd.home();
  lcd.write(0);
  delay(1000);
}


Bitmap 을 이용해서 만들었고, 화면 refresh 를 통해서 움직이는 것 처럼 구성했네요.



동영상도 올려 봅니다.



참고로, 이 Liquid Crystal 은 Hitachi HD44780 를 사용하거나 호환품들이라 아래 폰트를 기본 제공합니다.


HD44780.pdf






11. 아...


인터넷에서 보지 말아야 할 것을 봐버렸습니다.



이렇게 이쁘게도 커스터마이징 할 수 있는거군요.

다음은, 커스텀 폰트를 가지고 놀아보겠습니다.


And
prev | 1 | next