M5Paper SDCard access
-
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
-
Did you ever figure this out? Struggling with the same issue
-
@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()
-
@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 :)
-
Same problem. Any updates? There must be a reason why the code in boot.py is there and why it was commented out
-
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 -
@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)
-
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?
-
Hello @mehulge
yep, still broken. And my previous attempt to fix that doesn't seem to work anymore.
Thanks
Felix -
@mehulge stuck with same issue, did you ever found the fix?
-