I am trying to get my pi zero to act as a HID USB keyboard when plugged in to a computer, following this guide.
I finished the configuration, and I get to the "Keyboard / Mouse / Joystick (HID)" section. I added these commands to the bottom of /etc/rc.local
:
sudo echo -ne "\0\0\x4\0\0\0\0\0" > /dev/hidg0
sudo echo -ne "\0\0\0\0\0\0\0\0" > /dev/hidg0
When I plug the pi zero into the target computer, it recognizes the USB device, as shown by dmesg
:
[26919.807536] usb 1-1: new high-speed USB device number 48 using xhci_hcd
[26919.828689] usb 1-1: New USB device found, idVendor=1d6b, idProduct=0104
[26919.828698] usb 1-1: New USB device strings: Mfr=1, Product=2, SerialNumber=3
[26919.828704] usb 1-1: Product: iSticktoit.net USB Device
[26919.828709] usb 1-1: Manufacturer: Tobias Girstmair
[26919.828713] usb 1-1: SerialNumber: fedcba9876543210
[26919.831132] input: Tobias Girstmair iSticktoit.net USB Device as /devices/pci0000:00/0000:00:15.0/usb1/1-1/1-1:1.0/0003:1D6B:0104.0007/input/input21
[26919.888595] hid-generic 0003:1D6B:0104.0007: input,hidraw1: USB HID v1.01 Keyboard [Tobias Girstmair iSticktoit.net USB Device] on usb-0000:00:15.0-1/input0
But the computer does not receive any keystrokes at all. I am really struggling to figure this out, and I would apreciate any help. Thanks!
/etc/rc.local
has limitations due to Compatibility with SysV. Following the recommendation of the developers from systemd you should avoid using it. Maybe writing to/dev/hidg0
comes to early?