Can't access SD card

can see directories, can detect SD card, but can’t get into it to read or write files to it below is what happens when running some simple code

:open_file_folder: Root directories:

  • rom
  • flash
  • sdcard

:white_check_mark: SD card detected!
:wrench: mount()/remount() skipped or failed: ‘str’ object has no attribute ‘readblocks’
:cross_mark: Error accessing /sd: [Errno 19] ENODEV
• This is a known ENODEV bug in OpenMV v4.7.0 on STM32H7 boards.
OpenMV v4.7.0; MicroPython v1.25.0-r0; OPENMV4P with STM32H743
Type “help()” for more information.

I was using copilot to help with writing and reading to the SD card, I’m finding out copilot is unfamiliar with all the SD card usage on h7. I eventually found img.save for storing images but am struggling with fully utilizing the SD card on h7 via openMV.

Hi, the SD card is mounted under /sdcard:

I’ve seen chatgpt giving people repeatedly the wrong advice here.

Also, you should not use an absolute path which chatgpt also likes to give.

The card is also already mounted. You do not need to mount it. This causes problems.

Always tell the AI you just want to do normal file read/writes using a relative path.

thanks much, finally have several hours I was lucky to insist with copilot to use a different import a different library. now we are importing pyb file I/O commands and we seem to be good, though just did a simple text write and read. I will copy your suggestion and try it as I’m very new to microcontrollers, about 2 months on pi pico before coming over here

finally got copilot to use pyb, code below


import pyb


# Check SD card status
sd = pyb.SDCard()
if sd.present():
    print("✅ SD card detected! Listing files...")

    try:
        # Use OpenMV's SD card file system commands
        with open("test_file.txt", "w") as f:
            f.write("Hello, Rookie OpenMV dude!\n")
        print("✅ File 'test_file.txt' written successfully!")

        # Read the file contents
        with open("test_file.txt", "r") as f:
            content = f.read()
        print("📖 File contents:\n", content)

    except OSError as e:
        print(f"❌ Error accessing SD card: {e}")

else:
    print("❌ No SD card found. Please insert one.")

output:

✅ SD card detected! Listing files...
✅ File 'test_file.txt' written successfully!
📖 File contents:
 Hello, Rookie OpenMV dude!
OpenMV v4.7.0; MicroPython v1.25.0-r0; OPENMV4P with STM32H743
Type "help()" for more information.
>>>

I recommend just os.stat(“/sdcard”) and check if that doesn’t throw an exception to check if the SD card exists as the pyb module is deprecated.