No internet connection
  1. Home
  2. Technical Support

PI Zero 2 OTG port no KB/Mouse

By Andrew @pp6000v2
    2023-08-17 18:08:43.846Z2023-08-17 19:08:17.052Zassigned to
    • @cghague

    I'm trying to move to an ultra portable tinypilot setup, currently using a pi4b with a USB HDMI capture adapter, and a USB C-to-A adapter cable to connect my modified USB cable for kb/mouse input to the connected computer. It all works great.

    I snagged a pi zero 2 recently, and a CSI HDMI module. The HDMI capture works fine, tinypilot shows video of the connected computer. But the kb/mouse inputs aren't working. I'm using the same USB cable as my pi4b set up, this time using a micro-to-A adapter. No hub devices being used, just straight from the micro USB port > adapter cable > data-only USB-A cable.

    Aug 17 13:46:29 pizero2 python[8309]: Process ProcessWithResult-21:
    Aug 17 13:46:29 pizero2 python[8309]: Traceback (most recent call last):
    Aug 17 13:46:29 pizero2 python[8309]:   File "/usr/lib/python3.9/multiprocessing/process.py", line 315, in _bootstrap
    Aug 17 13:46:29 pizero2 python[8309]:     self.run()
    Aug 17 13:46:29 pizero2 python[8309]:   File "/opt/tinypilot/app/hid/write.py", line 45, in run
    Aug 17 13:46:29 pizero2 python[8309]:     result.return_value = self._target(*self._args, **self._kwargs)
    Aug 17 13:46:29 pizero2 python[8309]:   File "/opt/tinypilot/app/hid/write.py", line 65, in _write_to_hid_interface_immediately
    Aug 17 13:46:29 pizero2 python[8309]:     hid_handle.write(bytearray(buffer))
    Aug 17 13:46:29 pizero2 python[8309]: BrokenPipeError: [Errno 108] Cannot send after transport endpoint shutdown
    Aug 17 13:46:29 pizero2 python[1661]: 2023-08-17 13:46:29.071 socket_api      ERROR [SENSITIVE] Failed to forward mouse event: Failed to write to HID interface: /dev/hidg1. Is USB cable connected? [/SENSITIVE]
    

    I know the pi zero (original) is pretty resource limited, but the zero 2 is a quad-core 1GHz and far more performant. The micro USB port supports OTG supposedly. I've tried editing /etc/modules to include g_hid, and /boot/config.txt already has dtoverlay=dwc2.

    What else should I be looking at to get the keyboard and mouse inputs to work? I know the USB-A cable is good, it works swapping back to the pi4 tinypilot. The micro-to-A adapter cable isn't any special one... should it be?

    • 5 replies
    1. C

      Hi Andrew, thanks for your question about using TinyPilot on a Pi Zero 2.

      The Raspberry Pi Zero 2 has two USB ports - one for data and one for power. The data port is the one closest to the centre of the board and is the only one that supports USB gadget mode. Can you please check that you’re using the data port to connect to the target computer?

      1. PAndrew @pp6000v2
          2023-08-17 20:50:02.515Z2023-08-17 20:59:02.905Z

          Yes, the proper micro usb port is being used. Oooh, and I should add: the micro-to-A adapter cable does work with other things plugged into it: using it with SDR dongles, they work just fine, so it is not a dead cable.

          1. Thanks for getting back to me! I appreciate it might have seemed like an obvious question, but it’s often a good place to start given the differences between the separate ports on the Raspberry Pi Zero 2 and the single port on the Raspberry Pi 4B.

            The TinyPilot install process configures /boot/config.txt automatically, and the relevant kernel modules are loaded by the app when needed so there’s no need to modify /etc/modules. Keyboard and mouse support should work without any configuration tweaks being needed, so the most likely issue is that the adapter and cable combination isn’t compatible.

            Can you please try testing using a direct microUSB to USB-A data cable and see if that works?

            1. PAndrew @pp6000v2
                2023-08-19 19:24:07.653Z

                Well, wold you look at that. I had to make another cable, but sacrificing one to make a micro-to-A data-only has the mouse input working. Can you proffer any thoughts on why a micro adapter that is known good, and an A-to-A cable that is known good, would not work together?

                And would you have a link to a proper data-only USB cable? Most I find are either switching the data pins to make a toggled charge-only cable, or are wired directly to be charge-only. The homebrew wire works, but I'd fancy one that hasn't been modified.

                1. Thanks for confirming, it’s good to hear that the software side is working correctly. In terms of hardware, it’s difficult to say why the previous combination of USB adapter and cable didn’t work, but one possibility could be that the adapter contains active circuitry that only allows host mode to work in a single direction.

                  Data-only USB cables are used to prevent electrical backfeeding. However, the Raspberry Pi Zero 2 can generally draw enough power directly from the host computer, so unless you’re using an external power supply for some other reason, you shouldn’t need a data-only cable.

                  If you are using an external power supply, then you might be able to use the TinyPilot Power Connector as an alternative to a data-only cable. However, you’d need to swap out the USB-A to USB-C cable for a USB-A to microUSB cable as the product is designed for the Raspberry Pi 4B.