U8G2 runs very slowly

colinives
Posts: 37
Joined: Tue Mar 03, 2020 2:53 pm

U8G2 runs very slowly

Postby colinives » Tue Mar 09, 2021 5:26 pm

So, the good news what the driver problem has been solved but, as is often the way, things move forward then hold!

I'm running a 128x64 OLED with SPI

For testing, I'm drawing a 10 pixel circle and moving on one pixel every loop - I started with a delay but have now removed it:

The problem I'm having now is that the draw speed is very, very slow - one circle a second running on an ESP32 with Freertos. Its so slow you can see it writing the circle!

Code: Select all

	u8g2_t u8g2; 
		u8g2_Setup_ssd1306_128x64_noname_f(
		&u8g2,
		U8G2_R0,
		u8g2_esp32_spi_byte_cb,
		u8g2_esp32_gpio_and_delay_cb); 


	u8g2_InitDisplay(&u8g2); // send init sequence to the display, display is in sleep mode after this,

	u8g2_SetPowerSave(&u8g2, 0); // wake up display
	int intXPos = 0;
		u8g2_ClearBuffer(&u8g2);
	u8g2_DrawCircle(&u8g2, 32,intXPos, 10,U8G2_DRAW_ALL);
	u8g2_SetFont(&u8g2, u8g2_font_ncenB14_tr);
	u8g2_DrawStr(&u8g2, 0,15,"Hello Colin!");

	while(true){
	u8g2_ClearBuffer(&u8g2);
	u8g2_DrawCircle(&u8g2, intXPos,32, 10,U8G2_DRAW_ALL);
	u8g2_SendBuffer(&u8g2);
	intXPos +=1;
	if (intXPos>100) intXPos = 0;
	//vTaskDelay(10/ portTICK_PERIOD_MS);
}
Your thoughts/ideas on why this is happening would be very welcome. Runs a dream on Arduino (SPI)

colinives
Posts: 37
Joined: Tue Mar 03, 2020 2:53 pm

Re: U8G2 runs very slowly

Postby colinives » Tue Mar 16, 2021 9:08 am

"Doh"

Of course the clock rate was set to only 50khz - no wonder it was running slow. I guess I didn't check there because it didn't occur to me it would bet set at walking pace. Ho Hum

The solution is in the u8g2_es32_hal.c:

Was:
dev_config.clock_speed_hz = 50000;

Changed to:
u8gv_config.clock_speed_hz = 10000000;

myetam
Posts: 3
Joined: Sat Oct 26, 2024 11:25 am

Re: U8G2 runs very slowly

Postby myetam » Sun Oct 27, 2024 9:08 am

I had a similar issue with u8g2 but I'm using an I2C connection to the display.
There is also a constant that sets the I2C frequency but it's defined in the header file u8g2_es32_hal.h, not in the .c file.

So, just changing the:

Code: Select all

#define I2C_MASTER_FREQ_HZ 50000     //  I2C master clock frequency
from the default 50k, to 400k, which I believe is the I2C standard solved the issue for me.

Or at least it's good enough. I was getting around 4 fps before, not it's around 20, though originally when I was running u8g2 on Arduino it was around 30 fps, but 20 fps is already ok for me.

Who is online

Users browsing this forum: No registered users and 55 guests