Author Topic: Making a µC act as a HID?  (Read 2903 times)

0 Members and 1 Guest are viewing this topic.

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Making a µC act as a HID?
« on: January 22, 2019, 01:21:05 pm »
Hey all!

So I’m using an esp32 for a project and I need it to act as a simple keyboard. I haven’t been able to find a software implementation for this.
What I want to do is print out a huge value (64bit) as fast as possible and if there is a software implementation like V-USB it’s most likely going to be too slow.

So is there an IC with built in hardware support for USB-HID that I can communicate with over SPI or HS-I2C and send keyboard strokes to a PC.
I did some searching and found FTDI's FT260 but I’m not sure it’s doing the same thing I want it to do. I also made a version that sends the data to an ATMega32u4 that acts as a keyboard. But it’s not as fast as id hope...

The reason for this project is to "check in/out" at work using your fingerprint. The biggest problem with this project is the fact that the current system that this is going to replace is not designed to be enhanced. The sequence goes as following.

RFID tag sends a 64bit integer to a pc
PC checks two text files stored on a local server
Searches the text file with the RFID number
Compares it to the employee ID text file
When it matches it then writes time and employee id to a file on the local server


Se the attached image for a visual representation.

This system has been in place since 2012, as of now nobody is allowed to rewrite the code for the server side or for the pc checking side. So the only way I can make this happen is by emulating a keyboard just like the RFID tag reader.
 

Offline nsrmagazin

  • Regular Contributor
  • *
  • !
  • Posts: 156
  • Country: ru
Re: Making a µC act as a HID?
« Reply #1 on: January 22, 2019, 02:02:43 pm »
A keyboard from a USB port should be more than enough at terms of speed, especially if its a USB 3.0 port.

I don't get the need for the MCU, unless it acts as the PC? If its only for converting the output from the PC to the ESP32, this will help you:

https://diolan.com/usb-spi-adapters

I you want to build a keyboard by yourself instead of using a ready one this makes more sence?

Maybe this will help you.
https://www.adafruit.com/product/2264
« Last Edit: January 22, 2019, 02:06:10 pm by nsrmagazin »
Hi all!
If you like the post, please press "thanks".
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Making a µC act as a HID?
« Reply #2 on: January 22, 2019, 02:11:12 pm »
I did some searching and found FTDI's FT260 but I’m not sure it’s doing the same thing I want it to do. I also made a version that sends the data to an ATMega32u4 that acts as a keyboard. But it’s not as fast as id hope...
Even if you encode the bytes in hex and add a CR (making the 64 bit number 17 bytes long), that's only ~1.2 ms at 115200 baud. A single hard drive access is likely to be 8 ms or longer and so if speeding things up is important, caching the file in a running program hashtable/dictionary and hooking the filesystem to be notified of updates is probably better. IOW, I don't think the USB is your limiting factor on speed. 64 bits isn't huge.

As for keyboard interfaces, I wouldn't roll my own in software on the ESP32, but would use an off-the-shelf chip that presents as HID or write a custom software driver that sends keystrokes on the PC side.
 

Offline Fred27

  • Supporter
  • ****
  • Posts: 726
  • Country: gb
    • Fred's blog
Re: Making a µC act as a HID?
« Reply #3 on: January 22, 2019, 02:13:25 pm »
I've successfully used a MSP430F5529 Launchpad to emulate a keyboard. Fairly easy with example code supplied by TI.
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: Making a µC act as a HID?
« Reply #4 on: January 22, 2019, 02:13:53 pm »
Sorry I must have been unclear.
The esp32 handles the data from the fingerprint reader and in the future I want it to replace the PC completely. At the time of writing this nobody is allowed to rewrite the server side of the code due to prior mad experiences...

Since I can’t touch the code on the server or pc I’m forced to make the esp32 act like the RFID reader (a HID keyboard). The problem is that I have no way of interfacing with the pc as a keyboard when using the esp32.

Is there a USB HID controller that can act as the middle man between the esp32 and the host pc. I’m not able to find such an interface IC...

I only need to build around 5 of these so I don’t really care if the IC is discontinued or so
 

