Home Creators Posts Import Register Favorites Logout

Content

Are you bored of being limited to the same old input buttons and switches as in every other Arduino project? Wouldn't you rather try letting users have to use a joypad, or trackball, swipe a magnetic card, or read a QR code? If so, this project is for you!

In this tutorial I'll explain how you can add functionality to read input from any USB Human Interface Device (HID). I'll present one detailed example, which is how to read a (1D) barcode or (2D) QR code, and show the decoded output on a display which would be perfect for use in an escape room, but you can adapt the same codebase to interpret report data received from any USB HID peripheral.

My examples make use of the USB Host Library, which you can download from https://github.com/felis/USB_Host_Shield_2.0 (or install from the Arduino IDE Library Manager), and I'll be putting more details up in a patreons'-only post soon. Hope you enjoy, and tell me if you make use of any bonkers USB peripherals in your projects! :)

Files

How to use USB HID Devices as Arduino Inputs - Keyboards, Mice, Magstripe/Barcode readers, and more!

In this video, I'll describe how to use an Arduino (or ESP8266 / ESP32 / other microprocessor) as a USB Host, allowing you to use any USB HID device such as a keyboard, mouse, trackball, joystick, gamepad, barcode scanner, or magstripe reader as an input. This provides many opportunities for novel input mechanisms beyond the typical switches and pushputtons associated with Arduino projects, and I'll demonstrate one such example - using a barcode scanner as a "decoder" that displays messages encoded in QR codes or barcodes found in an escape room :) To customise this project for other devices, you need to define the appropriate logic in the report parser function that processes input from the device, based on the USB HID standard published here: https://usb.org/sites/default/files/hut1_21.pdf Timings 00:00:00 - 00:00:38 Introduction and Demonstration 00:00:39 - 00:02:10 USB Host Shield 00:02:11 - 00:03:35 Barcode scanner 00:03:36 - 00:08:03 Data and Power Interface 00:08:04 - 00:28:52 Arduino Code 00:28:53 - 00:31:46 Wrapup To download the resources used in this project (as well as all the other escape room tutorials in this channel), please check out my patreon at https://www.patreon.com/playfultech

Comments

Michael

really cool, can you also provide the magnetic card reader script with the floating display text?

Alastair Aitchison

Hi! Yes, the download includes code for all the demos I showed - the keyboard, joypad, and magstripe reader, as well as the barcode scanner.

RC

Question, can you show the wiring diagram for the 2.0 ADK Mini USB Host Shield SLR Development Tool you showed. Is this compatable with a ESP32-S3

Soporte Conacctel

Hi Alastair! How can I achieve the code that appears in the video for barcode scanners?

Bingxin Feng

Hi Alastair! I followed your youtube tutorial noted the code in IDE, however when it compiles, there's always an error: "Compilation error: expected initializer before 'Usb' ". Any sugguetion to fix it? Thanks!