🤖Have you ever tried Chat.M5Stack.com before asking??😎
    M5Stack Community
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Register
    • Login

    Avoid LCD Flicker When Updating Text on M5StickC?

    Micropython
    5
    6
    12.2k
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • J
      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.

      Other suggestions?

      1 Reply Last reply Reply Quote 0
      • m5stackM
        m5stack
        last edited by m5stack

        try use M5.Lcd.fillRect(x,y,w,h,color); to cover display the value. don't need clear whole screen

        1 Reply Last reply Reply Quote 0
        • felmueF
          felmue
          last edited by felmue

          Hello @JackH

          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.

          Cheers
          Felix

          GPIO translation table M5Stack / M5Core2
          Information about various M5Stack products.
          Code examples

          J 1 Reply Last reply Reply Quote 0
          • R
            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
            lcd.set_fg(color)

            On 1.4.5 firmware looks like:
            https://youtu.be/EzupP4tXkZA

            1 Reply Last reply Reply Quote 0
            • J
              JackH @felmue
              last edited by

              Thanks @felmue and @robalstona , I will try your suggestions tomorrow.
              Jack

              1 Reply Last reply Reply Quote 0
              • A
                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);
                
                1 Reply Last reply Reply Quote 0
                • First post
                  Last post