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

    M5Paper SDCard access

    Micropython
    8
    10
    12.9k
    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.
    • TitiMobyT
      TitiMoby
      last edited by

      Is there a way to access M5Paper SD card with MicroPython?

      There is no uos module, but os has mount function.
      I tried:

      import os
      os.mount(machine.SDCard(), '/sd')
      

      which result in:

      Traceback (most recent call last):
        File "<stdin>", line 1, in <module>
      OSError: 16
      
      1 Reply Last reply Reply Quote 0
      • M
        mrk
        last edited by

        Did you ever figure this out? Struggling with the same issue

        M 1 Reply Last reply Reply Quote 0
        • M
          Medy @mrk
          last edited by Medy

          @mrk I figured it out...

          turns out you dont need to mount at all just do

          import json
          
          with open('/sd/config.json', 'r') as fs:
          c = json.loads(fs.read())
          label0 = M5TextBox(140, 106, c['ssid'], lcd.FONT_Default, 0xFFFFFF, rotate=0)
          

          I may have run some code prior to that .. dont remember .. try that if the first thing didnt work .. ( this is from boot.py) ... maybe it gets added automatically

          import machine, os
          try:
              sd = machine.SDCard(slot=3, miso=19, mosi=23, sck=18, cs=4)
              sd.info()
              os.mount(sd, '/sd')
              print("SD card mounted at \"/sd\"")
          except:
              pass
          

          .

          import uos
          
          uos.sdconfig(uos.SDMODE_SPI,clk=18,mosi=23,miso=19,cs =4)
          
          uos.mountsd()
          
          P 1 Reply Last reply Reply Quote 0
          • P
            paeber @Medy
            last edited by

            @medy which UIFlow version do you use? v1.9.0? I have the M5Paper (Version 1) with v1.9.0

            I've still got some issues but I'm glad that this topic still has some progress.

            The code you posted from boot.py is present on mine as well, but commented out. If I add the code (in boot.py or main.py) my device freezes. This happens on sd.info() and os.mount(sd, '/sd').

            Did you use your third code from the post? or is this just a regular micropython module?

            Any help is highly appreciated :)

            1 Reply Last reply Reply Quote 0
            • P
              Pavlo
              last edited by

              Same problem. Any updates? There must be a reason why the code in boot.py is there and why it was commented out

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

                Hello guys

                the uncommented code in boot.py uses the incorrect SPI GPIOs for M5Paper. But even with the correct GPIOs it doesn't seem to work. I suspect that the SDCard driver built into the M5Paper UiFlow firmware is faulty.

                That said, I found a replacement SDCard driver here mentioned here that seems to work.

                With the sdcard.py file downloaded onto my M5Paper (alongside boot.py, main.py) I was able to list the files on the inserted SD card and write and read a file.

                import os
                from machine import Pin, SPI
                from sdcard import SDCard
                
                spisd = SPI(-1, miso=Pin(13), mosi=Pin(12), sck=Pin(14))
                sd = SDCard(spisd, Pin(4))
                os.mount(sd, '/sd')
                print(os.listdir('/sd'))
                
                ### Write file
                #f = open('/sd/___AAA.txt', 'w')
                #f.write('Some text')
                #f.close()
                
                ### Read a file
                #f = open('/sd/___AAA.txt', 'r')
                #print(f.read())
                #f.close
                

                Note: I was using Thonny to download and test.

                Thanks
                Felix

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

                M 1 Reply Last reply Reply Quote 1
                • M
                  Medy @felmue
                  last edited by Medy

                  @felmue said in M5Paper SDCard access:

                  isd = SPI(-1, miso=Pin(13), mosi=Pin(12), sck=Pin(14))
                  sd = SDCard(spisd, Pin(4))
                  os.mount(sd, '/sd')
                  print(os.listdir('/sd'))

                  Doesnt work for me ( it works for printing in thonny ... but the device freezes)

                  1 Reply Last reply Reply Quote 0
                  • M
                    mehulge
                    last edited by

                    This issue has returned for Ui Flow 2.
                    [Errno 22] EINVAL
                    E (705271) spi: spi_bus_initialize(758): SPI bus already initialized.
                    Traceback (most recent call last):
                    File "<stdin>", line 13, in <module>
                    File "<stdin>", line 8, in setup
                    File "hardware/sdcard.py", line 21, in sdcard
                    OSError: (-259, 'ESP_ERR_INVALID_STATE')

                    Any possible solutions?

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

                      Hello @mehulge

                      yep, still broken. And my previous attempt to fix that doesn't seem to work anymore.

                      Thanks
                      Felix

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

                      R 1 Reply Last reply Reply Quote 0
                      • R
                        rodrigob @felmue
                        last edited by

                        @mehulge stuck with same issue, did you ever found the fix?

                        1 Reply Last reply Reply Quote 0
                        • R rodrigob referenced this topic on
                        • First post
                          Last post