0.91 inch I2C SSD1306 is not working
I have following code tried for all driver options on 0.91 oled ssd1306
#define SSD1306_I2C_PORT hi2c1
#define SSD1306_I2C_ADDR (0x3C << 1)
u8g2_t myDisplay;
// u8g2_Setup_ssd1306_i2c_128x64_noname_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_128x32_univision_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_102x64_ea_oleds102_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_128x32_winstar_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_128x64_alt0_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_128x64_vcomh0_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_48x64_winstar_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_64x32_1f_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_64x32_noname_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_72x40_er_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_96x16_er_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_96x39_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
// u8g2_Setup_ssd1306_i2c_96x40_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
u8g2_Setup_ssd1306_i2c_128x32_winstar_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay);
u8g2_InitDisplay(&myDisplay); // Send init sequence to the display
u8g2_SetPowerSave(&myDisplay, 0); // Wake up display
u8g2_SetFont(&myDisplay, u8g2_font_ncenB14_tr); // Set font before drawing
u8g2_DrawStr(&myDisplay, 40, 15, "Timer");
u8g2_SendBuffer(&myDisplay);
uint8_t u8x8_gpio_and_delay(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
switch(msg)
{
case U8X8_MSG_DELAY_MILLI:
HAL_Delay(arg_int);
break;
}
return 1;
}
uint8_t u8x8_i2c(u8x8_t *u8x8, uint8_t msg, uint8_t arg_int, void *arg_ptr)
{
static uint8_t buffer[32]; /* u8g2/u8x8 will never send more than 32 bytes between START_TRANSFER and END_TRANSFER */
static uint8_t buf_idx;
uint8_t *data;
switch(msg)
{
case U8X8_MSG_BYTE_SEND:
data = (uint8_t *)arg_ptr;
while( arg_int > 0 )
{
buffer[buf_idx++] = *data;
data++;
arg_int--;
}
break;
case U8X8_MSG_BYTE_START_TRANSFER:
buf_idx = 0;
break;
case U8X8_MSG_BYTE_END_TRANSFER:
HAL_I2C_Master_Transmit(&SSD1306_I2C_PORT, SSD1306_I2C_ADDR, buffer, buf_idx, 1000);
break;
default:
return 0;
}
return 1;
}
Note i have tested same code and same hardware for 0.96 Inch I2C Resolution radio:128 x 64 working fine with u8g2_Setup_ssd1306_i2c_128x64_noname_f(&myDisplay, U8G2_R0, u8x8_i2c, u8x8_gpio_and_delay); but i tried all the combinations for 0.91 oled ssd1306 is not working fine.
I found that https://github.com/afiskon/stm32-ssd1306 is working fine on same hardware for 0.91 inch oled. please resolve issue and update u8g2.
Maybe you need to use
#define SSD1306_I2C_ADDR (0x3C)
I tried for both one by one for all the combinations of driver. still not working
#define SSD1306_I2C_ADDR (0x3C)
#define SSD1306_I2C_ADDR (0x3C<<1)
well, then... I don't think that I can help here. Maybe there is a wiring issue or you made a mistake with the Hal function.
Already tested on same hardware with same wiring circuit and same i2c hal initialized and clock initalization, code works fine https://github.com/afiskon/stm32-ssd1306 but not u8g2
Well, I can also claim the same: U8g2 works nicely with Arduino and my none-Arduino STM32 and LPC projects.
U8g2 and STM32: https://github.com/olikraus/u8g2/tree/master/sys/arm/stm32l031x6/u8x8_test https://github.com/olikraus/u8g2/tree/master/sys/arm/stm32l031x4/u8g2_test
You could also check the issues here. Similar questions appears quite often, for example here: https://github.com/olikraus/u8g2/issues/2545