I
eventually managed to find some time to continue working to my
Pi-zero camera project. During initial tests I took advantage of
Pi-Zero wireless interface and used “sftp" command in order to
transfer files between Raspberry and desktop computer. A more
suitable way of transferring files using USB, like real digital
cameras, would be of course advisable.
Raspberry
Pi Zero as mass storage
The
Pi Zero USB port is directly
connected to processor, unlike others Raspberrys using
a on-board USB Hub.
This, cheaper, solution means
the Pi Zero can be configured to act as USB host,
like a computer, or as
a “USB gadget”
like all cell-phones and digital cameras do. In
order to activate such “USB gadget”
mode some
specific “dcw2” kernel modules must be enabled, in my specfic
case the needed module is called “g_mass_storage”. I followed
this simple
guide from a Github user.
First I enabled DCW2 USB driverecho "dtoverlay=dwc2" | sudo tee -a /boot/config.txtecho "dwc2" | sudo tee -a /etc/modules
sudo dd if=/dev/zero of=/usb-drive.img bs=1M count=1000sudo mkdosfs -F 32 /usb-drive.imgOnce the Raspberry PI is conncted to a computer the mass storage can be enabledl ike this
sudo modprobe g_mass_storage file=/usb-drive.img stall=0 removable=1and disabled with following modprobe command
sudo modprobe -r g_mass_storage
the same virtual
disk can be availabe to Raspberri PI by mounting it
sudo mkdir /media/usb-drivesudo mount -o loop,rw /usb-drive.img /media/usb-drive/of course the same virtual disk cannot be both available as mass storage drive and mounted on Raspberry at the same time, since it could lead to disk corruption. The camera software will have so to manage the switch between two modes.