Closed mumrah closed 5 months ago
U8g2 loop looks good. Interrupts might be an issue, but my ATMega knowledge is not that good. I see three interrupts enabled, maybe you should disable them step by step and see whether the performance of the display improves.
U8g2 performance improvement ideas:
I've managed to make marginal improvements by removing some unnecessary draw calls (like when the data hasn't changed).
If possible, I want to avoid things like this:
where part of the old buffer is visible while the new buffer is being drawn. Maybe this is unavoidable?
Is it possible to only update portions of the display when using the paged memory mode?
If possible, I want to avoid things like this:
It looks like, that your content changes during execution of the u8g2 while loop. I mean, "u8g2.drawStr(0, 30, ui->buffer_1);" seems to change although I don't see the reason for this in your code.
After a lot of trial and error, I've gotten things working better.
One big help was to remove unnecessary calls to
u8g2.drawStr(0, 56, ui->message_line_1);
u8g2.drawStr(0, 64, ui->message_line_2);
(these are only populated in certain cases)
Another issue I kept having was that the display would blank out after a while. I believe this was due to the timing of the interrupt code. My interrupt was firing at 50Hz and I guess if it runs too long, it disrupts the SPI communication. I've optimized my interrupt code and now it's running at 500Hz and the UI is no slower (and doesn't crash).
I'm still seeing draw times around 600-700ms total using paged mode. I never really got it to be much faster without removing UI elements. I guess I'm asking a lot of this ATMega :)
In the future, I'll be trying a higher clock speed for the ATMega328p. Currently I'm running at 8Mhz. I'm hoping 12 or 16Mhz will make the UI a lot snappier.
Thanks for the help!
Hello, thanks for this incredible library! It has saved me a ton of SRAM :)
I've run into some trouble with the drawing speed and I was wondering if there's anything obvious I'm doing wrong.
My microcontroller is an ATMega328p running at 8MHz.
I'm using this constructor
U8G2_SSD1309_128X64_NONAME0_2_4W_HW_SPI u8g2(U8G2_R2, 10, 9);
I recently switched from using the blocking
analogRead
method to using interrupts for ADC reads. I am using Timer1 for this purpose. I noticed after this switch, things went wrong with my OLED display. Initially, I was updating the OLED in between analogRead calls as part of my main loop. The display was being refresh once every few hundred milliseconds and things looked smooth.Now that I'm using interrupts, the display seems slow to draw and eventually it stops updating completely. I added some code to time the UI drawing (shown below) and its taking around ~190ms for each update (so, ~95ms per page)
I'm wondering if this could be related to the new interrupt code interfering with the SPI timing, or just generally slowing down the execution of my code. Or maybe my use of a Timer1 is throwing something off?
Any ideas?
Here is my setup code:
and my main draw routine