Page 1 of 1
howto mount sd card in script
Posted: Wed Apr 12, 2017 6:43 am
by icenov
I'm running a script on a pyboard (V1.1) that logs solar data to an SD card. I've decided to (foolishly!) include a check to see if the card is present, and if not then stop the script and print a warning. It works to a point - the switch press works, but I can't find a way to mount the card in software and continue the script. If the card is present on boot, then everything works.
Code: Select all
try:
os.chdir('/sd')
except OSError:
print('No SD card detected! - insert card and press usr switch')
while switchpress == 0:
print('waiting for switchpress...')
utime.sleep(1)
else:
print('switchpress registered')
# need to mount SD card!
# switchpress=0
#
I've tried to use pyb.mount(sd,/sd) and some of the other obvious(?) commands with no luck. I'm trying to avoid running a reboot after inserting the card. I recall reading a way to do this in the forum, but can't seem to find it again.
Any suggestions appreciated.
Re: howto mount sd card in script
Posted: Wed Apr 12, 2017 6:57 am
by dhylands
After waiting for the user switch, you could do a hard-reset by using pyb.hard_reset() or machine.reset().
Re: howto mount sd card in script
Posted: Wed Apr 12, 2017 7:06 am
by icenov
I did initially use that, but then instantly lost my terminal connection (using rshell) so thought there might be a more subtle way!
Re: howto mount sd card in script
Posted: Wed Apr 12, 2017 7:14 am
by dhylands
rshell should reconnect (at least under linux). Press RETURN to see the prompt again.
Re: howto mount sd card in script
Posted: Wed Apr 12, 2017 7:31 am
by icenov
Not for my setup unfortunately (Ubuntu 16.10) . It drops back to rshell, but REPL won't connect and I have to ctrl-C out of rshell, restart rshell and then I can REPL and ctrl-D soft reboot. It's not a problem - and it might be related to auto-mounting the SD card, which I haven't disabled yet.
Re: howto mount sd card in script
Posted: Thu Apr 13, 2017 7:00 pm
by pythoncoder
I can confirm this, Dave, under Mint 17.1 (rebecca) on a Pyboard 1.1 with an SD card fitted and MSC mode disabled.
Code: Select all
[adminpete@axolotl]: ~
$ rshell
Connecting to /dev/pyboard ...
Welcome to rshell. Use Control-D to exit.
/home/adminpete> repl
Entering REPL. Use Control-X to exit.
>
MicroPython v1.8.7-589-gd7310fa on 2017-04-08; PYBv1.1 with STM32F405RG
Type "help()" for more information.
>>>
>>> pyb.hard_reset()autoconnect: /dev/ttyACM0 action: remove
USB Serial device '/dev/ttyACM0' disconnected
autoconnect: /dev/ttyACM0 action: add
Connecting to /dev/ttyACM0 ...
serial port /dev/pyboard closed
/home/adminpete> repl
Entering REPL. Use Control-X to exit.
^X^C
[adminpete@axolotl]: ~
At the REPL Enter just gave blank lines. <ctrl>D had no effect. <ctrl>X just printed ^X. The only way out was <ctrl>C.
boot.py:
Code: Select all
import pyb
pyb.usb_mode('CDC') # act as a serial (CDC) and a storage device (MSC)