SD card after ejecting and re-inserting.

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
sim222
Posts: 5
Joined: Wed Nov 27, 2019 12:04 am

SD card after ejecting and re-inserting.

Post by sim222 » Mon Jan 11, 2021 11:03 am

Hi guys,
Thanks for your valuable posting!!

I have searched the article last a few days however, failed to find any proper answer regarding my problem.
My project is the data logger using pyboard which should receive three sensors and send it's data through serial port and save any data.
So I need to save the data into the sd card.
My simple cord worked well however, after ejecting and re-inserting the card I can't access the card anymore until the power-resetting even keyboard-reset(Ctrl-D) didn't work.

So tested the mount method uos.mount() / uos.umount() / os.mount() / os.umount()
From the test, I have got the conclusion that ejecting the card makes me not to access the card anymore.

1. before ejecting, I can mount and unmount freely and access the card any time I want.

2. After re-inserting, I can't use any method related the access sd card before power-reset.

Got this kind of message to access the card.

Is it impossible to access it without power-resetting?
I think this kind of issue would occur easily in the real world because of the vibration.

How can I deal with this issue regarding sd card?

>>> uos.mount(sd,'/sd')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
OSError: [Errno 19] ENODEV


Here's my cord.

#simple SD recorder

#Logs the data from the accelerometer to a file n the SD card

import pyb,lcd160cr
from BMP280 import BMP280_I2C

lcd = lcd160cr.LCD160CR('X')
lcd.set_orient(lcd160cr.PORTRAIT)
lcd.set_pos(0, 0)
lcd.set_text_color(lcd.rgb(255, 0, 0), lcd.rgb(0, 0, 0))
lcd.set_font(1,0)
lcd.write('Hello MicroPython!\n')
lcd.erase()

accel=pyb.Accel()
blue=pyb.LED(4)
s=BMP280_I2C(2)

f.write('From accelerometer, time,x,y,z,temperature,pressure\n')
f.close()

blue.on()

while True:
blue.on()
lcd.erase()
lcd.set_pos(0,0)

f=open('test.log','a')

for n in range (5):
t=pyb.millis()
rv=s.read()

x,y,z=accel.filtered_xyz()
f.write('{},{},{},{},{},{}\n'.format(t,x,y,z,s.temperature,s.mbar))
print('{},{},{},{},{},{}\n'.format(t,x,y,z,s.temperature,s.mbar))
lcd.set_pos(0,n*25)
lcd.write('{},{},{},{}\n'.format(t,x,y,z))
lcd.set_pos(0,n*25+10)
lcd.write('{0:0.2f},{1:0.2f}\n'.format(s.temperature,s.mbar))
pyb.delay(500) # 500ms


f.close()
blue.off()
pyb.delay(500)

Post Reply