Announcement

Collapse
No announcement yet.

Problems reading from SD card

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Problems reading from SD card

    Hi,

    I'm having issues reading data from an SD card. I'm using the uOLED-160-G2 controlled by an Arduino and eventually I want to simply display an image from the SD card. As my straight-forward approach using media_DisplayImage didn't work, I tried a small test program to see whether I can properly access the SD card at all. I'm simply creating random numbers, write them to the SD card and try to read them back in:

    Code:
    [...]
      Display.print("Media init...");
      int i = Display.media_Init();
    
      if (i > 0) {
        Display.println("done");
          
       // Create random numbers and write them to SD
    
        Display.media_SetAdd(0, 0);
        Display.media_SetSector(0, 0);
    
        for (int i = 0; i < 10; i++) {
          word w = random(65535);
          Display.print("writing ");
          Display.print(w);
          int res = Display.media_WriteWord(w);
          if (res == 0) {
            Display.println(" failed!");
          } else {
            Display.println(" success");
          }
        }
    
        int res = Display.media_Flush();
        if (res == 0) {
          Display.println("flush failed!");
        } else {
          Display.println("flush success");
        }
    
       // Read back numbers from SD
    
        Display.media_SetAdd(0, 0);
        Display.media_SetSector(0, 0);
    
        for (int i = 0; i < 10; i++) {
          word width = Display.media_ReadWord();
          Display.println(width);      
        }
      } else {
        Display.println("failed!");
      }
    [...]
    The writing part seems to work (at least I get "success" messages), but all the reads return 65535.

    Any ideas what I'm doing wrong?
    Last edited by Harald.S; 4th July 2018, 09:23 PM.

  • #2
    Hi Harald,

    Welcome to the forum!

    With regards to the displaying of an image from the SD card, you may want to look at the Serial Displaying Images from the uSD Card Application notes at https://www.4dsystems.com.au/appnote/4D-AN-00134/ with a minor revision to have the codes an Arduino Compatible. I have also tried loading image from the memory card by just pasting the code of the image and it works fine for me. Below was the pasted code of the image:
    Display.media_SetAdd(iImage1H, iImage1L) ; // point to the Image1 Image1 image
    Display.media_Image(##, ##) ; // show image
    On the other hand, I tested the sample code you have provided and got random values of ‘w’ as expected. I have tested the codes in both Arduino Compatible environments and found no errors. The values that are written to the memory card are the same values that are read in the SD card.

    Have you tried using different SD card?

    I have attached a video file displaying the output.

    Hope this helps.

    Best Regards,
    Attached Files
    Danica

    Comment


    • #3
      Hi Danica,

      thanks for the input. I didn't suspect the SD card, as it works flawlessly on my computer and also on another display module (by Adafruit). But you are right, I tried again with a different SD card and now it works as expected.

      From the first SD card I tried I have two samples. Both show the same behavior i. e. writing to the card results in "success", but reading always returns 65535. So it seems this model is not compatible with the SD card reader in the display. The model is an 8 GB micro SD card from Silicon Power, see here: https://www.silicon-power.com/web/product-170 (SP008GBSTHBU1V20SP). Do you have any idea why this card would not work?

      Comment


      • #4
        Hi Harald,

        Glad to know that the problem has been solved.

        One of the reasons why the SD card is not compatible with your program is because it is not SPI compatible.

        You may also want to check this link: https://forum.4dsystems.com.au/forum...ds-support-spi for the list of working and non-working uSD cards for the 4D displays.

        Hope this helps.

        Best Regards,
        Danica

        Comment

        Working...
        X