Error Reading from an SD card



  • Hi there!
    I'm trying to read file information from an SD card and store that information for later retreival but I keep getting an error on line 10 that I do not understand. Does Anyone know what is going on or what I am missing? I am using an M5stack Fire core with 1.8.0-fire firmware. Code and Output error can be seen below.
    0_1625714347350_SD File Reader Program.png
    0_1625714363994_M5_Output.jpg


  • M5Stack

    with open('/sd/FileName.*', 'r') as fs:
      lcd.print((fs.read()), 0, 0, 0xffffff)
    


  • Hi M5Stack,
    Thanks for your answer but this really doesn't help me. I'm trying to create a database so that I can cherry pick the information I want to show the user based on their inputs. The code you sent me takes all data and throws it up on the screen regardless of whether the user asked for that information or not. Here is a small example using python:

    SD card file data:
    0_1625759040986_Faux Data.png

    Python code:
    0_1625759074942_Python Way.png

    Python output:
    0_1625759101619_Python Output.png

    The M5stack does have the ability to parse out information from a list of list, I know because I tested it, but I'm having trouble reading the file from an SD card and creating a list of lists (basically an in memory ready data base.) The reason for the SD card is because this information changes depending on the project. Changing information on an SD card (or switch SD cards) is a lot easier than programming information straight to the M5stack.

    Also based on your answer where is fs.close()? Does the M5stack automatically do this or is the file left open while the program is running. If the file is left open while the program is running, how do you mitigate file corruption when loss of power to the M5Stack occurs?



  • @M5Stack After looking at your comment again I figured out what you were trying to tell me (Took me a while to figure it out). I forgot to tell the M5Stack where to look for the text file using /sd/file_name. That took care of the error. Still am unable to print what I want to the screen but at least I'm one step closer.