Offline Sudo_apt-get_install_yumTopic starter

  • Regular Contributor
  • *
  • Posts: 161
  • Country: se
Re: Making a µC act as a HID?
« Reply #5 on: January 22, 2019, 02:21:35 pm »
As for keyboard interfaces, I wouldn't roll my own in software on the ESP32, but would use an off-the-shelf chip that presents as HID or write a custom software driver that sends keystrokes on the PC side.
Ok, so maybe it’s not my limiting factor...
Writing my own soft USB is not very high on the priority list which is why I’m looking for an interface IC to handle that for me.
Could you recommend an interface IC, I’ve not been able to find a suitable one.
 

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Making a µC act as a HID?
« Reply #6 on: January 22, 2019, 02:23:17 pm »
You don't say what kind of communications you want between the ESP32 and the HID chip but maybe this will work
https://www.ftdichip.com/Products/ICs/FT260.html

Here is where I first got started with HID and it worked very well:
https://www.pjrc.com/teensy/rawhid.html
 
The following users thanked this post: firehopper

Online rstofer

  • Super Contributor
  • ***
  • Posts: 9890
  • Country: us
Re: Making a µC act as a HID?
« Reply #7 on: January 22, 2019, 02:24:19 pm »
Could you recommend an interface IC, I’ve not been able to find a suitable one.

Totally define 'suitable'!  Chips are all over the place as is code for use in some uCs.
 

Offline Doctorandus_P

  • Super Contributor
  • ***
  • Posts: 3360
  • Country: nl
Re: Making a µC act as a HID?
« Reply #8 on: January 23, 2019, 01:13:09 am »
If you like V-USB, why don't you use V-USB?
1.5Mbit/s is plenty bandwith. and USB is polled every ms (by hardware design).

As others have said before me. I suspect the largest delays are on the server side.
You might be able to pinpoint your delays easily with a logic analyser.
Get some "24MHz 8ch" boxes from Ali / Ebay / China and use them with Sigrok / Pulseview, which is a truly amazing piece of open source software.

Also:
A few days ago I stumbled into a software USB stack for ESP8266 on github.
https://github.com/cnlohr/espusb

Faullt finding in an USB stack is no trivial task. the USB protocol is quite complex.
With the Logic analyser software Sigrok / Pulseview you can capture low-speed USB with EUR7 hardware from Ali / Ebay / China. Almost any board with a Cypress CY7C68013A will work with Sigrok / Pulseview.

Pulseview has a software decoder for USB to give meaning to the binary squiggles on the D+ and D- lines. It decodes T-states, Packets, headers, checksums and much more. It even flags a number of communication errors on the USB wires.
« Last Edit: January 23, 2019, 03:08:05 am by Doctorandus_P »
 

Offline sokoloff

  • Super Contributor
  • ***
  • Posts: 1799
  • Country: us
Re: Making a µC act as a HID?
« Reply #9 on: January 23, 2019, 02:33:36 am »
Side note: human perception is such that 100ms or less is perceived as "instantaneous" is generally anything under 1000ms will not be objected to as a delay by most people.
I don't think you have a speed problem surrounding the data transmission from uC to server.
 

Offline viperidae

  • Frequent Contributor
  • **
  • Posts: 306
  • Country: nz
Re: Making a µC act as a HID?
« Reply #10 on: January 23, 2019, 02:46:32 am »
I wouldn't be worried about a millisecond or so of latency.
Isn't the default polling frequency for USB only 125Hz? That's 8ms between each poll to the HID.
 

Offline Boschi

  • Regular Contributor
  • *
  • Posts: 85
  • Country: it
  • just a arduino-guy
Re: Making a µC act as a HID?
« Reply #11 on: January 23, 2019, 04:13:56 pm »
about an uC with USB support able to interface different protocol and easy to use, there is the arduino leonardo with the atmega32u4. its the same as an arduino uno (as ram and rom).

i know an arduino it almost never looks good as a permanent solution, but this is a temporary solution if i understand correcly.

also, probably you can make the atmega do all the work, even read the fingerprint sensor.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf