Avoid LCD Flicker When Updating Text on M5StickC?
JackH last edited by
I measure quantities and display them every tenth of a second or so. The screen flickers annoyingly.
I have tried lcd.clear() and overwriting with the previous text with lcd.Black color in between writes but they both flicker the same way. printing '\r' on each line before writing text doesn't work either.
m5stack last edited by m5stack
M5.Lcd.fillRect(x,y,w,h,color);to cover display the value. don't need clear whole screen
felmue last edited by felmue
Here is my attempt to reduce flicker for a simple counter. The code separates the digits and only updates the ones which are necessary. The flicker isn't completely gone, but at least only the digit which changes flickers a little bit.
from m5stack import * from m5ui import * from uiflow import * import time setScreenColor(0x000000) count0 = None oldten0 = None one0 = None ten0 = None from numbers import Number import math count0 = 0 oldten0 = 0 for count in range(30): one0 = count0 % 10 lcd.print(one0, 20, 5, 0x000000) count0 = (count0 if isinstance(count0, Number) else 0) + 1 one0 = count0 % 10 lcd.print(one0, 20, 5, 0xff0000) ten0 = math.floor(count0 / 10) if ten0 != oldten0: lcd.print(oldten0, 5, 5, 0x000000) lcd.print(ten0, 5, 5, 0xff0000) oldten0 = ten0 wait_ms(300)
BTW: In the Arduino environment a solution to reduce flicker is to use sprites, but I have no idea if sprites exist in M5Stack's MicroPython implementation.
robalstona last edited by robalstona
I am using the lcd.print function. I add one or two spaces to the displayed value and display in the same place. In firmware version 1.4.5 UiFlow, this function displays text with a black background (default), blurring previously displayed text completely. And there is no display flickering effect. Unfortunately, in version 1.5 the background of the text is transparent and the following text overlaps. I don't know how it is solved from version 1.6 and higher.
or try below commands in execute block
Print text on screen, x and y is beginning cursor , use current foreground color is not given
lcd.print(text, x, y, [,color])
Set the default foreground color
On 1.4.5 firmware looks like:
JackH last edited by
Thanks @felmue and @robalstona , I will try your suggestions tomorrow.
anuradhawick last edited by
You can always use sprites to get rid of flicker. It happens because you write to LCD in runtime which is slow. Try sprites;
First, create a sprite and set the size. Then fill it in black to avoid overwriting text.
disp_buffer = new TFT_eSprite(&M5.Lcd); disp_buffer->setSwapBytes(false); disp_buffer->createSprite(240, 135); disp_buffer->fillRect(0, 0, 240, 135, BLACK);
Then write desired text and push it to screen.
disp_buffer->drawString("This is some text", 0, 0, 2); disp_buffer->pushSprite(0, 0);