【Portable Environmental Status Detector】OLED Screen Display Driver
[Copy link]
The ESP32-S2-Kaluga-1 kit is equipped with an LCD display, which can be used for human-computer interaction. However, an error message appears during the compilation and download of the routine program, preventing normal use.
To this end, we first completed the display driver of an OLED screen to lay the foundation for subsequent development and testing, and then moved the completed development to the LCD screen for display, so as not to affect the design progress.
The OLED screen used here uses the I2C interface to work, so it occupies fewer pin resources.
To reduce the impact on subsequent development, the pin relationship used by the OLED screen is as follows:
GPIO15---SCL
GPIO9---SDA
The configuration function for the used pins is:
staticvoidconfigure_Oled(void)
{
gpio_reset_pin(SCL_GPIO);
gpio_set_direction(SCL_GPIO, GPIO_MODE_OUTPUT);
gpio_reset_pin(SDA_GPIO);
gpio_set_direction(SDA_GPIO, GPIO_MODE_OUTPUT);
}
The initialization function of the display is:
static void OLED_Init(void)
{
OLED_WR_Byte(0xAE,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x10,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x81,OLED_CMD);
OLED_WR_Byte(0xff,OLED_CMD);
OLED_WR_Byte(0xA1,OLED_CMD);
OLED_WR_Byte(0xC8,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xA8,OLED_CMD);
OLED_WR_Byte(0x3f,OLED_CMD);
OLED_WR_Byte(0xD3,OLED_CMD);
OLED_WR_Byte(0x00,OLED_CMD);
OLED_WR_Byte(0xd5,OLED_CMD);
OLED_WR_Byte(0x80,OLED_CMD);
OLED_WR_Byte(0xD9,OLED_CMD);
OLED_WR_Byte(0xF1,OLED_CMD);
OLED_WR_Byte(0xDA,OLED_CMD);
OLED_WR_Byte(0x12,OLED_CMD);
OLED_WR_Byte(0xDB,OLED_CMD);
OLED_WR_Byte(0x40,OLED_CMD);
OLED_WR_Byte(0x20,OLED_CMD);
OLED_WR_Byte(0x02,OLED_CMD);
OLED_WR_Byte(0x8D,OLED_CMD);
OLED_WR_Byte(0x14,OLED_CMD);
OLED_WR_Byte(0xA4,OLED_CMD);
OLED_WR_Byte(0xA6,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
OLED_WR_Byte(0xAF,OLED_CMD);
OLED_Clear();
OLED_Set_Pos(0,0);
}
The function that implements string display is:
voidOLED_ShowString(uint8_t x,uint8_ty,char *chr,uint8_tChar_Size)
{
unsignedchar j=0;
while (chr[j]!='\0')
{
OLED_ShowChar(x,y,chr[j],Char_Size);
x+=8;
if(x>120){x=0;y+=2;}
j++;
}
}
The main program to achieve the following display effect is:
voidapp_main(void)
{
configure_Oled();
OLED_Init();
OLED_Clear();
OLED_ShowString(0,0,"ESP32-S2-Kaluga",16);
OLED_ShowString(16,2,"OLED Display",16);
OLED_ShowString(16,6,"by:jinglixixi",16);
while (1);
}
Display effect diagram
|