Page 1 of 1

Grabbing files on SD card to use in python

Posted: Fri Mar 08, 2013 9:32 pm
by tackyattack
So let's say I am building an audio sampler using python with pygame mixer. Normally, I would put the sound .wav files into the same directory as the program so it could use them. The thing is, it's not easy to hook up the RPi to the computer when I want to load new samples in. What would be a lot easier, and make more sense, would be to have the files actually visible on the SD card. So to change the samples, all you would do is pop the SD into your computer, then drag the files over to some spot. Is it possible to source files on an SD card like this with the RPi?

Thank you!

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 8:47 am
by DBryant
You have no network connection to your Pi?

If not then you can mount the disk on another system and copy the required files to the card. Your mileage will vary according to the type of filesystems you have on your SD card. For example, if ext4 then Windows will not see them. So another Linux system is ideal, you could use a 'Live CD' on any Windows systems, mount its HDD, mount the SD card and then copy via drag and drop.

You modify the filesystems to be Windows compatible if it were more convenient to you. Depends on your overall goals in your project.

You will probably copy the files into the pi user account i.e into /home/pi or a sub-directory you have created within that location (say something like /home/pi/audio). You should how no problem finding that via a 'Live CD' file browser on the SD mount.

With a network connection, WiFi is cheap and usually trouble free to set up nowadays, then simply use secure copy (scp from the ssh stable). There are a variety of ways of getting this functionality, my solution has always been to install Cygwin on my Windows laptop(s). This will provide the full Linux experience from the command line, well as much as you want.

Hope this helps.

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 5:05 pm
by tackyattack
DBryant wrote:You have no network connection to your Pi?

If not then you can mount the disk on another system and copy the required files to the card. Your mileage will vary according to the type of filesystems you have on your SD card. For example, if ext4 then Windows will not see them. So another Linux system is ideal, you could use a 'Live CD' on any Windows systems, mount its HDD, mount the SD card and then copy via drag and drop.

You modify the filesystems to be Windows compatible if it were more convenient to you. Depends on your overall goals in your project.

You will probably copy the files into the pi user account i.e into /home/pi or a sub-directory you have created within that location (say something like /home/pi/audio). You should how no problem finding that via a 'Live CD' file browser on the SD mount.

With a network connection, WiFi is cheap and usually trouble free to set up nowadays, then simply use secure copy (scp from the ssh stable). There are a variety of ways of getting this functionality, my solution has always been to install Cygwin on my Windows laptop(s). This will provide the full Linux experience from the command line, well as much as you want.

Hope this helps.

Hello there!

Thank you so very much for the wealth of information! I have indeed connected my Pi to my computer via ssh and scp. So far it has worked great! The only problem is that it's a little bit too tedious for the application that it will end up being.

I am using a Mac computer, which is Linux, correct? I have opened the SD card on it and see no directories. I've attached a picture of the files I am seeing.
Screen Shot 2013-03-09 at 10.58.33 AM.png
Screen Shot 2013-03-09 at 10.58.33 AM.png (18.6 KiB) Viewed 5712 times

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 5:27 pm
by DBryant
MacOS is a Unix rather than Linux, it should be NFS literate. Sorry never used MacOS so I can't be definitive, b ut Googling around this does seem to be the case.

How is your SD card partitioned?

Code: Select all

sudo fdisk -l
on your Pi will show you.
On inserting a Pi SD card into my Linux box, running Ubuntu, I would see several new mount-points. The one you have show is what /boot. As I've configured mine a second one will be the /home directories containing the pi accounts filesystem. I would then be in a position to drag'n'drop files as you appear to want. But of course mine is Linux throughout so I've not much worry about the various filesystems, it all is consistent and inter-working is no issue.

http://blog.applegrew.com/2011/12/acces ... lion-10-7/ says that ext2/3 filesystems are supported, but I've seen ext4 requires some commercial software. Maybe someone on the forum can contribute here. But once you have a filesystem your Mac can see then you should be able to achieve your result.

If you can determine the SD configuration, idnetifiy your version of Mac OS, then we can go from there I'm sure.

Meanwhile back to the rugby!

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 5:50 pm
by tackyattack
DBryant wrote:MacOS is a Unix rather than Linux, it should be NFS literate. Sorry never used MacOS so I can't be definitive, b ut Googling around this does seem to be the case.

How is your SD card partitioned?

Code: Select all

