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

    M5 Paper : Unable to clear screen contents

    Arduino
    2
    3
    3.3k
    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.
    • Z
      zitrone
      last edited by

      Hi folks,

      I just started using M5 paper and went through the documentation at
      https://docs.m5stack.com/en/api/m5paper/epd_canvas

      Using this info, I created a canvas with some content in the setup.
      Then, in the loop I wish to clear the canvas and display some other content.
      The code is as follows :

      #include <M5EPD.h>
      M5EPD_Canvas canvas(&M5.EPD);
      void setup() {
      M5.begin(); //Init M5Paper.
      M5.EPD.SetRotation(90); //Set the rotation of the display.
      M5.EPD.Clear(true); //Clear the screen.
      M5.RTC.begin(); //Init the RTC.

      canvas.createCanvas(540, 960); //Create a canvas.
      canvas.setTextSize(3); //Set the text size.
      canvas.drawString("Hello World", 10, 10); //Draw a string.
      canvas.pushCanvas(0,0,UPDATE_MODE_DU4); //Update the screen.
      delay(2000);
      }

      void loop() {
      M5.EPD.Clear(true); //Clear the screen.
      canvas.drawString("Another string", 10, 60); //Draw a string.
      canvas.pushCanvas(0,0,UPDATE_MODE_DU4); //Update the screen.
      delay(5000);
      }

      Expected : I see only 'Another string' after refresh every 5 seconds.
      Actual : Both 'Hello World' and 'Another string' are displayed.
      :(

      I think I am missing something. May you please explain what is going wrong here?

      Thanks,
      Zitrone

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

        Hello @zitrone

        the reason both strings are displayed is that both strings are present in the canvas which then is pushed to the screen. M5.EPD.Clear(true); only clears what is on the screen but it leaves the canvas untouched, therefore the next pushCanvas() displays both strings again on the screen.

        Try adding a canvas.fillCanvas(0); after the M5.EPD.Clear(true); - this will clean the canvas (and remove the first string). See also the touch example.

        BTW: you don't need the M5.EPD.Clear(true); in the loop for one string to be removed and the other to be added. (Note: w/o there might be a slight shadow where the first string was.)

        Thanks
        Felix

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

        1 Reply Last reply Reply Quote 1
        • Z
          zitrone
          last edited by

          @felmue Thank you for the quick reply.
          Yes, it works perfectly. :)

          1 Reply Last reply Reply Quote 0
          • First post
            Last post