Widgets on SSD1306-based OLED


Trying to print simple widgets on SSD1306-based OLED

What MCU/Processor/Board and compiler are you using?

Compiler: GCC
IDE: CubeIDE (Eclipse)

What LVGL version are you using?


What do you want to achieve?

Display widgets to continue learning about interactions with them

What have you tried so far?

Downloaded LVGL ver.8.3 from Github
Setted up project according to Porting guide
Used template from Github to register display and flush buffer
Setted needed variables/buffers/callbacks

Code to reproduce

To mention, problem is not in display driver, since i’m using it with basic functions (draw pixel, etc.) and it works.

My disp_flush()

static void disp_flush(lv_disp_drv_t * disp_drv, const lv_area_t * area, lv_color_t * color_p)
	int32_t x, y;
	for(y = area->y1; y <= area->y2; y++) {
		for(x = area->x1; x <= area->x2; x++) {
			ssd1306_DrawPixel(x, y, lv_color_to1(*color_p));

My lv_port_disp_init()

void lv_port_disp_init(void)

    static lv_disp_draw_buf_t draw_buf_dsc_1;
    static lv_color_t buf_1[MY_DISP_HOR_RES * 10];                          /*A buffer for 10 rows*/
    lv_disp_draw_buf_init(&draw_buf_dsc_1, buf_1, NULL, MY_DISP_HOR_RES * 10);   /*Initialize the display buffer*/

    static lv_disp_drv_t disp_drv;                         /*Descriptor of a display driver*/
    lv_disp_drv_init(&disp_drv);                    /*Basic initialization*/

    disp_drv.hor_res = MY_DISP_HOR_RES;
    disp_drv.ver_res = MY_DISP_VER_RES;
    disp_drv.flush_cb = disp_flush;
    disp_drv.draw_buf = &draw_buf_dsc_1;

disp_init() just calls for ssd1306_init()
In my system timer i am calling lv_tick_inc(1);
Finally, my main()

int main(void)
/*Create a spinner*/
  lv_obj_t * spinner = lv_spinner_create(lv_scr_act(), 1000, 30);
  lv_obj_set_size(spinner, 32, 32);
  lv_obj_align(spinner, LV_ALIGN_BOTTOM_MID, 0, 0);
  while (1)

However, after flashing whole screen becomes filled with white.
I think that my main problem is that i don’t really undertand how flushing function works with monochrome display. Or maybe my problem in spinner init? All hepl will be highly appreciated.

There was actually problem with how my LVGL flush callback (from STM32 porting guide). Callback interprets colors as bytes, while ssd1306 driver on OLED interprets color as bit (was already mentioned on number of posts here). I don’t wanna roll my own, so just copied code directly from here.
It doesn’t solve problem with spinner, but at least now it shows simple text labels on screen.

Hi there, I have a similar setup (STM32F407-DISC1 board, i2c 128x64 oled and lvgl 8.3.11) and no matter what I try, I can’t get anything to display on the screen… I’m using this driver and it works just fine without using lvgl. Could you please show the working version of your flush_cb and are you using any set_px_cb and rounder_cb callbacks? I’m really keen to get this library to work!

Sure, I’ll try to find project and paste code on monday

…interested in this driver too :wink:

Send info pls