sudo fdisk -l
on your Pi will show you.
On inserting a Pi SD card into my Linux box, running Ubuntu, I would see several new mount-points. The one you have show is what /boot. As I've configured mine a second one will be the /home directories containing the pi accounts filesystem. I would then be in a position to drag'n'drop files as you appear to want. But of course mine is Linux throughout so I've not much worry about the various filesystems, it all is consistent and inter-working is no issue.

http://blog.applegrew.com/2011/12/acces ... lion-10-7/ says that ext2/3 filesystems are supported, but I've seen ext4 requires some commercial software. Maybe someone on the forum can contribute here. But once you have a filesystem your Mac can see then you should be able to achieve your result.

If you can determine the SD configuration, idnetifiy your version of Mac OS, then we can go from there I'm sure.

Meanwhile back to the rugby!
Hello again!

Running the fdisk command I get this in return on my Pi:

Code: Select all

Disk /dev/mmcblk0: 4075 MB, 4075290624 bytes
4 heads, 16 sectors/track, 124368 cylinders, total 7959552 sectors
Units = sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disk identifier: 0x000108cb

        Device Boot      Start         End      Blocks   Id  System
/dev/mmcblk0p1            8192      122879       57344    c  W95 FAT32 (LBA)
/dev/mmcblk0p2          122880     7959551     3918336   83  Linux
I am running OS X version 1.8.2

Thank you :)

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 6:24 pm
by DBryant
Thought OS X releases were 10.x?

Look at the content of /etc/fstab on your Pi, it will show you type of filesystem. On one of my system:

Code: Select all

[b]cat /etc/fstab[/b]
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
So I have ext4 and I daresay yours is the same. So that ext4 is going to be a source of aggravation by the look of it.

You can look at the gparted tool (or parted on the command line). It is run under sudo since there is potential to run your system, so be careful. Its fairly good in protecting you form yourself! Basically you need to re-format the ext4 partition to something OS X can recognise. This will destroy any data on this existing partition, so you will have to tread carefully.

Is all ouf your SD used do you know? If not, you could create a partition of the OS X friendly type. Put the SD card in your Mac to verify it can be read. You could create an audio folder on your new partition and copy your files into it. Then put if back in the Pi, login and make sure that you can mount the new partition by adding to the existing /etc/fstab file and then access its data. One can then muck about to make it all a little saner in terms of SD usage but you at least know it can be made to work the way you want!

If all the SD card is used you can still mangle it but it just (even) more convoluted.

Hope I've not confused you!

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 7:11 pm
by tackyattack
DBryant wrote:Thought OS X releases were 10.x?

Look at the content of /etc/fstab on your Pi, it will show you type of filesystem. On one of my system:

Code: Select all

[b]cat /etc/fstab[/b]
proc            /proc           proc    defaults          0       0
/dev/mmcblk0p1  /boot           vfat    defaults          0       2
/dev/mmcblk0p2  /               ext4    defaults,noatime  0       1
So I have ext4 and I daresay yours is the same. So that ext4 is going to be a source of aggravation by the look of it.

You can look at the gparted tool (or parted on the command line). It is run under sudo since there is potential to run your system, so be careful. Its fairly good in protecting you form yourself! Basically you need to re-format the ext4 partition to something OS X can recognise. This will destroy any data on this existing partition, so you will have to tread carefully.

Is all ouf your SD used do you know? If not, you could create a partition of the OS X friendly type. Put the SD card in your Mac to verify it can be read. You could create an audio folder on your new partition and copy your files into it. Then put if back in the Pi, login and make sure that you can mount the new partition by adding to the existing /etc/fstab file and then access its data. One can then muck about to make it all a little saner in terms of SD usage but you at least know it can be made to work the way you want!

If all the SD card is used you can still mangle it but it just (even) more convoluted.

Hope I've not confused you!
Sorry, forgot to put the zero in 10.8.2 ;)

I am very new to this Raspberry pi stuff so I am completely lost in what you said. I've just been following adafruit's tutorials. I don't even have a clue how to make multiple partitions. Would it be best to buy this software? http://www.paragon-software.com/home/extfs-mac/
Would that work with my setup?

Thanks

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 8:04 pm
by DBryant
Nah, where's the fun in that! Of course this depends on your overall aims and requirements, so you may determine licensing some software is the way for you.

Search these forums for any input, if nothing else you will gain some background. For example
http://www.raspberrypi.org/phpBB3/viewt ... ms#p278960 fills in a bit mor einfo for me.

