Skip to content

Instantly share code, notes, and snippets.

@dglaude
Created September 24, 2022 21:24
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dglaude/e779f4cf3635bd78b08bdeecb8807453 to your computer and use it in GitHub Desktop.
Save dglaude/e779f4cf3635bd78b08bdeecb8807453 to your computer and use it in GitHub Desktop.
USB Host in CircuitPython

STATUS

CircuitPython does not support USB Host yet, but the basis API and partial implementation.

adafruit/circuitpython#6527

The idea is for CircuitPython to rely on TinyUSB, the same way it does for USB Client activities.

Some hardware that run CircuitPython are designed with USB Host in mind such as:

For better understanding of the status of USB Host in CP, please check those two tickets:

But at least they can be used with Arduino until proper support is available.

The most promising hardware that is largely available and low cost is to do it on RP 2040 board such as the Pico from Raspberry Pi:

The discussion on this possibility take place in this issue:

There was an impressive demo using PIO on the RP2040 to support USB Host with minimum additional hardware:

The goal is to integrate that in TinyUSB and be able to use that from CP.

INTEREST

The persone or team most interested with USB Host is Bill Binko founder of ATmakers.

In Assistive Technology, it is frequently needed to create custom device that help communicate with computer, emulating a keyboard or a mouse. But sometimes devices do exist, but talk a legacy USB protocol or need modification. The most flexible way to interface and reuse those device is by creating USB Filter. That is a device with a USB Host interface and a USB Device interface where USB HID can be used. This explain the particular interest in that kind of feature in CircuitPython.

ALTERNATIVE

Some very old assistive device might have a PS2 interface to generate mouse/keyboard input to old computer. It is supported by CircuitPython https://gist.github.com/dglaude/67585e5be7f59e0f080afbe1f8a25ba9

But that solution is not helping to read from USB Device...

Waiting for native USB support, a coprocessor can be used. The Trinket M0 with special software and a USB OTG adaptor is a very low cost and powerfull such coprocessor:

Github user gdsports made a lot of ready to use firmware and demo of the possibilities:

@SunboX
Copy link

SunboX commented Jul 28, 2023

Any news on this?

@dglaude
Copy link
Author

dglaude commented Jul 28, 2023

Maybe watch this https://www.youtube.com/watch?v=lNmwbJ5EH7o NOW
Or check that product: https://www.adafruit.com/product/5723 (that will be supported in CP).

@MrMino
Copy link

MrMino commented Oct 27, 2023

CircuitPython 9.0.0 has usb_host module. Still in prerelease, trying it out now on several RP 2040 boards.

@dglaude
Copy link
Author

dglaude commented Oct 28, 2023

usb_host has been available since a bit of time already and is not even where current work on 9.0 is happening.
The current prefered hardware is still this: https://circuitpython.org/board/adafruit_feather_rp2040_usb_host/
But development was also done on IMX hardware.
Best is to check the support matrix: https://docs.circuitpython.org/en/latest/shared-bindings/support_matrix.html?filter=usb_host

The future is also a USB Host Feather that LadyAda is working on.
It seems to be based on the same microcontroler/hardware that is frequently used in Arduino USB Host project.
The support is needed in TinyUSB for this to be added to CircuirPython, but that work is funded by Adafruit so it is or will be there.

On the practical level, you can already do this in CP:

  • Keyboard workflow, where you can plug a keyboard and type in the REPL (assuming you have a way to see the result like on a build-in screen
  • Reading from Keyboard (if you detach from the REPL)
  • Reading and writing on a USB mass storage
  • Reading USB ID and detect the kind of device connected
  • ... maybe more ... reading mouse? reading MIDI?

So at API level, maybe everything needed is present and there are a few library already available (some that I lightly tested).

I guess that with 9.0 availability, there will be more eyeballs on that feature from CP and more example coming, some nice learn guide, ...

I had one project to turn on and off a Teddy Ruxpin by turning on and off the USB port, but I was blocked by this issue: adafruit/circuitpython#8471

The next step was to modify the Teddy Ruxpin file system to change the bear behaviour based on external information available from the microcontroler (proximity sensor, light sensor, ...).

@MrMino
Copy link

MrMino commented Oct 29, 2023

usb_host has been available since a bit of time already

Right. I was actually looking at support for RP2040 boards and forgot this gist is more general than just those. 8.x doesn't have the support for RP2040 usb_host.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment