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)
SD card after ejecting and re-inserting.
Re: SD card after ejecting and re-inserting.
Try sd.deinit() after uos.umount('/sd') or eject SD card, and initialize 'sd' object again after re-insert SD card.
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: SD card after ejecting and re-inserting.
Worth a try, but I don't hold out much hope. I think hot plugging the Pyboard SD card is unsupported.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: SD card after ejecting and re-inserting.
.deinit() is affect to ESP32 port, I confuse them, on PyBoard, use sd.power() instead,
before eject SD card,
If none SD card inserted, execute sd.power(0) or sd.power(1) will return False.
before eject SD card,
Code: Select all
uos.umount('/sd')
sd.power(0)
then re-insert SD card,True
Code: Select all
sd.power(1)
True
Code: Select all
uos.mount(sd, '/sd')
Re: SD card after ejecting and re-inserting.
It looks work!! Thanks a lot.water wrote: ↑Fri Feb 12, 2021 7:00 pm.deinit() is affect to ESP32 port, I confuse them, on PyBoard, use sd.power() instead,
before eject SD card,Code: Select all
uos.umount('/sd') sd.power(0)
then re-insert SD card,TrueCode: Select all
sd.power(1)
TrueIf none SD card inserted, execute sd.power(0) or sd.power(1) will return False.Code: Select all
uos.mount(sd, '/sd')
I will test it again!!