Making a µC act as a HID? - Page 1
Forum section: electronics / beginners

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: January 22, 2019, 01:21:05 pm
content: 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 pcPC checks two text files stored on a local serverSearches the text file with the RFID numberCompares it to the employee ID text fileWhen it matches it then writes time and employee id to a file on the local serverSe 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.

author: nsrmagazin
author_rank: Regular Contributor
timestamp: January 22, 2019, 02:02:43 pm
content: 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-adaptersI 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

author: sokoloff
author_rank: Super Contributor
timestamp: January 22, 2019, 02:11:12 pm
content: Quote from: Sudo_apt-get_install_yum on January 22, 2019, 01:21:05 pmEven 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.

author: Fred27
author_rank: Unknown
timestamp: January 22, 2019, 02:13:25 pm
content: I've successfully used a MSP430F5529 Launchpad to emulate a keyboard. Fairly easy with example code supplied by TI.

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: January 22, 2019, 02:13:53 pm
content: 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

author: Sudo_apt-get_install_yum
author_rank: Regular Contributor
timestamp: January 22, 2019, 02:21:35 pm
content: Quote from: sokoloff on January 22, 2019, 02:11:12 pmOk, 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.

author: rstofer
author_rank: Super Contributor
timestamp: January 22, 2019, 02:23:17 pm
content: You don't say what kind of communications you want between the ESP32 and the HID chip but maybe this will workhttps://www.ftdichip.com/Products/ICs/FT260.htmlHere is where I first got started with HID and it worked very well:https://www.pjrc.com/teensy/rawhid.html

author: rstofer
author_rank: Super Contributor
timestamp: January 22, 2019, 02:24:19 pm
content: Quote from: Sudo_apt-get_install_yum on January 22, 2019, 02:21:35 pmTotally define 'suitable'! Chips are all over the place as is code for use in some uCs.

author: Doctorandus_P
author_rank: Super Contributor
timestamp: January 23, 2019, 01:13:09 am
content: 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/espusbFaullt 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.

author: sokoloff
author_rank: Super Contributor
timestamp: January 23, 2019, 02:33:36 am
content: 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.

author: viperidae
author_rank: Frequent Contributor
timestamp: January 23, 2019, 02:46:32 am
content: 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.

author: Boschi
author_rank: Regular Contributor
timestamp: January 23, 2019, 04:13:56 pm
content: 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.