Custom Firmware Teaches USB Relay Board New Tricks
HomeHome > News > Custom Firmware Teaches USB Relay Board New Tricks

Custom Firmware Teaches USB Relay Board New Tricks

Dec 14, 2023

If you’re looking for a quick and easy way to control a few devices from your computer, a cheap USB relay board might be the ideal solution. These are fairly simple gadgets, consisting of little more than a microcontroller and a handful of relays. But that doesn't mean there isn't room for improvement, and as [Michał Słomkowski] recently demonstrated, flashing these boards with a custom firmware allows the user to modify their default functionality.

In his case, [Michał] wanted to build a power strip that would cut the power to any devices plugged into it once his computer went to sleep. Unfortunately, he couldn't just check to see if there was 5 V on the line as his motherboard kept the USB ports powered up all the time. But with some modifications to the relay board's firmware, he reasoned he should be able to detect if there was any USB activity by watching for the start-of-frame packet that goes out every millisecond when the bus is active.

Now [Michał] isn't claiming to be the first person to come up with a custom firmware for one of these boards, in fact, he credits an existing open source firmware project as an inspiration for his work. But he did create an entirely new GPLv3 firmware for these ATtiny45 powered devices, which includes among other improvements the latest version of V-USB. As it so happens, V-USB includes start-of-frame packet detection out of the box, which made it much easier to implement his activity detection code.

With the new firmware flashed to the relay board's chip, [Michał] put it in an enclosure and wired up the outlets. But there was still one missing piece of the puzzle. It seems that Linux won't actually send out the start-of-frame packets unless its actively communicating with a USB device, as part of the so-called "selective suspend" power saving feature. Luckily there is support for disabling this feature for specific devices based on their Vendor/Product ID pair, so after a little udev fiddling, everything was working as expected.

We love custom firmware projects here at Hackaday. Not only do they keep proprietary software out of our devices, but they often unlock new and expanded capabilities which otherwise would be hidden behind artificial paywalls.