Create a generic HID that receives data

I'd need to develop a HID device which receives commands from a PC or smart phone (a USB host).
From the host side the device should be found via its VID and PID.
So far I found out that there's a keyboard and mouse library but this is not sufficient since I need to send data from the host to the device. Also I do not want the host's OS to recognize the device as mouse or keyboard. I need to setup the device descriptor myself. The R4 has an build-in USB engine and therefore should be able to be configured as such a device.
So, here's my question:
Has someone already realized such a project and if so how?
Thanks

1 Like

Does it need to be a HID? Why not simple serial communication?

I did try some time ago, but got nowhere with it.

It looks like it is possible to do in theory, but the paid employees of Arduino (Identified by the Arduino Team tag on their names) say it is possible but they haven't got round to implementing it yet.

Why have you hijacked some on else's thread?
That is against the rules here.

You might want to look at this How to get the best out of this forum before you proceed any further.

Who hijacked?

It was @kevinss111123334553213

The OP was @xdata

I have flagged the moderators about this.

1 Like

Oops! I am very sorry, I just logged on using my credentials. I did not do something special to 'hijack' something.

I just checked my account: My UN is xdata and my credentials are correct. As well as my icon.

@kevinss111123334553213 was a spammer with no connection to @xdata (who is a legitimate forum member).

Spammers often make vague or innocuous replies on topics, with the intention of coming back a couple days later to edit in a spam link. I suspect that was the reason for @kevinss111123334553213's post that caused the confusion.

@kevinss111123334553213 has been suspended and the post has been deleted so all is well. Please carry on with the efforts of supporting @xdata's project.

@sterretje: I am not surprised, that this is the first answer to my question. But: Yes, It has to be HID. While 'stone age serial' is ok for developers, customers expect a 'professional' and universal solution without sewing with COM ports.

Assuming you have a PC application it can easily pick-up usb vid/pid, usb product and other USB related stuff and based on that determine the serial port. I do not know if it's possible using a smart phone.

For 32U4 based boards I've done the above in Windows powershell as well as with a Linux bash script where I look for the usb_product and open the associated serial port. The approach should work for all boards with native USB.

For boards that don't use native USB it might be trickier; it will also work for an original Uno or Mega but not necessarily for clones as multiple connected device can have the same vid/pid without additional identification.

2 Likes

At one point, I thought I was playing with something like this, but did not find it anywhere...

What I was going to do, and might still, is to create a teensy like
rawhid.

C code for Teensy: USB Raw HID - for building custom USB devices

Which simply allows you to send packets of data back and forth.
The Teensy version is by default setup for 64 byte packets. I have an old pr for those boards whose USB runs in high speed (like T4.x), allow you to send 512 byte packets.

I was also curious about the library:
HID-Project - Arduino Reference
Github is:
NicoHood/HID: Bring enhanced HID functions to your Arduino!

Not sure if this library works on the R4 or not.

Dear KurtE,
I stumbled over that page as well but it seams that it only helps with the R3 which has an extra USB MCU. The beauty of the R4 is its build-in USB capabilities. But in the UNO this is the problem: the USB port is used to flash the chip. So, after installing a HID software, the board can no longer be accessed to flash it because it will no longer be recognized as a UNO by the PC. Anyway, there's a mouse and keyboard sample where this issue is somehow solved. They use their own libraries which give no access to the underlying HID framework. Obviously the developers of those libs want to prevent the user from descriptors and reports and stuff. It appears to me that I have to develop this all by myself and I don't know whether I am willing to go this way since other MCUs offer better support.

I played a little bit with this since then, I think I remember I tried to do it, back then and ran into issues and punted.

The issue I ran into is/was that how I could output the generic (RAW) HID report to the PC, but not how I could receive information back from the PC.

For example, keyboard implementation. With most keyboard implementions, example Teensy: the HID descriptor has informatation in it, that allows the teensy, to request the state of the LEDS from the host:
The descriptor includes things like:

        0x95, 0x05,                     //   Report Count (5),
        0x75, 0x01,                     //   Report Size (1),
        0x05, 0x08,                     //   Usage Page (LEDs),
        0x19, 0x01,                     //   Usage Minimum (1),
        0x29, 0x05,                     //   Usage Maximum (5),
        0x91, 0x02,                     //   Output (Data, Variable, Absolute), ;LED report
        0x95, 0x01,                     //   Report Count (1),
        0x75, 0x03,                     //   Report Size (3),
        0x91, 0x03,                     //   Output (Constant),         ;LED report padding

But I don't see any support for this. For example on the Teensy in the USBHost code, we allow the host code to tell the keyboard to update it's LEDS by sending a control packet:
driver_[0]->sendControlPacket(0x21, 9, 0x200, 0, sizeof(leds_.byte), (void*) &leds_.byte);

Then on the other side, the USB code has to detect this control packet,
and then route it to the keyboard driver, who then updates the LEDS state, such that for example if the keyboard sent a keycode for caps-lock, and the host decides that press means to turn off caps lock, it may then send this message, such that the device then turns off the caps-lock LED. Or maybe displays it on a screen...

But again I am not seeing this capability and glue in this HID library. But maybe I am missing something.

Probably. I am just playing with these boards for the fun of it. And as I mentioned, I punted trying to make this work a while ago. But it would be a good thing if someone actually did fill in the missing pieces. Maybe I will take a look again at some point. But currently pulling my remaining strands of hair out on other things, like trying to understand the Zephyr on the GIGA...

Good luck

Dear KurtE,
Thanks for your support. I realy think a real HID firmware is important: The serial connection is indeed simple but outdated. Also not working with smart phones. And, before someone finds a smart phone-to-serial solution: it is not the way to go, we do not fall back in time. There's a reason why usb was developed and I did a lot of HID devices, it is not this terrible.
BR