esp32-snippets
esp32-snippets copied to clipboard
U8G2 does not work with SSD1306 I2C
Hello, I'm having an issue with setting up my I2C 128x64 SSD1306 with ESP-IDF. When I first tried, the display didn't turn on at all, so I tested it with Arduino IDE, with the same configuration. I loaded the Hello World sketch and it worked, so my wiring is good and the display is working. After this, I reuploaded the ESP-IDF program, and now the display turns on, but is very glitchy and constantly flickers. After unplugging the board from USB and retrying, the display remained black again. After retrying with Arduino IDE, I got the same result as before. I think the problem is that the display does not get reset / does not get initialized properly. Otherwise, the u8g2 library, the ESP32 HAL and my project compile fine. Here is my code:
u8g2_esp32_hal_t u8g2_esp32_hal = U8G2_ESP32_HAL_DEFAULT;
u8g2_esp32_hal.sda = (gpio_num_t)21;
u8g2_esp32_hal.scl = (gpio_num_t)22;
u8g2_esp32_hal_init(u8g2_esp32_hal);
u8g2_Setup_ssd1306_128x64_noname_f(&u8g2, U8G2_R0, u8g2_esp32_i2c_byte_cb, u8g2_esp32_gpio_and_delay_cb);
u8x8_SetI2CAddress(&u8g2.u8x8, 0x78);
u8g2_InitDisplay(&u8g2);
u8g2_SetPowerSave(&u8g2, 0);
u8g2_ClearBuffer(&u8g2);
u8g2_SetFont(&u8g2, u8g2_font_u8glib_4_tf);
u8g2_DrawStr(&u8g2, 10, 5, "Hello, world!");
u8g2_SendBuffer(&u8g2);
Hello @Lorinet , i have exactly the same issue with the ssd1306 and esp -idf. In Aduino everything works as expected but in the esp-idf unfortunately not. Have you found a workaround for this problem?