Googling may also help. For example http://forums.macrumors.com/showthread.php?t=1498072 lists some alternatives.

Basically you have an SD card with vfat/fat32 and an ext4 partitions. You've seen that your Mac can read the vfat one so one obvious thing would be to make the second one vfat too. You didn't say whether you were employing the full capaciaty of the card? If you run parted you can list the details, in my case, I sudo parted and run the print command:

Code: Select all

sudo parted
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD SU16G (sd/mmc)
Disk /dev/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  62.9MB  58.7MB  primary  fat16        lba
 2      62.9MB  15.9GB  15.9GB  primary  ext4
and it will show you whether there is a chunk of unformatted space. In my case, the 16Mb card is used entirely (add up the sizes!). Now parted is a tool where you can re-size the partitions, so if it were me, I'd look to shrink #2 to half its size. Then, in the 8Gb of free space now available, create a new #3 partition and format it as fat32. I would then get the Mac and Pi to access that new partition, so as its stands the Mac would be able to read only 2 out of the 3 partitions, while the Pi would see all 3. parted has a help command, and there are numerous tutorials online.

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 8:39 pm
by tackyattack
DBryant wrote:Nah, where's the fun in that! Of course this depends on your overall aims and requirements, so you may determine licensing some software is the way for you.

Search these forums for any input, if nothing else you will gain some background. For example
http://www.raspberrypi.org/phpBB3/viewt ... ms#p278960 fills in a bit mor einfo for me.

Googling may also help. For example http://forums.macrumors.com/showthread.php?t=1498072 lists some alternatives.

Basically you have an SD card with vfat/fat32 and an ext4 partitions. You've seen that your Mac can read the vfat one so one obvious thing would be to make the second one vfat too. You didn't say whether you were employing the full capaciaty of the card? If you run parted you can list the details, in my case, I sudo parted and run the print command:

Code: Select all

sudo parted
GNU Parted 2.3
Using /dev/mmcblk0
Welcome to GNU Parted! Type 'help' to view a list of commands.
(parted) print
Model: SD SU16G (sd/mmc)
Disk /dev/mmcblk0: 15.9GB
Sector size (logical/physical): 512B/512B
Partition Table: msdos

Number  Start   End     Size    Type     File system  Flags
 1      4194kB  62.9MB  58.7MB  primary  fat16        lba
 2      62.9MB  15.9GB  15.9GB  primary  ext4
and it will show you whether there is a chunk of unformatted space. In my case, the 16Mb card is used entirely (add up the sizes!). Now parted is a tool where you can re-size the partitions, so if it were me, I'd look to shrink #2 to half its size. Then, in the 8Gb of free space now available, create a new #3 partition and format it as fat32. I would then get the Mac and Pi to access that new partition, so as its stands the Mac would be able to read only 2 out of the 3 partitions, while the Pi would see all 3. parted has a help command, and there are numerous tutorials online.
So a partition is a size of memory allocated that acts like a hard drive? By creating another partition that is fat32 both the mac an Pi would be able to see it? Would it be basically like having a third SD card formatted as fat32 connected to the Pi? The part I really don't get is how the raspberry pi would be able to 'see' it? Would it be as simple as finding the directory path of this new partition?

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 9:16 pm
by ghans
You might have to "mount" the partition.

Typically , this works like this :

Code: Select all

mkdir /mnt/transfer
mount /dev/mmcblk0p3 /mnt/transfer
cd /mnt/transfer
Now you can use the third partition
(the directory "transfer" on your Pi ) and write files to it.
Mac OS X , Windows and Ubuntu "auto-mount" partitions
(and might do this with this third partition) , but
Raspbian currently does not.

ghans

Re: Grabbing files on SD card to use in python

Posted: Sat Mar 09, 2013 9:31 pm
by tackyattack
ghans wrote:You might have to "mount" the partition.

Typically , this works like this :

Code: Select all

mkdir /mnt/transfer
mount /dev/mmcblk0p3 /mnt/transfer
cd /mnt/transfer
Now you can use the third partition
(the directory "transfer" on your Pi and write files to it.
Mac OS X , Windows and Ubuntu "auto-mount" partitions
(and might do this with this third partition) , but
Raspbian currently does not.

ghans
ghans
I see. I have decided the easiest thing to do is run Ubuntu on my Mac so I can see the invisible partition. So far it works just fine!