Sunday, April 19, 2026

Creating Drive Lights: Now for Linux and Windows!


Last post, I wrote about creating “Drive Lights” on Linux using GPIO pins on a Raspberry Pi. It was a fun project that used the kernel’s fanotify API to monitor disk activity and flash physical LEDs. But what if you’re on Windows? Or what if you’re using a modern desktop without native GPIO pins?

Today, I’m excited to share a major update to the Drive_Lights project. It’s now cross-platform, supports USB GPIO hardware, and uses modern Python tooling!

What’s New?

1. Windows Support (ReadDirectoryChangesW)

The biggest addition is a full Windows port (mainw.py). While Linux uses fanotify at the kernel level, Windows provides the ReadDirectoryChangesW API. I’ve implemented a recursive monitoring loop that captures file creations, deletions, renames, and modifications across an entire drive or directory.

2. USB GPIO Hardware (MCP2221A)

You no longer need a Raspberry Pi to see your drive lights! By using a simple USB-to-GPIO adapter like the MCP2221A or FT232H, you can add physical LEDs to any Windows or Linux desktop. The project now supports Adafruit Blinka, which allows gpiozero and other libraries to talk to USB GPIO hardware as if it were a native Pi.

3. Modern Dependency Management with uv

I’ve migrated the project to uv. This means you can get up and running with a single command: bash uv sync No more manual pip install or broken virtual environments!

Technical Deep Dive: Fanotify vs. ReadDirectoryChangesW

One of the most interesting parts of this update was comparing how different operating systems handle file events:

  • Linux (fanotify): This is a powerful, low-level kernel feature. It allows us to monitor an entire mount point (like /) and see every single read or write event system-wide. It requires root privileges but is incredibly efficient.
  • Windows (ReadDirectoryChangesW): This API is directory-based. We tell Windows, “Watch this folder and all its children.” While it’s slightly more “high-level” than fanotify, it’s perfect for monitoring a specific drive or project folder.

Hardware Setup

The hardware remains simple. You just need two LEDs (one for Read, one for Write) and two resistors (around 220-330 ohms).

If you’re using a Raspberry Pi, connect them to GPIO 20 and 21. If you’re using the MCP2221A, you can map the pins in the .env file:

READ_LED=20
WRITE_LED=21
 

I’ve included updated Fritzing diagrams (Sketch.fzz) and schematics in the repository to help with the wiring.

Get the Code

The full project, including both the Linux and Windows scripts, is available on the GitHub repository. Check out the README.md for detailed installation instructions and the OVERVIEW.md for a deeper look at the code structure.

Happy monitoring!

No comments:

Post a Comment