Smart (USB Drive (RPi02W, InkyPHAT & FlircCase)

(from the in my github repo GitHub - baralong/inky-gadget: Scripts etc for the pi zero with inkyPhat)

# Overview

A smart usb drive made from:

  1. Raspberry Pi Zero 2 W
  2. Pimoroni InkyPHAT (red & black)
  3. 128Gb micro SD card
  4. Flirc Raspberry Pi Zero case (hacked up a bit)

Borrowing from the ethernet and mass storage gadgets described here: GitHub - 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.

Screen shots

on off

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) phat off side view

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 edit GadgetPiStartup.service . The latest version of the Raspberry Pi Imager does not default to using the pi 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 will probably fail if it’s not plugged in.

Basic prerequisites

  1. Start with a clean install of Raspbian set up as per the above assumptions
  2. Enable usb gadget mode by editing /boot/config.txt at the end, under [all] add
  3. Install and test the inkyPHAT libraries, their one liner should work
    curl | bash
  • Optional: you can test the install with the included examples
  1. Reboot the Raspberry Pi
    sudo shutdown -r now
  2. Install git
    sudo apt install git
  3. Clone this repo
    md dev;cd dev # optional
    git clone
    cd inky-gadget
  4. If you didn’t clone to the dev directory:
  5. Edit GadgetPiStartup.service so the ExecStart points to the full path of
  6. Edit GadgetPiStartup.service so the ExecStart points to the full path of

Set up the mass storage backing file and usb gadget

  1. Install exfat support needed for the mass storage device
    sudo apt-get install exfat-fuse exfat-utils
  2. Allocate space for the mass storage device (e.g. 32GB)
    you can check the available disk space with df -h look for the / mount point
    sudo fallocate -l 32GB /usbdisk.img
  3. Format the image (volume name of gadget-pi is used here)
    sudo mkfs.exfat -n gadget-pi /usbdisk.img

Create and run the usbGadget service

  1. Copy the service configuration
    sudo cp usbGadget.service /etc/systemd/system/
  2. Enable the service
    sudo systemctl enable usbGadget.service
  3. Start the service
    systemctl start usbGadget.service
  4. 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

Create and run the GadgetPiStartup service (used for the inky display)

  1. Install extra python libraries used by the service
    sudo pip3 install ifcfg Pillow psutil

  2. Test the script:
    sudo python3
    You should see the InkyPHAT displaying the details as above. Terminate with <ctrl>-C

  3. Copy the service configuration
    sudo cp GadgetPiStartup.service /etc/systemd/system/

  4. Enable the service
    sudo systemctl enable GadgetPiStartup.service

  5. Start the service
    systemctl start GadgetPiStartup.service

  6. Check for errors.
    sudo journalctl --unit=GadgetPiStartup.service

You’re all done!!

  1. Reboot and make sure the services start up correctly
    sudo shutdown -r now

Owner Details

These details are stored in a file called owner.json there’s a sample stored in the repo.

    "name": "Unspecified User",
    "email": "",
    "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.

Known issues

  1. 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.
  2. If you run sudo reboot instead of shutdown -r now the service doesn’t get time to finish redrawing the screen before exiting
  3. You can only really shut down cleanly if you are connected to the pi via ssh or the USB-serial port
  4. 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.

Future changes:

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:

  1. 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.
  2. An accelerometer… it could detect taps and movement/orientation. I2C would probably be best, but, again, wiring it up would be hard
  3. Dropping files onto the mass storage. No hardware required, but the drive is read only, so it’d need a way to detect changes.
  4. 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.

Any tips on adding buttons and/or faster updates on the inky would be appreciated :)