SD card recognition after reinserting.

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
sim222
Posts: 20
Joined: Wed Nov 27, 2019 12:04 am

SD card recognition after reinserting.

Post by sim222 » Mon Jan 25, 2021 1:50 am

I have posted it on the pyboard forum however, I haven't got the reply for this issue,
PLZ give the advice ~
---------------------------------------------------
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)

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: SD card recognition after reinserting.

Post by pythoncoder » Tue Jan 26, 2021 6:33 am

The Pyboard does not support hot plugging of the SD card.
Peter Hinch
Index to my micropython libraries.

sim222
Posts: 20
Joined: Wed Nov 27, 2019 12:04 am

Re: SD card recognition after reinserting.

Post by sim222 » Mon Feb 01, 2021 6:36 am

pythoncoder wrote:
Tue Jan 26, 2021 6:33 am
The Pyboard does not support hot plugging of the SD card.
oops...

Then, how can I handle it?
It should be the only hardware reset?
Is there any software solution for this issue?

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: SD card recognition after reinserting.

Post by pythoncoder » Mon Feb 01, 2021 9:16 am

My understanding is that the SD card should only be removed or inserted when the power is down.

It is possible to run an external SD card using the official sdcard.py driver. In this case you can provide your own power control circuit allowing you to power down the external SD card for removal and re-insertion.
Peter Hinch
Index to my micropython libraries.

sim222
Posts: 20
Joined: Wed Nov 27, 2019 12:04 am

Re: SD card recognition after reinserting.

Post by sim222 » Tue Feb 02, 2021 12:48 am

pythoncoder wrote:
Mon Feb 01, 2021 9:16 am
My understanding is that the SD card should only be removed or inserted when the power is down.

It is possible to run an external SD card using the official sdcard.py driver. In this case you can provide your own power control circuit allowing you to power down the external SD card for removal and re-insertion.
Thanks for your idea!!
Ok. I will try it.

Best regards,

Post Reply