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

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

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
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.

  • 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

  • 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.

  • 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.

  • 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?

  • 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:

  • 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.

  • 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.

Bluetooth Joystick : A wireless joystick with ESP-32 microcontroller and Dual Axis Joystick Module using the Bluetooth connectivity.
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.

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

Sep 28, 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

Jun 30, 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
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

Jul 20, 2022
Map joystick events to mouse/key events
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

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

May 27, 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

May 27, 2022
ESP32S2 Arduino USB host printer, MIDI, and keyboard demos
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+

Sep 15, 2022
Use Atari keyboard as USB keyboard with a Teensy 3.6
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

Dec 3, 2021
Gesture-Detecting-Macro-Keyboard - Glorified Bluetooth macro keyboard with machine learning (TensorFlow Lite for Microcontrollers) running on an ESP32.
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

Sep 4, 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

Sep 25, 2022
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

Sep 21, 2022
IR2USB - IR to USB HID Converter based on ATtiny45/85
 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,

Aug 10, 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
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.

Sep 30, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.
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. 中文版

Sep 20, 2022
A cheap,simple,Ongeki controller Use Keyboard Simulation and Mouse Simulation to controller the ongeki game. Using Pro-micro control.
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

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

Sep 28, 2022
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.
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

Aug 15, 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 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

Feb 4, 2022