-
Hardware
07/06/2020 at 02:00 • 0 commentsNot much here. I just soldered a cable connecting to a push button between 5v and pin 5 and a pull-down resistor to pin 5.
-
USB and software
07/06/2020 at 01:59 • 0 commentsUSB setup:
Disclaimer:
- I'm using Arch Linux but this should probably be portable to most mainstream Linux distros (Debian, Ubuntu, Fedora, etc).
- I am using an external USB hub because it stays docked on my desk and I don't trust my soldering enough to plug the Digispark directly into my computer.
What I tried:
I thought it would be as simple as asking the Digispark keyboard library to type something when the button press was detected.
That didn't end up working out because the Digispark keyboard library doesn't have ( as I discovered later after a lot of wasted time and effort) a wake-up flag which means the Linux kernel never considers it to be a device that can wake up the computer.After that, I tried the DigiCDC library, which can emulate (from what I understand) more low-level USB functionality. I realized that I could just start a serial connection with the SerialUSB.begin() command, and it would (from what I understand) basically act as if a device was just plugged in. This seemed perfect because a device being plugged in seemed exactly like the sort of thing that the kernel would consider waking up the computer for.
After figuring out what wake-up flags were (the capibality of a device to wake up a computer or not) I realized that my USB hub that enabled and it issued a wake-up request when a USB device was plugged in. Perfect! So any time a button was pressed, I issued these commands
SerialUSB.begin(); SerialUSB.delay(6000); SerialUSB.end();
Looking at dmesg with `dmesg -w`, it seemed like the device was being unplugged each time this was happening. After that,
I sent
echo enabled > /sys/bus/usb/devices/1-3/power/wakeup
I had previously figured out that 1-3 was my usb hub by looking at lsusb and seeing
Bus 004 Device 004: ID 05e3:0749 Genesys Logic, Inc. Bus 004 Device 003: ID 0bda:8153 Realtek Semiconductor Corp. RTL8153 Gigabit Ethernet Adapter Bus 004 Device 002: ID 05e3:0626 Genesys Logic, Inc. USB3.1 Hub Bus 004 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 003 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub Bus 001 Device 007: ID 8087:0a2b Intel Corp. Bus 001 Device 006: ID 06cb:0081 Synaptics, Inc. Bus 001 Device 004: ID 04f2:b61e Chicony Electronics Co., Ltd Integrated Camera Bus 001 Device 032: ID 046d:c534 Logitech, Inc. Unifying Receiver Bus 001 Device 038: ID 16d0:087e MCS USB2.1 Hub Bus 001 Device 030: ID 05e3:0610 Genesys Logic, Inc. 4-port hub Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
I figured that MCS USB was my Digispark because that showed up every time the Digispark's SerialUSB was activated. Also, the Logitech reciever was the only other thing plugged into that particular hub so it made sense that they would be devices 30 and 3[1-9]. Then, I had to investigate a bit to find out how to relate the numbers in /sys to these ID's but it worked out by `grep . /sys/bus/usb/devices/*/idProduct`.
I set up a systemd action to do this on each boot,
And it works!!!!!!
.
.
.
Not so easily, I realized after a few hours and my USB hub being unplugged once for unrelated reasons, each time the USB hub is unplugged, these settings reset themselves. Thankfully though, on my adventures across the internet search for what would end up being the wake-up flag, I had learned about udev. Basically, udev is a utility that does stuff when any peripheral is plugged in (read the Arch wiki page for more info). So, I set up a udev command that whenever the usb device '05e3:0610' is plugged in,
ACTION=="add", SUBSYSTEM=="usb", DRIVERS=="usb", ATTRS{idVendor}=="05e3", ATTRS{idProduct}=="0610",
udev sets its wake-up attribute to enabled.
ATTR{power/wakeup}="enabled"
And it works!!!! (As of writing this I haven't rebooted my computer after making this change so I don't know if it will persist yet. In principle this should be pretty robust.)
-
Rationale behind the parts
07/06/2020 at 01:23 • 0 commentsThis will explain the why of things. To see just the final product look at the build instructions.
Digispark:
This was an obvious choice since I had it lying around and am mostly familliar with it's USB functionality (or at least I thought so before I started this project). It is small in size and has a few IO pins in case I need to add more functionality in the future.
Ethernet:
Used it in case I need to add more buttons in the future and because I had some partly broken ethernet cable lying around. Could be replaced with any 2 wire cable.
Pushbutton:
No rationale just a generic push button.