ESP8266 (ESP-WROOM-02)으로 I2C LCD 8 자리 2 행 제어
개요
ESP8266 (ESP-WROOM-02)으로 I2C로 연결할 수있는 LCD 8 자리 2 행 제어
소개
부품 세트에 포함되어 있던 LCD를 제어하려고 하는 기획입니다만, 16자리 2행 형번:1602라고 하는 것 밖에 모르는 orz.
아키즈키에서도 취급하지 않을 것 같기 때문에, 이 LCD는 포기하고, 보다 저렴하고 메이저인 LCD를 선택했습니다. 이것이 AQM0802라는 LCD입니다.
부품 조달
위가 AQM0802 (8 자리 2 행), 아래가 1602 (16 자리 2 행)

AQM0802는 저렴하게 구입할 수 있습니다. I2C 연결 소형 캐릭터 LCD 모듈 (8x2 행) 320엔
브레보용으로 피치 변환이 끝난 모듈은 이쪽. 피치 변환 모듈 (완제품) 700엔 이번은 이것을 사용했습니다.
데이터시트
아래 데이터시트 발췌

카타카나도 표시 가능 합니다만, 이번은 감히 오렌지색 음영 (ASCII 호환) 부분에 포커스합니다.

회로
~/Library/Arduino15/packages/esp8266/hardware/esp8266/2.0.0/variants/generic/pins_arduino.h
static const uint8_t SDA = 4;
static const uint8_t SCL = 5;
회로도

이글
https://github.com/exabugs/eagleLCD
스케치
#include <Wire.h>
#define ADDR 0x3e
uint8_t CONTROLL[] = {
0x00, // Command
0x40, // Data
};
const int C_COMM = 0;
const int C_DATA = 1;
uint8_t settings[] = {
0b00111001, // 0x39 // [Function set] DL(4):1(8-bit) N(3):1(2-line) DH(2):0(5x8 dot) IS(0):1(extension)
// Internal OSC frequency
(0b0001 << 4) + 0b0100, // BS(3):0(1/5blas) F(210):(internal Freq:100)
// Contrast set
(0b0111 << 4) + 0b0100, // Contrast(3210):4
// Power/ICON/Contrast control
(0b0101 << 4) + 0b0110, // Ion(3):0(ICON:off) Bon(2):1(booster:on) C5C4(10):10(contrast set)
// Follower control
(0b0110 << 4) + 0b1100, // Fon(3):1(on) Rab(210):100
// Display ON/OFF control
(0b00001 << 3) + 0b111, // D(2):1(Display:ON) C(1):1(Cursor:ON) B(0):1(Cursor Blink:ON)
};
const int LINE = 2;
String buff[LINE];
void setup() {
Serial.begin(115200);
Serial.println("");
//Wire.begin(4, 5); // (SDA,SCL) Default
Wire.begin(); // (SDA,SCL)
// LCD初期化
write(C_COMM, settings, sizeof(settings));
}
void loop() {
if (0 < Serial.available()) {
delay(10);
for (int i = 0; i < LINE - 1; i++) {
buff[i] = buff[i + 1];
}
buff[LINE - 1] = "";
while (0 < Serial.available()) {
char ch = Serial.read();
if (ch == '\n') {
print2line();
Serial.println(buff[LINE - 1]);
break;
} else if (0x20 <= ch && ch <= 0x7f) {
// ASCII文字コード
buff[LINE - 1] = buff[LINE - 1] + ch;
} else {
// Do nothing
}
}
}
}
// 2行表示
void print2line() {
// クリア
uint8_t cmd[] = {0x01};
write(C_COMM, cmd, sizeof(cmd));
delay(1);
// 書き出し
for (int i = 0; i < LINE; i++) {
uint8_t pos = 0x80 | i * 0x40; // 位置
uint8_t cmd[] = {pos};
write(C_COMM, cmd, sizeof(cmd));
write(C_DATA, (uint8_t *)buff[i].c_str(), buff[i].length());
}
}
void write(int type, uint8_t *data, size_t len) {
for (int i=0; i < len; i++) {
Wire.beginTransmission(ADDR);
Wire.write(CONTROLL[type]);
Wire.write(data[i]);
Wire.endTransmission();
delayMicroseconds(27); // 26.3us
}
}
결과

요약
여담
static const uint8_t SS = 15;
static const uint8_t MOSI = 13;
static const uint8_t MISO = 12;
static const uint8_t SCK = 14;
Reference
이 문제에 관하여(ESP8266 (ESP-WROOM-02)으로 I2C LCD 8 자리 2 행 제어), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://qiita.com/exabugs/items/9d1b66aa1d22805afbc8텍스트를 자유롭게 공유하거나 복사할 수 있습니다.하지만 이 문서의 URL은 참조 URL로 남겨 두십시오.
우수한 개발자 콘텐츠 발견에 전념
(Collection and Share based on the CC Protocol.)