ESP32 software USB host through general IO pins. We can connect up to 4 USB-LS HID (keyboard mouse joystick) devices simultaneously.

Overview

esp32_usb_soft_host

esp32 USB-LS pure software host thru general IO pins. Up to 4 HID devices simultaneously.

board ~$3 :https://www.aliexpress.com/premium/LOLIN32.html or any of https://www.aliexpress.com/premium/ESP32.html

usb connectors(for example): https://www.aliexpress.com/item/1005002027124387.html

//set right esp32 env for me it:

export IDF_PATH=$HOME/esp/esp-idf

source $HOME/esp/esp-idf/export.sh

//connect the board, build & flash

git clone https://github.com/sdima1357/esp32_usb_soft_host

cd esp32_usb_soft_host/usb_test/

make flash monitor

Comments
  • USB Host not working - only getting `Nack`s

    USB Host not working - only getting `Nack`s

    Latest main doesn't seem to work on my ESP32:

    esp32_usb_soft_host/usb_test$ git status
    On branch main
    Your branch is up to date with 'origin/main'.
    
    nothing to commit, working tree clean
    
    esp32_usb_soft_host/usb_test$ idf.py set-target esp32
    ...
    
    esp32_usb_soft_host/usb_test$ idf.py flash monitor
    ...
    <several warnings, see below>
    ...
    Hello world end!
    b=0x4008ba0c
    a=0x3ffafadc
    c=0x3ffafb3c
    setDelay =0x400d4d1c
    0x400d4d1c: setDelay at esp32_usb_soft_host/usb_test/build/../main/usb_host.c:163
    
    pins 16 17 is OK!
    READ_BOTH_PINS = 0000
    READ_BOTH_PINS = 0000
    READ_BOTH_PINS = 0000
    READ_BOTH_PINS = 0000
    cpu freq = 160 MHz
    TIME_MULT = 77 
    D=   0 4800 bits in 1935.000000 uSec 2.480620 MHz  6 ticks in 2.418750 uS
    D= 126 4800 bits in 5651.000000 uSec 0.849407 MHz  6 ticks in 7.063750 uS
    D=  63 4800 bits in 3751.000000 uSec 1.279659 MHz  6 ticks in 4.688750 uS
    D=  31 4800 bits in 2801.000000 uSec 1.713674 MHz  6 ticks in 3.501250 uS
    D=  47 4800 bits in 3271.000000 uSec 1.467441 MHz  6 ticks in 4.088750 uS
    D=  39 4800 bits in 3031.000000 uSec 1.583636 MHz  6 ticks in 3.788750 uS
    D=  43 4800 bits in 3161.000000 uSec 1.518507 MHz  6 ticks in 3.951250 uS
    D=  45 4800 bits in 3210.000000 uSec 1.495327 MHz  6 ticks in 4.012500 uS
    D=  44 4800 bits in 3181.000000 uSec 1.508959 MHz  6 ticks in 3.976250 uS
    D=  44 4800 bits in 3191.000000 uSec 1.504231 MHz  6 ticks in 3.988750 uS
    TRANSMIT_TIME_DELAY = 46 time = 3.988750 error = -0.281250% 
    pins -1 -1 is Errors !
    pins -1 -1 is Errors !
    pins -1 -1 is Errors !
    USB0: Ack = 0 Nack = 0 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
    USB0: Ack = 0 Nack = 44 02 pcurrent->cb_Cmd = 2  state = 3 epCount = 0
    USB0: Ack = 0 Nack = 268 02 pcurrent->cb_Cmd = 1  state = 3 epCount = 0
    USB0: Ack = 0 Nack = 372 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
    USB0: Ack = 0 Nack = 372 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
    USB0: Ack = 0 Nack = 536 02 pcurrent->cb_Cmd = 2  state = 2 epCount = 0
    USB0: Ack = 0 Nack = 760 02 pcurrent->cb_Cmd = 2  state = 2 epCount = 0
    USB0: Ack = 0 Nack = 764 00 pcurrent->cb_Cmd = 0  state = 0 epCount = 0
    

    I tried with a couple different USB devices and none of them worked - kept seeing only Nacks. Any pointers on how to troubleshoot this?


    I did see a lot of warnings, many about unused var, discarding volatile, and packed attribute being ignored:

    [1011/1026] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/usb_test.c.obj
    In file included from ../main/usb_test.c:32:
    ../main/usb_host.h:47:1: warning: 'packed' attribute ignored [-Wattributes]
     } sDevDesc;
     ^
    ../main/usb_host.h:59:1: warning: 'packed' attribute ignored [-Wattributes]
     } sCfgDesc;
     ^
    ...
    ../main/usb_test.c: In function 'kscan0':
    ../main/usb_test.c:67:10: warning: unused variable 'unum' [-Wunused-variable]
          int unum= msg.src / 4;
              ^~~~
    [1016/1026] Building C object esp-idf/main/CMakeFiles/__idf_main.dir/usb_host.c.obj
    In file included from ../main/usb_host.c:22:
    ...
    ../main/usb_host.c:102:7: warning: initialization discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
          {&GPIO.out_w1tc,&GPIO.out_w1ts},
           ^
    ../main/usb_host.c:102:22: warning: initialization discards 'volatile' qualifier from pointer target type [-Wdiscarded-qualifiers]
          {&GPIO.out_w1tc,&GPIO.out_w1ts},
                          ^
    ...
    ../main/usb_host.c: In function 'parseImmed':
    ../main/usb_host.c:342:15: warning: unused variable 'sIntfCount' [-Wunused-variable]
     static int    sIntfCount   = 0;
                   ^~~~~~~~~~
    ../main/usb_host.c:341:15: warning: unused variable 'cfgCount' [-Wunused-variable]
     static int    cfgCount   = 0;
                   ^~~~~~~~
    ...
    

    I tried replacing __packed with __attribute__((packed)) which made those warnings go away, but still to no avail.

    opened by sfraint 9
  • Does it work with USB 2.0 keyboards ?

    Does it work with USB 2.0 keyboards ?

    Hi, I'm building an e-ink typewriter based on Inkplate 6 (just like the picowriter project) and just bought a USB 2.0 keyboard for that. It's a Motospeed CK62 - was the cheapest mecanical 61 keys keyboard I found - and the manual says that it's a "USB Full Speed 2.0, support up to 1000Hz true reporting rate" whatever that means... Do you think it could work with your software implementation ? If so, if I understand, I would just have to buy one of those adapters and plug it into GPIO pins on the board, right ? Thanks, Andréas

    opened by dedesite 4
  • Serial devices (FTDI, CP210X, PL2303, CH340/1 and CDC)

    Serial devices (FTDI, CP210X, PL2303, CH340/1 and CDC)

    @sdima1357 great work :+1:

    Would it be possbile to also support serial devices like

    • FTDI FT23... series
    • Prolific PL2303
    • SiLabs CP210X range
    • CH340G / CH341G
    • CDC Communications, e.g., Arduino Boards using CDC (UNO, Mega, Leonardo etc.)

    similar to https://www.hobbytronics.co.uk/usb-host-serial?

    This would be very useful e.g., for 3D printer applications, where the ESP32 could be used to steer a 3D printer attached over USB.

    opened by probonopd 4
  • Does your board provide +5v?

    Does your board provide +5v?

    its hard to see in the picture but is your board providing a +5v to the USB power pins? all the esp32 boards I can find don't have a 5v pin to supply output, and I tired using an external 5v power supply but nothing seems to happen at all. All the keyboards I have tried don't even try to light up.

    opened by neozeed 3
  • Game pad support?

    Game pad support?

    Hello,

    I am new to circuits and arduino so I am sorry if these are dump/simple questions.

    I am trying to use a esp32 adafruit feather to turn a wired usb gamepad into a wireless one for pc. I have the gamepad to bluetooth part (https://github.com/lemmingDev/ESP32-BLE-Gamepad) but I need to get the usb gamepad to be readable to that code. Would your code work or partly work for that?

    opened by ccc9090 1
  • Invalid USB Packets

    Invalid USB Packets

    Thanks for this development. I have implemented your host using tobozo's arduino wrapper. As noted there, although separately quite plausible, the data for x and y are strangely inconsistent. But perhaps their apparent plausibility is misleading.

    I note and respect your disclaimer re hardware debugging. I also note that I am a hobbyist rather than professional. Notwithstanding this, I'll ask a couple of questions but understand if to answer would be out of scope.

    Having read the pins as you've done with PulseView, USB packets are shown to be invalid. Picture below (I can't attach the .sr file).

    The setup reports "New device detected on USB#0". It also reports bDeviceClass = 0x00 and similar for each of bDeviceSubClass & bDeviceProtocol. I'll put all similar data reported from the setup below.

    The mouse is labelled NextTech, model: XM5245. The main 12 pin chip is labelled: A582: 2147FS524.
    Am I right in understanding that all mice are LS? How can I confirm that this one is? I've done the testing with only slight modifications to tobozo's USB_Test example.

    I'd be grateful for any suggestions as to how to proceed.

    desc.bcdUSB = 0x0110 desc.bDeviceClass = 0x00 desc.bDeviceSubClass = 0x00 desc.bDeviceProtocol = 0x00 desc.bMaxPacketSize0 = 0x08 desc.idVendor = 0x30fa desc.idProduct = 0x0300 desc.bcdDevice = 0x0100 desc.iManufacturer = 0x00 desc.iProduct = 0x01 desc.iSerialNumber = 0x00 desc.bNumConfigurations = 0x01

    202210033 sr

    opened by MoretonBayKiting 0
  • Is ESP32 S2/S3 support realistic?

    Is ESP32 S2/S3 support realistic?

    Hi and million thanks for your awesome library :+1:

    An idea came up while I was playing with an ESP32-C3 and esp32-arduino-lib-builder to produce a package with memory protection disabled, and accidentally built for ESP32 S2/S3 too.

    Although S2/S3 already have builtin USB support, this support is limited to either host or device role, but what if esp32_usb_soft_host is used along with tinyUSB acting as a device?

    I chose to focus on ESP32S2/esp32_usb_soft_host alone, I don't have a broken out ESP32-S3 and tinyUSB considerations can wait.

    Adapting the code was mostly adding || defined CONFIG_IDF_TARGET_ESP32S2 to #if CONFIG_IDF_TARGET_* conditional blocks and assigning pins.

    However checkPins() detection fails, and now the doubt is there :thinking:

    Some thoughts:

    • not sure what value to assign to BLINK_GPIO, tried the builtin led pin, scl pin, random pins and got not change
    • not sure if cpu_ll_enable_cycle_count(); is needed in function usb_process(), enabling/disabling produces no change
    • using the makeOpcodes() from ESP32 works fine, maybe ESP32S2 wants different opcodes

    (In the event the situation is realistic) Possible use cases of an ESP32S2 using esp32_usb_soft_host/tinyUSB and acting both as host+device:

    • Gaming: DIY dongle for joypad/joystick auto fire + programming
    • Security research: HID MITM keylogger, mouselogger, injector, etc
    • ...

    So here's my question:

    Is it a xxx limitation prevents yyy feature situation or is it worth researching further?

    Thanks again for creating this project, it brought hours of fun :heart:

    opened by tobozo 1
  • A bit confused by the example

    A bit confused by the example

    When I plug in a USB keyboard the 3 leds do come on and off briefly, which is a good sign. But curious what this demo is doing, because it does not report any data when keys are pressed.

    opened by seulater 0
  • Is it possible to support USB2.0 fullspeed?

    Is it possible to support USB2.0 fullspeed?

    Thanks to the excellent work first, it works great with legacy mouse and keyboards which have a 8-Bytes endpoint 0, but it fails when connected to a gaming keyboard with 64-Bytes endpoint 0, no device got enumerated. Is it possible to upgrade the fullspeed support? I guess it will fix the problem.

    opened by Huckies 3
Owner
Samsonov Dima
Software Engineer,Senior,Architect. 13 years GE-CT recon, GPGPU application from 2005. Now: CMT-THALES Innovation Hobby: 3d from video, vi3dim
Samsonov Dima
Bluetooth Joystick : A wireless joystick with ESP-32 microcontroller and Dual Axis Joystick Module using the Bluetooth connectivity.

BluetoothJoystick Bluetooth Joystick : A wireless joystick with ESP-32 microcontroller and Dual Axis Joystick Module using the Bluetooth connectivity.

null 9 Feb 24, 2022
Raw HID keyboard forwarder to turn the Pi 400 into a USB keyboard

Raspberry Pi 400 as a USB HID Keyboard Hook your Pi 400 up to your PC somehow, using a USB Type-C cable into the power port. Anker make good ones- I u

Philip Howard 182 Dec 12, 2022
esp32S2 USB HID host example.

Simple usb host HID example Since usb host support is still beta stage and include file is in private_include i copied component to this example. Code

null 16 Oct 10, 2022
The pico can be used to program other devices. Raspberry pi made such an effort. However there is no board yet, that is open-source and can be used with OpenOCD as a general-purpose programmer

pico-probe-programmer The pico can be used to program other devices. Raspberry pi made such an effort. However there is no board yet, that is open-sou

martijn 22 Oct 15, 2022
Map joystick events to mouse/key events

enjoy map joystick events to mouse/key events Recently, I got a DevTerm and enjoy is specially written for this device to map joystick events to mouse

null 1 Nov 19, 2021
This Program Enables And Disables Hyper-V Hypervisor So You Can Use Other Virtualisation Tools Such As (VMware, VirtualBox) Simultaneously.

Hyper-V-Switch This Program Enables And Disables Hyper-V Hypervisor So You Can Use Other Virtualisation Tools Such As (VMware, VirtualBox) Simultaneou

RaynerSec 4 Nov 10, 2022
USB2Sun - USB keyboard/mouse to Sun Converter

USB2Sun While I've found many projects for connecting the Sun serial based keyboards to a modern machine via USB, I've never found anything to connect

Joakim L. Gilje 9 Nov 24, 2022
ESP32S2 Arduino USB host printer, MIDI, and keyboard demos

ESP32 S2 USB Host Jumpstart A collection of experiments and demos using Espressif ESP32 S2 in USB host mode. Most of the sketches have little or no C+

null 31 Jan 4, 2023
Use Atari keyboard as USB keyboard with a Teensy 3.6

Atari Keyboard Convert an Atari 600/800/1200 XL into a USB keyboard. I bricked my Atari mainboard. My goal is to use the keyboard of the Atari on a Ra

Jos Koenis 2 Dec 3, 2021
Gesture-Detecting-Macro-Keyboard - Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32.

Gesture detection tldr; Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32. Main feat

Jakob Krantz 68 Dec 1, 2022
Tiny and portable usb host and device stack for mcu with usb ip

Tiny and portable usb host and device stack for mcu with usb ip

sakumisu 545 Jan 2, 2023
ESP32 S2 USB host with examples.

This new USB host library based is based on changed and hopefully somehow final API from espressif. The idea is to make this library usable with esp-i

null 22 Nov 10, 2022
IR2USB - IR to USB HID Converter based on ATtiny45/85

IR2USB - IR to USB HID Converter based on ATtiny45/85 IR2USB receives signals from an infrared remote control and converts them into keyboard inputs,

Stefan Wagner 15 Dec 21, 2022
Display array is a board that sets 6 ST7735 display with a resolution of 80x160px in a linear array sharing the clock, data, rs, backlight pins together

The display array is a board that sets 6 ST7735 display with a resolution of 80x160px in a linear array sharing the clock, data, rs, backlight pins together, and leaving individual access to the cs lines of each display, This board allows you to display images with a resolution of 480x160px.

Josue Alejandro Gutierrez 70 Dec 19, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.

N.A.G.E.K.I. A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control. 中文版

NanaNana 39 Dec 8, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.

N.A.G.E.K.I. PLEASE CHECK Main Project A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Us

NanaNana 11 Dec 30, 2021
Cross-platform C++ input library supporting gamepads, keyboard, mouse, touch

This project is archived. It's neither maintained nor developed anymore. Gainput Gainput is the awesome C++ input library for your game: handles your

Johannes Kuhlmann 766 Jan 3, 2023
A continuation of FSund's pteron-keyboard project. Feel free to contribute, or use these files to make your own! Kits and PCBs are also available through my facebook page.

pteron-pcb Intro This project is the evolution of the Pteron-Keyboard project, an incredible ergonomic keyboard that was handwired only. I aimed to in

null 17 Oct 11, 2022
ESP32-Skid-Steer - Bruder Catepillar Skid Steer model converted to RC, controlled by an ESP32 with 2 analog joysticks and a receiver that is an ESP32 on the model.

ESP32-Skid-Steer Bruder Catepillar Skid Steer model converted to RC, controlled by an ESP32 with 2 analog joysticks and a receiver that is an ESP32 on

null 6 Oct 27, 2022