From 9ed4aa23b2f805519ba6db35fab5a2d91cca61c9 Mon Sep 17 00:00:00 2001 From: Tonu Samuel Date: Sat, 19 Jul 2025 20:57:45 +0300 Subject: [PATCH 1/2] Fix the garbage appearing on last line of OLED --- src/main/drivers/display_ug2864hsweg01.c | 27 ++++++++++++++++-------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/src/main/drivers/display_ug2864hsweg01.c b/src/main/drivers/display_ug2864hsweg01.c index 118acff5730..453f8483bd3 100644 --- a/src/main/drivers/display_ug2864hsweg01.c +++ b/src/main/drivers/display_ug2864hsweg01.c @@ -200,16 +200,25 @@ void i2c_OLED_clear_display(void) i2c_OLED_send_cmd(0xae); // Display OFF i2c_OLED_send_cmd(0x20); // Set Memory Addressing Mode i2c_OLED_send_cmd(0x00); // Set Memory Addressing Mode to Horizontal addressing mode - i2c_OLED_send_cmd(0xb0); // set page address to 0 - i2c_OLED_send_cmd(0x40); // Display start line register to 0 - i2c_OLED_send_cmd(0); // Set low col address to 0 - i2c_OLED_send_cmd(0x10); // Set high col address to 0 - for (uint16_t i = 0; i < 1024; i++) { // fill the display's RAM with graphic... 128*64 pixel picture - i2c_OLED_send_byte(0x00); // clear + + // Clear all 8 pages (0-7) + for (uint8_t page = 0; page < 8; page++) { + i2c_OLED_send_cmd(0xb0 + page); // set page address + i2c_OLED_send_cmd(0x00); // set low col address to 0 + i2c_OLED_send_cmd(0x10); // set high col address to 0 + + for (uint8_t col = 0; col < 128; col++) { + i2c_OLED_send_byte(0x00); // clear + } } - i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL, following byte is the contrast Value... always a 2 byte instruction - i2c_OLED_send_cmd(200); // Here you can set the brightness 1 = dull, 255 is very bright - i2c_OLED_send_cmd(0xaf); // display on + + i2c_OLED_send_cmd(0xb0); // Reset to page 0 + i2c_OLED_send_cmd(0x00); // Reset low col address to 0 + i2c_OLED_send_cmd(0x10); // Reset high col address to 0 + + i2c_OLED_send_cmd(0x81); // Setup CONTRAST CONTROL + i2c_OLED_send_cmd(200); // Contrast value + i2c_OLED_send_cmd(0xaf); // Display ON } void i2c_OLED_clear_display_quick(void) From 275c3ba6ec7a7c03683ad0df7d04ab28c9889746 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?T=C3=B5nu=20Samuel?= Date: Sun, 20 Jul 2025 12:00:14 +0300 Subject: [PATCH 2/2] Fix OLED addressing mode and restore display start line command - Changed from horizontal (0x00) to page addressing mode (0x02) to match the page-by-page clearing approach - Restored the display start line command (0x40) that was missing from the previous commit - This ensures proper OLED initialization and prevents garbage on the last line --- src/main/drivers/display_ug2864hsweg01.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/main/drivers/display_ug2864hsweg01.c b/src/main/drivers/display_ug2864hsweg01.c index 453f8483bd3..68a2a207d42 100644 --- a/src/main/drivers/display_ug2864hsweg01.c +++ b/src/main/drivers/display_ug2864hsweg01.c @@ -199,7 +199,8 @@ void i2c_OLED_clear_display(void) i2c_OLED_send_cmd(0xa6); // Set Normal Display i2c_OLED_send_cmd(0xae); // Display OFF i2c_OLED_send_cmd(0x20); // Set Memory Addressing Mode - i2c_OLED_send_cmd(0x00); // Set Memory Addressing Mode to Horizontal addressing mode + i2c_OLED_send_cmd(0x02); // Set Memory Addressing Mode to Page addressing mode + i2c_OLED_send_cmd(0x40); // Set Display Start Line to 0 // Clear all 8 pages (0-7) for (uint8_t page = 0; page < 8; page++) {