1

Please comment if you think I can improve my question (like rephrase, add other tags) . I'm really at a loss at the moment.

There are many online instructions explaining how to make a raspberry pi zero behave like a USB keyboard / mouse / etc.

A few years ago I used my pi as a USB keyboard by just following instructions, that I found on the net everything was working fine.

Example: https://randomnerdtutorials.com/raspberry-pi-zero-usb-keyboard-hid/

I installed a new OS (Raspbian GNU/Linux 11 (bullseye)), which has a more recent kernel (6.1.21+) and all the instructions that I find don't work anymore. Whenever I perform the final command
ls /sys/class/udc > UDC
I get an error message:

ls: write error: Device or resource busy

Summary of what I tried.

  • add "dtoverlay=dwc2" to /boot/config.txt
  • add dwc2 and libcomposite to /etc/modules
  • add modules-load=dwc2,g_ether at the end of /boot/cmdline.txt

I created a script that shall be called after bootup to setup your usb device:

Example version:

#!/bin/bash
cd /sys/kernel/config/usb_gadget/
mkdir -p isticktoit
cd isticktoit
echo 0x1d6b > idVendor # Linux Foundation
echo 0x0104 > idProduct # Multifunction Composite Gadget
echo 0x0100 > bcdDevice # v1.0.0
echo 0x0200 > bcdUSB # USB2
mkdir -p strings/0x409
echo "fedcba9876543210" > strings/0x409/serialnumber
echo "Tobias Girstmair" > strings/0x409/manufacturer
echo "iSticktoit.net USB Device" > strings/0x409/product
mkdir -p configs/c.1/strings/0x409
echo "Config 1: ECM network" > configs/c.1/strings/0x409/configuration
echo 250 > configs/c.1/MaxPower

Add functions here

mkdir -p functions/hid.usb0 echo 1 > functions/hid.usb0/protocol echo 1 > functions/hid.usb0/subclass echo 8 > functions/hid.usb0/report_length echo -ne \x05\x01\x09\x06\xa1\x01\x05\x07\x19\xe0\x29\xe7\x15\x00\x25\x01\x75\x01\x95\x08\x81\x02\x95\x01\x75\x08\x81\x03\x95\x05\x75\x01\x05\x08\x19\x01\x29\x05\x91\x02\x95\x01\x75\x03\x91\x03\x95\x06\x75\x08\x15\x00\x25\x65\x05\x07\x19\x00\x29\x65\x81\x00\xc0 > functions/hid.usb0/report_desc ln -s functions/hid.usb0 configs/c.1/

End functions

ls /sys/class/udc > UDC

If my web searches are correct it seems that some things changed in newer kernels and therefore the old instructions don't work anymore. However I didn't find any article guiding me to a solution.

Does anyone have a raspberry pi zero W with a halfways recent distribution, that can act as a USB keyboard / mouse and have Wifi enabled at the same time?

I don't insist on Raspian.

In fact all that I want is a device, that can simulate mouse movements / clicks and be controlled via Wifi. in fact the major use case is even more simple.

I just want to be able to wake up a laptop, that is in standby mode and that doesn't have a working wake on lan feature. Send a command over Wwifi to the pizero and let it do a keyboard press / mouse click to wake it up would be all I really need.

Rohit Gupta
  • 343
  • 2
  • 4
  • 11
gelonida
  • 121
  • 9

1 Answers1

1

I have a RPi Zero W connected to a RPi Zero 2W in gadet mode for ethernet only through a powered usb hub. I never understood it as a keyboard. The cmdline.txt should also include modules-load=dwc2,g_ether modules-load=dwc2,g_hid. But this is my only configuration on the RPi Zero W, (if that is of any help):

pi@RPi0:~ $ cat /boot/cmdline.txt
console=serial0,115200 console=tty1 root=/dev/mmcblk0p8 rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_ether quiet splash plymouth.ignore-serial-consoles

pi@RPi0:~ $ cat /boot/config.txt | grep -v -E '^$|#' hdmi_ignore_edid=0xa5000080 hdmi_cvt 800 480 60 6 0 0 1 hdmi_group=2 hdmi_mode=87 hdmi_blanking=1 hdmi_drive=2 [cm4] otg_mode=1 [pi4] arm_boost=1 [all] dtoverlay=dwc2,dr_mode=peripheral dtparam=act_led_activelow=off gpu_mem=32

pi@RPi0:~ $ pinfo RPi0 Raspberry Pi Zero W Rev 1.1 32bit Raspbian 11.9 bullseye 6.1.21+ Mem 461M Swap 1,412M Gpu 32M usb0 UP 192.168.9.10 wlan0 UP 192.168.0.10

My display is different and pinfo is my script to display pi info.

$ dmesg | grep -E 'g_hid|g_ether'

[ 0.000000] Kernel command line: coherent_pool=1M 8250.nr_uarts=0 snd_bcm2835.enable_headphones=0 bcm2708_fb.fbwidth=800 bcm2708_fb.fbheight=480 bcm2708_fb.fbswap=1 smsc95xx.macaddr=B8:27:EB:08:6D:9A vc_mem.mem_base=0x1ec00000 vc_mem.mem_size=0x20000000 console=ttyS0,115200 console=tty1 root=/dev/mmcblk0p8 rootfstype=ext4 fsck.repair=yes rootwait modules-load=dwc2,g_ether modules=dwc2,g_hid quiet splash plymouth.ignore-serial-consoles [ 0.000000] Unknown kernel command line parameters "splash modules-load=dwc2,g_ether modules=dwc2,g_hid", will be passed to user space.

[ 2.930752] modules-load=dwc2,g_ether

[ 2.930762] modules=dwc2,g_hid

[ 11.119180] g_ether gadget.0: Ethernet Gadget, version: Memorial Day 2008 [ 11.119211] g_ether gadget.0: g_ether ready [ 11.119383] dwc2 20980000.usb: bound driver g_ether

bstipe
  • 574
  • 4
  • 6