M5 Paper SD image display stopped working



  • I managed to get a small black and white png file of a smiley face stored on a micro SD card to display on the M5 Paper V1.1 but now when I flash the device, the screen refreshes white and no image is displayed. I removed the SD card to verify that the png file was not corrupted, and it looked fine on my PC. I have tinkered with the code, to scale the image up, which is when it stopped working (initially correctly scaled it) so I tried to go back to the basic drawPngFile() function but it did not recover.

    What could have gone wrong?

    #include <M5EPD.h>
    
    M5EPD_Canvas canvas(&M5.EPD);
    
    void setup()
    {
      M5.begin();
      M5.EPD.SetRotation(0);
      M5.EPD.Clear(true);
    
      canvas.createCanvas(540, 960);
      canvas.setTextSize(3);
      canvas.drawPngFile(SD, "/smiley.png", 0, 0);
      canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
    }
    


  • I tried using an SD file test example and SD.begin() returned false (I used SPI.begin(14, 13, 12, 4) ).

    So to try and get around the issue of the SD card, I placed smiley.png in a data folder in the Arduino sketch folder and used the ESP32 Sketch Data Upload tool in Arduino/Tools menu to copy the png to SPIFFS.

    Then I ran the code above with canvas.drawPngFile(SPIFFS, "/smiley.png", 0, 0); and got the same blank display.

    Then I tried to test SPIFFS to detect the file, with

     File file = SPIFFS.open("/smiley.png");
    
      if (!file) {
        Serial.println("Failed to open file for reading");
        return false;
      }
    

    and this returned false/ printed the failure message. Very confused now about where the issue could be! Sorry to ping but @felmue is there anything obvious I'm doing wrong or a known issue with SD cards and the Paper? Or another diagnostic check I should try? Being able to use the SD card or SPIFFS to store images would be extremely helpful for my project plans.

    The only other symptom I can report which may be of use is that when I used the scale factor in the overloaded drawPngFile(), I now get a square of that size flash white when the Paper runs setup(), as opposed to the full canvas size or the size of the original png. I find that strange and thought I'd add it in case it gives a clue as to the issue.



  • Hello @simonm

    I am no expert in this, but have you tried this example? It gives you a jpg file which can be displayed on the M5Paper. You could download and save it to your SD card and then try to use it from there.

    Thanks
    Felix



  • Thanks for the suggestion @felmue . That example is pretty much what I based my initially-working-now-not working test with the drawPngFile(). I have just downloaded and tested with the flower image on the SD card and it fails to render on the EPD:

    #include <M5EPD.h>
    //#include <WiFi.h>
    
    M5EPD_Canvas canvas(&M5.EPD);
    
    void setup() {
        M5.begin();
        M5.EPD.SetRotation(90);
        M5.EPD.Clear(true);
        /*
        WiFi.begin("WIFI-SSID", "WIFI-PASSWORD");
    
        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
        }
    */
        canvas.createCanvas(540, 960);
        canvas.setTextSize(3);
        /*
        canvas.drawJpgUrl(
            "https://m5stack.oss-cn-shenzhen.aliyuncs.com/image/example_pic/"
            "flower.jpg");
            */
        canvas.drawJpgFile(SD, "/flower.jpg", 0, 0);
        canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
    }
    

    I added to the M5EPD::begin(...) function in M5EPD.cpp:

      if (SDEnable == true) {
            SPI.begin(14, 13, 12, 4);
    	bool sdSuccess = SD.begin(4, SPI, 20000000);
    	if(!sdSuccess && SerialEnable) Serial.println("SD.begin() failed");
        }
    

    and when the sketch calls M5.begin() I get "SD.begin() failed" on the serial monitor. So I think this is more of an SD card issue than EPD at this point. I have tried various sequences of reset/power-down and insert/remove/insert the SD card in order to make sure both the SD card and the ESP32 start from known reset points. But no success so far. So strange that it would work a few times on the Paper and then stop working, especially as the SD card remains responsive to my Windows PC.

    I will start trying other SD cards but if anything else occurs please shout.



  • Aha, I forgot to initialise SPIFFS, which is why it didn't work with that file system. This now displays a smiley face on the EPD, from SPIFFS.

    #include <M5EPD.h>
    #include "SPIFFS.h"
    
    
    M5EPD_Canvas canvas(&M5.EPD);
    
    void setup()
    {
      M5.begin();
      M5.EPD.SetRotation(0);
      M5.EPD.Clear(true);
      if (!SPIFFS.begin(true)) {
        Serial.println("An Error has occurred while mounting SPIFFS");
        return;
      }
      if (testSpiffs())
      {
    
        canvas.createCanvas(540, 960);
        canvas.setTextSize(3);
        //canvas.drawPngFile(SD, "/smiley.png", 0, 0);
        canvas.drawPngFile(SPIFFS, "/smiley.png", 0, 0);
        canvas.pushCanvas(0, 0, UPDATE_MODE_GC16);
      }
      else
      {
        Serial.println("Error opening file from SPIFFS");
      }
    
    }
    
    void loop()
    {
    
    }
    
    bool testSpiffs(void)
    {
       /*static*/ uint16_t rowCounter = 0;
    
      File file = SPIFFS.open("/smiley.png");
    
      if (!file) {
        Serial.println("Failed to open file for reading");
        return false;
      }
    
      Serial.println("File Content:");
    
      while (file.available()) {
        Serial.print("0x");
        Serial.print((byte)file.read(), HEX);
        Serial.print(", ");
        rowCounter++;
        if (rowCounter == 12)
        {
          rowCounter = 0;
          Serial.println();
        }
      }
    
      file.close();
      return true;
    }
    

    Which strongly suggests my issue is with Paper reading from SD cards.



  • I have tested with a known-good other SD card (the previous one was brand new, out of the packet) and I cannot get a true return from SD.begin(...). Please can anyone help with how to address/debug this? Has anyone else reported their SD card reading failing before?

    EDIT: I have read some other instances of people having SD card issues on this forum. Having looked at their issues, I have ensured I have a 16GB (not larger) FAT32 formatted SD card. I have also tried SD.begin(4, SPI, 1000000); and 10 MHz too in M5EPD.cpp but it still returns false. I have also remembered to remove and reinsert the SD card between boot cycles where power has not been removed, so each SD.begin() should be the first that the SD card controller sees. Any other ideas?



  • Hello,
    I am facing the same issue and not able to display the images on to the M5 Paper. I have tried both canvas.drawPngFile(SPIFFS, "/smiley.png", 0, 0);
    and canvas.drawJpgFile(SPIFFS, "/smiley.jpg", 0, 0); but no luck.
    I already included #include "SPIFFS.h" and initialized SPIFF using M5.begin(true, true, true, true, false);. The png and jpg files are inside the data folder. SPIFFS.open("/smiley.png") is able to open the file however it is not printing any file content on the console.

    I think it is required to format the SPIFFS for the first time, as mentioned here so I followed these steps but ESP32 Sketch data upload is not appearing in arduino 2.0.

    However I am able to display the png image using canvas.drawPngUrl("http://imageUrl"); but it is taking more time and quite slow.

    Could you please help me in understanding what I am doing wrong?
    @simonm @felmue