A smart usb drive made from:
- Raspberry Pi Zero 2 W
- Pimoroni InkyPHAT (red & black)
- 128Gb micro SD card
- Flirc Raspberry Pi Zero case (hacked up a bit)
Borrowing from the ethernet and mass storage gadgets described here: https://github.com/thagrol/Guides using libcomposite
you plug it in and it appears as:
- USB Ethernet
- USB Serial port
- USB storage
The display shows:
- Name of the device
- Space on the external storage
- When powered and connected:
- network addresses (wifi & USB)
- any connections (TTY is com port, SSH is via network)
- When disconnected or unpowered (assuming the Pi was shut down cleanly)
- owner details
The display checks device state every 30 seconds, if there are any changes it refreshes.
The owner details can be stored in a file called owner.json
the script folder, but the code also looks for owner.json
on the root of the mass storage.
Icons used are from Font Awesome
When installed in the case standard header pins stick out really far, I ended up soldering the pins upside down so the short pins were pointing up. I found the top of the pins were about level with the hole in the top of the Flirc case and it was pretty tidy. If you already have header pins on your pi you could trim them, or just let the inky phat sit a bit higher. To fit everything on nicely I cut out parts of the case top (see below)
All this is optional, other cases would work just as well, but I really liked the final package.
- You have the inkyPHAT and related software installed and it runs as root (i.e.
sudo ...
) the service will run as root, so it's good to test it - The files for this are placed in
/home/pi/dev
. If you put them somewhere else you'll need to editGadgetPiStartup.service
. The latest version of the Raspberry Pi Imager does not default to using thepi
user, so it's likely you'll have a different location. - You can login to your pi via ssh etc. This doesn't cover headless pi setup.
- You have a basic understanding of doing stuff on a raspberry pi, particularly in headless mode
You'll need the InkyPHAT in the pi to verify all this actually works, also the GadgetPiStartup.py
will probably fail if it's not plugged in.
- Start with a clean install of Raspbian set up as per the above assumptions
- Enable usb gadget mode by editing
/boot/config.txt
at the end, under[all]
add
dtoverlay=dwc2
enable_uart=1
- Install and test the inkyPHAT libraries, their one liner should work
curl https://get.pimoroni.com/inky | bash
- Optional: you can test the install with the included examples
- Reboot the Raspberry Pi
sudo shutdown -r now
- Install git
sudo apt install git
- Clone this repo
md dev;cd dev
# optional
git clone https://github.com/baralong/inky-gadget.git
cd inky-gadget
- If you didn't clone to the
dev
directory:- Edit
GadgetPiStartup.service
so theExecStart
points to the full path ofGadgetPiStartup.py
- Edit
GadgetPiStartup.service
so theExecStart
points to the full path ofusbGadget.sh
- Edit
- Install exfat support needed for the mass storage device
sudo apt-get install exfat-fuse exfat-utils
- Allocate space for the mass storage device (e.g. 32GB)
you can check the available disk space withdf -h
look for the/
mount point
sudo fallocate -l 32GB /usbdisk.img
- Format the image (volume name of
gadget-pi
is used here)
sudo mkfs.exfat -n gadget-pi /usbdisk.img
- Copy the service configuration
sudo cp usbGadget.service /etc/systemd/system/
- Enable the service
sudo systemctl enable usbGadget.service
- Start the service
sudo systemctl start usbGadget.service
- Check for errors.
sudo journalctl --unit=usbGadget.service
- At this point you should be able to plug the Raspberry Pi in and connect via the USB serial port or the USB ethernet port
- Note: you may need to install additional CDC-ECM drivers for the ethernet port to work under windows
- Install extra python libraries used by the service
sudo pip3 install ifcfg Pillow psutil
- Test the script:
sudo python3 GadgetPiStartup.py
You should see the InkyPHAT displaying the details as above. Terminate with<ctrl>-C
- Copy the service configuration
sudo cp GadgetPiStartup.service /etc/systemd/system/
- Enable the service
sudo systemctl enable GadgetPiStartup.service
- Start the service
sudo systemctl start GadgetPiStartup.service
- Check for errors.
sudo journalctl --unit=GadgetPiStartup.service
- Reboot and make sure the services start up correctly
sudo shutdown -r now
These details are stored in a file called owner.json
there's a sample stored in the repo.
{
"name": "Unspecified User",
"email": "fake@fake.com",
"phone": "+61 # #### ####",
"twitter": "@not a real thing"
}
You can edit the file in place, or, make a copy to the root of the mass storage device from a connected computer and use it there.
- If you disconnect power or somehow shut the pi down abruptly it won't redraw the screen to show the owner info. The screen & pi need to be powered for it to change, but if you shut down cleanly it will.
- If you run
sudo reboot
instead ofshutdown -r now
the service doesn't get time to finish redrawing the screen before exiting - You can only really shut down cleanly if you are connected to the pi via ssh or the USB-serial port
- The mass storage device is pretty slow. Possibly a faster SD card would work, but I suspect the bottleneck is USB2 and the layers of software between the USB port and the image.
The main thing I'd like is some way to interact with the Raspberry Pi, other than remoting into it. There's not a lot of room, but these are the options as I see them:
- Buttons! There's some room to the left of the inky screen above the case cover. There are some spare pins though wiring them up could be tricky.
- An accelerometer... it could detect taps and movement/orientation. I2C would probably be best, but, again, wiring it up would be hard
- Dropping files onto the mass storage. No hardware required, but the drive is read only, so it'd need a way to detect changes.
- Including the human interface device gadget mode, but I'm not sure what I'd use it for. If I had buttons and a menu system, it could be used for keyboard macros (probably) or mouse jiggling
The other thing that I'd really like is faster screen refreshes. This would allow some kind of menu system. A bit like the Pimoroni Badger
One other thing would be to have scripts stored on the mass storage, that the pi could execute as required. Unfortunately there are some security issues there and working out when to run them would be challenging.