You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to migrate my code from external library to standard micropython libray. I am usnig ESP32 DevKit-V1 board.
This is barebone code that I am using at the moment to access SD card and interact with it. This version works.
import os
from machine import Pin, SPI
import sdcard
class SDCardModule:
def __init__(self, spi, cs_pin):
self.sd = sdcard.SDCard(spi, cs_pin)
self.mount()
def mount(self):
os.mount(self.sd, '/sd')
def write(self, path, data):
with open('/sd/' + path, 'w') as f:
f.write(data)
def read(self, path):
with open('/sd/' + path, 'r') as f:
return f.read()
# Implementation example:
spi = SPI(1, sck=Pin(18), mosi=Pin(23), miso=Pin(19))
sd_module = SDCardModule(spi, Pin(5))
sd_module.write('test.txt', 'Hello, World!')
print(sd_module.read('test.txt'))
Terminal output:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4672
load:0x40078000,len:14536
load:0x40080400,len:3364
entry 0x400805cc
Hello, World!
MicroPython v1.20.0-327-gd14ddcbdb on 2023-07-27; ESP32 module with ESP32
Type "help()" for more information.
The following part is my implementation with machine.SDCard.
import os
from machine import Pin, SDCard
class SDCardModule:
def __init__(self, slot=2, sck=None, miso=None, mosi=None, cs=None):
self.sd = SDCard(slot=slot, width=1, sck=sck, miso=miso, mosi=mosi, cs=cs, freq=1000000)
self.mount()
def mount(self):
os.mount(self.sd, '/sd')
def write(self, path, data):
with open('/sd/' + path, 'w') as f:
f.write(data)
def read(self, path):
with open('/sd/' + path, 'r') as f:
return f.read()
# Implementation example:
sd_module = SDCardModule(slot=2, sck=Pin(18), miso=Pin(19), mosi=Pin(23), cs=Pin(5))
sd_module.write('test.txt', 'Hello, World!')
print(sd_module.read('test.txt'))
Terminal output:
rst:0x1 (POWERON_RESET),boot:0x13 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:2
load:0x3fff0030,len:4672
load:0x40078000,len:14536
load:0x40080400,len:3364
entry 0x400805cc
E (1150) sdmmc_common: sdmmc_init_ocr: send_op_cond (1) returned 0x107
Traceback (most recent call last):
File "boot.py", line 22, in <module>
File "boot.py", line 8, in __init__
File "boot.py", line 11, in mount
OSError: 16
MicroPython v1.20.0-327-gd14ddcbdb on 2023-07-27; ESP32 module with ESP32
Type "help()" for more information.
Can someone spot the problem as I am unable to do. I have tried to search for the problem on the forum and web, but did not find the solution or explanation that would help me resolve the problem.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
I am trying to migrate my code from external library to standard micropython libray. I am usnig ESP32 DevKit-V1 board.
This is barebone code that I am using at the moment to access SD card and interact with it. This version works.
Terminal output:
The following part is my implementation with machine.SDCard.
Terminal output:
Can someone spot the problem as I am unable to do. I have tried to search for the problem on the forum and web, but did not find the solution or explanation that would help me resolve the problem.
Beta Was this translation helpful? Give feedback.
All reactions