Skip to content

I made an USB plug & play mode with zero-hid #1

Open

Description

@Ciantic

First of all, great work!

If you are interested here is my "plug & play" USB mode:

https://github.com/ciantic/pycamera-mouse

It was relatively easy to make, only gotcha was that using the zero-hid package was not straightforward, if I tried to use the "official" Python package it cratered the framerate from 70 -> 40fps, but I found out I can just write to the HID device like this:

mouse_hid_device = open("/dev/hidg1", "wb")

def set_relative_mouse(x, y):
    mouse_hid_device.seek(0)
    buttons = 0x0
    vertical_wheel_delta = 0
    horizontal_wheel_delta = 0
    buf = [
            buttons,
            int(x) & 0xFF,
            int(y) & 0xFF,
            vertical_wheel_delta & 0xFF,
            horizontal_wheel_delta & 0xFF,
        ]

    mouse_hid_device.write(bytes(buf))
    mouse_hid_device.flush()

And it was trivial after that. This didn't affect the framerate.

Activity

  1. stedwick commented on Sep 21, 2025

    @stedwick
    Owner

    @Ciantic Hey Jari, sorry I missed this before. This is really cool! Thanks for doing it. 🐁

    I googled it long ago, and people swore up and down that using the Raspberry Pi as a USB gadget was impossible unless you specifically got the Raspberry Pi Zero hardware.

    A couple of questions. First, how does it work? Again, everyone said it was impossible when I googled it.

    But second, what if I close the lid of my laptop and it goes to sleep? Does that shut off the Raspberry Pi? Seems like that would be inconvenient (just thinking out loud). It takes minutes for the Raspberry Pi to boot up. I've also had multiple Raspberry Pi's brick out when I unplugged them suddenly, unfortunately.

    I do wish there was a way to take my monstrosity -- held together with masking tape and rubber bands -- that needs an Ethernet cable or Wi-Fi connection, and turn it into into a little portable USB gadget.

    Do you have further ideas how this could be done with much smaller and cheaper hardware that boots up in seconds over USB? I chose the Raspberry Pi because it has an infrared camera with a high enough frame rate for my liking.

    OOOOoooooo @Ciantic one more thing, check out this other repository: https://github.com/stedwick/TrackIR-Python

    I've been trying to reverse engineer the NaturalPoint TrackIR hardware. It requires a Windows DLL to run, plus their proprietary libraries in C/C++. I was thinking if I could reverse engineer it, then the TrackIR would essentially be the best hardware.

  2. HRmeteohub commented on Feb 14, 2026

    @HRmeteohub

    First, thank you both, great idea, great work! Thank you!

    I just had a small problem with getting a camera to work, as Python could not access it. So I did: sudo apt install python3-libcamera python3-picamera2 This installed some 156MB of packages and now Python sees the camera.

    Finally, could this (HID version) be modified to run on a host machine, using a modified USB camera and some IR LEDs? Most USB cams have LED, and it can be swapped with IR LED.

    Some laptops and computers can be set to keep power on one USB, while the lid is down. Also, I guess we can use a USB-C dongle for powering both the laptop and this device?

  3. stedwick commented on Feb 14, 2026

    @stedwick
    Owner

    Welcome @HRmeteohub 👋 Always fun to see others explore our pet projects!

    tl;dr If you want to use a regular webcam on your laptop, you should really just use: https://smylemouse.com

    I went through all the trouble with the Raspberry Pi specifically because I wanted very high frame rate and very high accuracy with very low latency. The truth is 99% of "normal" webcams are low frame rate and high latency. I haven't found a webcam that comes anywhere near the Raspberry Pi camera in terms of quality and speed.

    But absolutely, yes. The answer to your question is you could indeed run it locally with any camera. (with minor changes like swapping python3-picamera2 for something else)

  4. je-miller commented on Feb 26, 2026

    @je-miller

    I've been trying to reverse engineer the NaturalPoint TrackIR hardware. It requires a Windows DLL to run, plus their proprietary libraries in C/C++. I was thinking if I could reverse engineer it, then the TrackIR would essentially be the best hardware.

    @stedwick How is this going btw? Or does the TrackIR SDK make this unnecessary.

    I’m about to pull the trigger on an IR tracker (or Tobii) for RSI reasons and was curious which one I should go for. You seem to be the SME that’s tried most all of them and you’ve even built a quality one from scratch. I’m looking for max precision and min latency over multiple monitors. It would be great if it works right out of the box so I can get it up a running quickly, but I also know I’ll eventually want full control of the telemetry so can throw Claude at it to handle custom behaviors and use cases.

  5. stedwick commented on Mar 3, 2026

    @stedwick
    Owner

    Hi Jeff! 👋 @je-miller

    I gave up on the TrackIR a year or two ago. With AI these days, I bet Claude or Codex might be able to reverse engineer it better than I was able to. It's on my list to get back to eventually because it would be nice to have such readily available hardware. Just haven't done it yet.

    If you're on Windows, you don't need to reverse-engineer it, though; you can just use the TrackIR SDK. You'd have to build your own app, though. The reason I can't do that is I'm on Mac and Linux.

    Shameless plug: my PhilNav is still the best on Mac/Windows/Linux if you're looking for "max precision and min latency": https://philipb.gumroad.com/l/philnav

  6. stedwick commented on Mar 22, 2026

    @stedwick
    Owner

    @Ciantic @je-miller @HRmeteohub FYI, I have successfully reverse engineered the TrackIR to work on macOS with no proprietary drivers or sdk: https://github.com/stedwick/OpenTrackIR 🐁🖱️🤗

  7. je-miller commented on Mar 23, 2026

    @je-miller

    Sweet! What a coincidence. I just picked up a TrackIR and was dabbling with the SDK and a custom app. So far, I’m not a fan of the SDK, hat clip or needing to have the TrackIR app running. Unless you were already planning on doing it, I might have Claude Code attempt a full port of your MacOS version to Windows.

  8. stedwick commented on Mar 23, 2026

    @stedwick
    Owner

    @je-miller Go for it, man! Just put it into the ./win directory. The C library I wrote should be cross-platform. So C communicates with the TrackIR, and I used SwiftUI on Mac. I assume you'll use WinUI with XAML or whatever in Visual Studio. Send me a PR if it works 🌱

  9. stedwick commented on Mar 29, 2026

    @stedwick
    Owner
  10. je-miller commented on Apr 4, 2026

    @je-miller

    @stedwick
    Oh yeah, this is way more precise and smoother than my 1st attempt I had working with the TrackIR SDK and the hat clip. Plus, it works across multiple monitors.

    For my second attempt, a couple weeks ago I had Opus one shot a port to Windows and it came up with a C# MVP with the same Zadig workaround and a hideous WinForms UI. Surprisingly the core functionality worked really well. I wasn’t thrilled with the Zadig option, and did some research for alternative options. Your WINDOWS_ZADIG_FREE_INSTALL_PLAN.md indicates you have the exact same ideas in mind. Then I got busy with work and forgot about it. Pushed it here je-miller/OpenTrackIR at windows-port just to keep an archive but have since switched over to your latest version.

    I pushed a couple of new features to my fork that you may be interested in. je-miller/OpenTrackIR at new-features

    • Mouse Override Delay
    • Absolute cursor positioning mode with recenter calibration. WIP, but it already keeps mouse cursor position from drifting so much.

    Let me know if you want to pick this up on another thread.

  11. stedwick commented on Apr 8, 2026

    @stedwick
    Owner

    @je-miller that's great. Yeah, when the mouse override and absolute cursor positioning are in a good spot, I'll merge that into my repo as well. Here's the draft PR: stedwick/OpenTrackIR#1 just let me know when it's ready!

    Let's pick up the conversation over there, and feel free to open more PRs as you add new features in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions