|
| 1 | +USB HID Host Interface |
| 2 | +====================== |
| 3 | + |
| 4 | + |
| 5 | +.. seo:: |
| 6 | + :description: Instructions for setting up a USB HID Host interface on an ESP32 in ESPHome |
| 7 | + :image: usb.svg |
| 8 | + |
| 9 | +The USB HID Host interface on the ESP32-S2, ESP32-S3 and ESP32-P4 is used to |
| 10 | +connect to USB HID (Human Interface Device) peripheral devices, that is, |
| 11 | +keyboards and mouses. Multiple devices may be configured and connected at once. |
| 12 | +By default, devices must be directly connected to the ESP32, but this can be |
| 13 | +changed by setting the ``enable_hubs`` option to ``true``. |
| 14 | + |
| 15 | +This component only supports **keyboards** today. Key presses, assuming a |
| 16 | +standard US keyboard layout, will be accumulated internally. It is therefore |
| 17 | +most useful in combination with a :doc:`/components/key_collector`, as |
| 18 | +illustrated below. |
| 19 | + |
| 20 | +.. code-block:: yaml |
| 21 | +
|
| 22 | + # Example configuration entry |
| 23 | + usb_host_hid: |
| 24 | + enable_hubs: true |
| 25 | + keyboards: |
| 26 | + - id: kbd_1 |
| 27 | + vid: 0x1725 |
| 28 | + pid: 0x1234 |
| 29 | +
|
| 30 | + key_collector: |
| 31 | + - id: reader_1 |
| 32 | + source_id: kbd_1 |
| 33 | + # Collects whole lines of text, up to <Return>. |
| 34 | + end_keys: "\r" |
| 35 | + timeout: 1s |
| 36 | + # on_result: |
| 37 | + # ... |
| 38 | +
|
| 39 | +.. note:: |
| 40 | + |
| 41 | + This component cannot be used in combination with |
| 42 | + :doc:`/components/usb_host` as both components need to assume control of the |
| 43 | + plugged USB devices, which would create a conflict. |
| 44 | + |
| 45 | +Configuration variables: |
| 46 | +************************ |
| 47 | + |
| 48 | +- **id** (*Optional*, :ref:`config-id`): The id to use for this component. |
| 49 | +- **enable_hubs** (*Optional*, boolean): Whether to include support for hubs. |
| 50 | + Defaults to ``false``. |
| 51 | +- **keyboards** (*Optional*, list): A list of keyboard devices to configure. |
| 52 | + |
| 53 | +Keyboard configuration options: |
| 54 | +******************************* |
| 55 | + |
| 56 | +- **id** (*Optional*, :ref:`config-id`): An id to assign to the device. |
| 57 | +- **check_class**: (*Optional*, boolean): Whether to check the device's HID |
| 58 | + class is indeed “keyboard”. |
| 59 | +- **vid** (**Required**, int): The vendor ID of the device. Use 0 as a wildcard. |
| 60 | +- **pid** (**Required**, int): The product ID of the device. Use 0 as a wildcard. |
| 61 | + |
| 62 | +If a device is configured and a device is connected that matches the |
| 63 | +configuration, the device will be connected to the ESP32 and log entries will |
| 64 | +appear at the DEBUG level. If the log level is set to VERBOSE, then individual |
| 65 | +key presses will be logged. The device will remain connected until it is |
| 66 | +disconnected or the ESP32 is reset. |
| 67 | + |
| 68 | +.. warning:: |
| 69 | + |
| 70 | + If multiple devices are plugged in that match the same wildcard |
| 71 | + configuration, only the first one will be correctly handled. A log entry at |
| 72 | + WARNING level will appear for subsequent conflicting devices. Make sure you |
| 73 | + have one ``keyboards`` configuration declared for each of the devices you |
| 74 | + intend to plug in, and that they do not conflict with each other. |
| 75 | + |
| 76 | +If a device is plugged in that does not match any configured device, it will be |
| 77 | +ignored and a log entry will appear at the DEBUG level. |
| 78 | + |
| 79 | +If a configured device is plugged in that does *not* declare itself as a HID |
| 80 | +keyboard, it will be ignored and a log entry will appear at the WARNING level. |
| 81 | +Some devices may work just fine (they report key presses) with this component, |
| 82 | +but do not declare themselves as keyboards, in which case you can set |
| 83 | +``check_class`` to ``false``. |
| 84 | + |
| 85 | +See Also |
| 86 | +-------- |
| 87 | + |
| 88 | +- :doc:`/components/usb_host_hid` |
| 89 | +- :apiref:`usb_host_hid/usb_hid.h` |
| 90 | +- :ghedit:`Edit` |
0 commit comments