first progress log

This commit is contained in:
Rudis Muiznieks 2022-03-06 14:18:40 -06:00
parent 2c1aef1343
commit 95e26968f7
Signed by: rudism
GPG Key ID: CABF2F86EF7884F9
2 changed files with 53 additions and 0 deletions

View File

@ -0,0 +1,32 @@
# 2022-03-06 Initial HID Test
Found a _really_ old 16gb SD card and loaded Raspbian up on it, then followed a guide to enable wifi and ssh on it before throwing it in the Pi Zero and plugging it in. After a few minutes I was able to ssh in.
I followed a guide to enable it as a HID device, which involves adding this to `/boot/config.txt`:
```
dtoverlay=dwc2
```
And adding this to `/etc/modules`:
```
dwc2
libcomposite
```
Then I created the `/raspi_config/hid_usb` script that's in this repo at `/usr/bin/hid_usb` and updated `/etc/rc.local` to execute it at boot time.
After a reboot, the Pi showed up as a usb device when running `lsusb` on the computer it's plugged into:
```
Bus 005 Device 008: ID 1d6b:0104 Linux Foundation Multifunction Composite Gadget
```
I created the `/test_scripts/test1.py` script on the Pi and ran it as root, then used a paperclip to alternately connect GPIO 26 and GPIO 16 with ground, and observed it printing characters on the host computer. 26 printed `a` over and over until I broke the connection, and 16 printed `B`. Success!
Looking at the pin-out, there are enough GPIO inputs to support well over 6 or 9 buttons directly hand-wired, so I think that's all I need to do. I guess I'd connect one pin on each keyboard switch to ground (maybe all chained together to the same ground pin?) then the other pin from each to a distinct GPIO pin on the Pi.
To further test this theory I got a second paper clip and awkwardly connected both GPIO 26 and 16 to the same ground pin simultaneously and observed `aBaBaBaB` being output on the host computer. Looking good!
Done messing with the Pi today. Going to mess with OpenSCAD a bit, having just learned about it and worked through a few steps of the introductory tutorial I still have a ways to go before I'll feel comfortable designing the switch plate and case for this thing.

21
test_scripts/test1.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python3
import time
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setup(26, GPIO.IN, pull_up_down=GPIO.PUD_UP)
GPIO.setup(16, GPIO.IN, pull_up_down=GPIO.PUD_UP)
NULL_CHAR = chr(0)
def write_report(report):
with open('/dev/hidg0', 'rb+') as fd:
fd.write(report.encode())
while True:
if not(GPIO.input(26)): # 26 = a
write_report(NULL_CHAR*2+chr(4)+NULL_CHAR*5)
write_report(NULL_CHAR*8)
if not(GPIO.input(16)): # 16 = b
write_report(chr(32)+NULL_CHAR+chr(5)+NULL_CHAR*5)
write_report(NULL_CHAR*8)