M5 Paper : Unable to clear screen contents



  • 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



  • 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



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