User avatar
DaveBlue
Posts: 14
Joined: Sun Dec 30, 2012 2:11 pm

PyUsb - Reading a file from a USB Stick

Tue Jun 21, 2016 9:13 am

I have a program which repeatedly rolls through a small number of images, each image being an advert for a special event for a Heritage Railway. The images are displayed on a monitor in the Heritage Railway shop, for the purpose of advertising forthcoming special events. Currently, the images reside on the RasPi SD card, which means that when new files are required I have to access the SD card.

I am investigating if I can read the files from a USB memory stick, so that I just have to change the files on the latter. I have finally got PyUsb to work, after I realised that the installation was to Python 2, rather than 3.

My first question is PyUsb the correct route?

Second, any guidance on reading files from a USB memory stick ?

Thanks in advance,

Dave

User avatar
MarkHaysHarris777
Posts: 1820
Joined: Mon Mar 23, 2015 7:39 am
Location: Rochester, MN
Contact: Website

Re: PyUsb - Reading a file from a USB Stick

Tue Jun 21, 2016 9:21 am

DaveBlue wrote: My first question is PyUsb the correct route?
'correct' is not the right question, but using PyUsb should be fine...
DaveBlue wrote: Second, any guidance on reading files from a USB memory stick ?
Reading files from a usb memory stick is no different than reading files from any disk (drive). You have to mount the usb stick somewhere on your filesystem (usually happens automatically these days somewhere like /media/<name> or /mnt/<name>

Once you know where the usb stick is mounted then its simply a matter of pointing your program at the correct directory on the stick, and voila !
marcus
:ugeek:

procount
Posts: 1309
Joined: Thu Jun 27, 2013 12:32 pm
Location: UK

Re: PyUsb - Reading a file from a USB Stick

Tue Jun 21, 2016 9:56 am

Why do you need PyUSB to read from a USB memory stick?
Just mount it in your file system and read the images from the folder where it is mounted.
PINN - NOOBS with the extras... https://www.raspberrypi.org/forums/viewtopic.php?f=63&t=142574

User avatar
DaveBlue
Posts: 14
Joined: Sun Dec 30, 2012 2:11 pm

Re: PyUsb - Reading a file from a USB Stick

Tue Jun 21, 2016 4:17 pm

I thought (dangerous) that the path to the USB stick could not be defined. However, on further investigation I find that this is not the case

reference: [url][/http://www.reuk.co.uk/Mount-USB-Memory- ... rry-Pi.htm]

by adding the following line

@reboot mount -t vfat -o uid=pi,gid=pi /dev/sda1 /media/usb

to the cron tasks file, then the path /media/usb is accessible

Much more straightforward

Thanks,

Dave

Return to “Python”