SD Card not mounting on computer or on board

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

SD Card not mounting on computer or on board

Post by UltraBob » Tue Aug 05, 2014 8:49 am

HI,

I have a Victor 4Gb class 4 microSD card, that I swear worked a few weeks back when I tried to use it (a few firmware upgrades ago)

I tried using it today and couldn't get it to work. When I plug in the usb cable, my finder windows (Mac OS 10.9) shudder as if they are mounting a new volume, but no volume shows up, not in the finder and not in disk utility.

When I log into repl and do:

Code: Select all

import sys
sys.path
I get

Code: Select all

['', '/flash', '/flash/lib']
but it isn't mounting the flash drive on my mac as a usb drive, so obviously it has some knowledge that there is a microSD card plugged in. I've tried reformatting the drive in FAT again in case the board wasn't liking the formatting, but that was no help.

What steps should I take next to debug this?

Incidentally I updated the firmware today in hopes of fixing this issue. Prior to that of course repl was reporting 0:/ variants.
Last edited by UltraBob on Wed Aug 06, 2014 1:32 pm, edited 1 time in total.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Wed Aug 06, 2014 1:28 pm

If anyone has any idea on how to debug this I'd appreciate it. I've tried mounting it on my mac, and on ubuntu running in virtual box on the mac, but neither of those worked. Putting the card in a card reader it mounted just fine. I wonder if booting the board in mode 3 with the sd card in would do anything...

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Wed Aug 06, 2014 1:37 pm

Well, that is either progress or just random chance. I booted the board in mode 3, and reset the files in flash at least. The first time it booted, I got the flash showing up as NO NAME and I restored my main.py and /lib folder onto it. Upon reset nothing mounted and nothing seemed to run on the board. running repl, I now see the following:

Code: Select all

>>> import sys
>>> sys.path
['', '/flash', '/flash/lib', '/sd', '/sd/lib']
>>> 
but unfortunately nothing mounts on the mac, so I don't have anyway that I know of to get stuff onto the sd card.

I had been wondering what pyb.sync() does, so maybe I'll try that out next, I'm feeling reckless.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Wed Aug 06, 2014 2:06 pm

I still don't know what pyb.sync does, but it doesn't sync the two memory cards. I didn't think it would, but it was worth a shot in desperate times. ;)

Is there a way in python for me to manipulate files (copy the files from flash to sd card)? I'm having some trouble without shutils available. I tried one thing, but got a memory error.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Wed Aug 06, 2014 2:11 pm

Got that working:

Code: Select all

def copyfile(source, dest, buffer_size=32):
    """
    Copy a file from source to dest. source and dest
    can either be strings or any object with a read or
    write method, like StringIO for example.
    """
    if not hasattr(source, 'read'):
        source = open(source, 'rb')
    if not hasattr(dest, 'write'):
        dest = open(dest, 'wb')
    while 1:
        copy_buffer = source.read(buffer_size)
        if copy_buffer:
            dest.write(copy_buffer)
        else:
            break
    source.close()
    dest.close()
Still, that is a terrible way of working. Any help I can get on getting the SD card to mount would be glorious. Otherwise I guess I need to make sure I carry the microsd adapter and mount the card on my laptop that way.

LeskoIam
Posts: 1
Joined: Wed Aug 06, 2014 2:05 pm

Re: SD Card not mounting on computer or on board

Post by LeskoIam » Wed Aug 06, 2014 2:13 pm

Take a look at this http://wiki.micropython.org/SDdatalogger. I think :)

Turbinenreiter
Posts: 288
Joined: Sun May 04, 2014 8:54 am

Re: SD Card not mounting on computer or on board

Post by Turbinenreiter » Wed Aug 06, 2014 3:44 pm

Note that in the SDdatalogger exymple the filenames of flash and sd aren't updated yet.

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Thu Aug 07, 2014 12:43 am

I wish I'd brought the board in with me so I could experiment with this, but I guess the suggestion is that I could either put in a manual toggle or I could add a little delay before setting the USB mode to hopefully give the sd some time to settle before presenting it to the OS, or have I missed the point entirely?

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Sun Aug 10, 2014 1:32 pm

OK, This worked, here is my full boot.py:

Code: Select all

# boot.py -- run on boot-up
# can run arbitrary Python, but best to keep it minimal

import pyb
#pyb.main('main.py') # main script to run after this one
#pyb.usb_mode('CDC+MSC') # act as a serial and a storage device
#pyb.usb_mode('CDC+HID') # act as a serial device and a mouse

pyb.delay(200)
pyb.usb_mode('CDC+MSC')
I'll experiment now with a smaller delays to see how large it has to be to still mount on the computer.

I defined the function to copy a file as seen above in the repl, and then copied my boot.py over like so:

Code: Select all

copyfile('/flash/boot.py', '/sd/boot.py')
If you are on an older version of the firmware you'll have to use

Code: Select all

0:/
and

Code: Select all

1:/
instead of

Code: Select all

/flash
and

Code: Select all

/sd

User avatar
UltraBob
Posts: 43
Joined: Mon Jul 28, 2014 1:18 pm
Location: Zushi, Japan
Contact:

Re: SD Card not mounting on computer or on board

Post by UltraBob » Sun Aug 10, 2014 1:43 pm

Even a delay of 1 millisecond seems to work. I suspect that running anything before setting usb_mode would have a similar effect.

Post Reply