這款 SSD1306 0.96吋 OLED 屏模塊是使用積體電路匯流排(I²C / I2C / IIC:Inter-Integrated Circuit)介面,接口祇有 4線,包括電源供應(VCC 和 GND)和 2線 I/O,2線 I/O 是 Pin 3 的SCK(Serial Clock Input)和 Pin 4 的 SDA(Serial Data Input),會連接到 ESP-12E 板上 Pin 23 的 GPIO14(ESP-12E 的 D5)和 Pin 26 的 GPIO2(ESP-12E的 D4) I/O 接口。
ESP8266 SSD1306 0.96吋 I2C OLED 屏模塊 I/O 電路 |
ESP8266 ESP-12E SSD1306 I2C OLED 屏連接:
LCD
|
Signal
|
Description
|
ESP8266
|
Board
Signal
|
I/O
Signal
|
1
|
VCC
|
VCC 2.7 ~ 3.3V
|
25
|
Vcc
|
Vcc
|
2
|
GND
|
Ground
|
24
|
GND
|
GND
|
3
|
SCK
|
Serial Clock Input
|
23
|
D5
|
GPIO14
|
4
|
SDA
|
Serial Data Input
|
26
|
D4
|
GPIO2
|
Solomon Systech (晶門)SSD1306 驅動晶片與 Microchip PIC24FJ64GA008 是採用積體電路匯流排(I²C / I2C / IIC:Inter-Integrated Circuit)連接,而 SSD1306 的 I/O 控制已經連接到 4腳的連接器,電源是連接到 ESP-12E 的 3.3V供電,OLED 屏模塊 Vcc 連接到 ESP-12E Pin 25 的 Vcc 和 Pin 24 的 GND 電源,SCK(Serial Clock Input)連接到 ESP-12E Pin 23 的 D5(GPIO14),SDA(Serial Data Input)連接到 ESP-12E Pin 26 的 D4(GPIO2)。2腳的 I2C 連接比 3腳的 SPI 更加簡單。
ESP8266 ESP-12E SSD1306 I2C OLED 屏接腳 I/O 程式定義:
//SDA on GPIO2
#define I2C_SDA_MUX
PERIPHS_IO_MUX_GPIO2_U
#define I2C_SDA_FUNC
FUNC_GPIO2
#define I2C_SDA_PIN
2
//SCK on GPIO14
#define I2C_SCK_MUX
PERIPHS_IO_MUX_MTMS_U
#define I2C_SCK_FUNC
FUNC_GPIO14
#define I2C_SCK_PIN
14
#define OLED_ADDRESS 0x78
// D/C->GND
|
ESP8266 ESP-12E SSD1306 I2C OLED 屏初始化程式:
bool ICACHE_FLASH_ATTR OLED_Init(void)
{
os_delay_us(60000);
os_delay_us(40000);
OLED_writeCmd(0xAE); // turn off oled panel
OLED_writeCmd(0x00); // set low column address
OLED_writeCmd(0x10); // set high column address
OLED_writeCmd(0x40); // set start line address
OLED_writeCmd(0x81); // set contrast control register
OLED_writeCmd(0xCF); // Set SEG Output Current Brightness
OLED_writeCmd(0xA1); // Set SEG/Col Mapping 0xA0, 0xA1
OLED_writeCmd(0xC8); // Set COM/Row Scan Direction 0xC0, 0xC8
OLED_writeCmd(0xa6); // set normal display
OLED_writeCmd(0xa8); // set multiplex ratio(1 to 64)
OLED_writeCmd(0x3F);
// 1/64 duty
OLED_writeCmd(0xD3); // set display offset
OLED_writeCmd(0x00);
// not offset
OLED_writeCmd(0xD5); // set display clock divide ratio/oscillator
frequency
OLED_writeCmd(0x80); // set divide ratio
OLED_writeCmd(0xD9); // set pre-charge period
OLED_writeCmd(0xF1);
OLED_writeCmd(0xDA); // set com pins hardware configuration
OLED_writeCmd(0x12);
OLED_writeCmd(0xDB); // set vcomh
OLED_writeCmd(0x40);
OLED_writeCmd(0x8D); // set Charge Pump enable/disable
OLED_writeCmd(0x14); // set(0x10) disable
OLED_writeCmd(0xA4); // Disable Entire Display On (0xA4/0xA5)
OLED_writeCmd(0xA6); // Disable Iverse Display On (0xA6/0xA7)
OLED_writeCmd(0xAF); // turn on oled panel
OLED_Fill(0x00); //OLED CLS
return
oledstat;
} // ResetDevice
|
ESP8266 SSD1306 0.96吋 I2C OLED 屏模塊 I/O 電路試驗 |
ESP8266 SSD1306 0.96吋 I2C OLED 屏模塊 I/O 電路顯示試驗 |
氣溫:17.5度 @ 20:20
相對濕度:百分之 62%
天氣:大致多雲