• Stars
    star
    122
  • Rank 292,031 (Top 6 %)
  • Language
    C++
  • Created about 6 years ago
  • Updated about 2 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

USB host library 2.0 for Zero/M0/SAMD

USB Host Library SAMD

USB Host Library for Arduino SAMD boards

This library is based on the USB Host Shield Library 2.0 with modifications to work on Arduino and Arduino compatible SAMD boards. Be sure to see the README for details on Bluetooth pairing, etc. because the information is not repeated here.

This library would not be possible without the work of the USB Host Shield Library developers. Thank you!

The example programs should work on Zero, M0, and MKR family on the native USB port in USB host mode. The USB host shield with MAX3421E is not supported by this library.

Early versions of this library required some changes to the SAMD board package. The current version does not, so it works like a regular Arduino library.

Image of MKR Zero connected to Xbox One controller

USB Host Co-Processor

The related USB Host Co-Processor project encapsulates some of the USB host drivers of this project (MIDI and keyboard so far) in an Adafruit Trinket M0. This allows boards without USB hardware or without USB host software support to use USB host mode by connecting via UART to a Trinket M0.

To make using the firmware even easier, the repo includes UF2 binary releases that can be burned into a Trinket M0 by dragging and dropping the UF2 file on the TRINKETBOOT USB drive. It is not necessary to install the Arduino IDE, libraries, or USB serial driver.

Xbox and MKR board example

Components from left to right:

  • USB phone/tablet charger, 5V
  • Arduino MKR Zero (but any MKR board should work)
  • Adafruit CP2104 USB to UART (but any USB 3.3V serial should work)
  • Xbox One controller with batteries

USB OTG to host cable and 2 X USB micro cables are also shown. Search any shopping website for "usb otg to usb host".

The Xbox controller must have working batteries to ensure the controller works when both rumble motors are turned on.

When using a MKR board, in the XBOXONE.ino example program, change "Serial." to "Serial1." to get serial console on the TX/RX pins.

When using USB host mode on MKR boards, the IDE automatic upload does not work. When the IDE says "Uploading", double click on the MKR board reset button.

Be sure the USB serial board uses 3.3V logic levels on Tx and Rx and 5V on the power pin.

CP2104 MKR board
5V VIN
GND GND
RXD 14<-TX (Serial1)
TXD 13->RX (Serial1)

The CP2104 board passes through the USB 5V to the MKR VIN power input pin. The MKR board powers the Xbox controller via its USB port.

Arduino MKR Boards

The Zero and M0 boards have two USB ports. The programming port is used for sketch uploads and serial console. The native USB port with a USB OTG to host cable/adapter is used for the USB device (for example, Xbox controller). When using a MKR board, the native USB port is used for both functions.

The IDE automatic upload does not work on MKR boards when using USB host. The solution is simple. Unplug the USB OTG to host cable/adaper, plug in the MKR board to computer running the IDE as usual. Press the IDE Upload icon. When the IDE status shows "Uploading", double click the MKR board reset button.

Adafruit M0 and M4 Boards

The Adafruit Metro M4 (SAMD51) and Trinket M0 (SAMD21) work with this library. Follow Adafruit's tutorial to install the Adafruit SAMD board package. Other Arduino compatible (for example Adafruit, SparkFun, etc.) SAMD boards might work.

Image of Metro M4 connected to PS3 controller clone via Bluetooth

Components starting from the Metro M4 board then moving clockwise.

  • Adafruit Metro M4 with USB OTG to host adapter and USB Bluetooth plug
  • USB FTDI serial board for serial console and power
  • USB phone/tablet charger, 5V
  • Playstation 3 controller (clone) with Bluetooth
FTDI Metro M4 board
5V VIN
GND GND
RXD TX-1 (Serial1)
TXD RX-0 (Serial1)

Related projects

Testing

This is unstable and may break at any time. It works for me but may not work you. Use At Your Own Risk. Your Mileage May Vary. Batteries Not Included.

I do not have the hardware to test all the drivers. Also I do not have time to do extensive testing. Hardware I have connected and tested minimally:

  • USB keyboard and mouse
  • Xbox One USB (genuine)
  • Xbox 360 USB (clone)
  • PS3 USB (cheap clone)
  • PS4 USB (genuine)
  • ftdi serial
  • pl2303 serial
  • CDC ACM serial (Uno, Leonardo, Zero, MKR, CircuitPlayground Express)
  • MIDI USB Korg NanoKontrol2
  • Bluetooth SPP, BTHID (BT keyboard), and PS3BT (Playstation 3 controller)
  • ADK ArduinoBlinkLED
  • USB hubs work but not reliable yet
  • Logitech Extreme 3D Pro joystick
  • Thrustmaster T.16000M FCS joystick
  • Dymo M10 postage scale using the scaleEasy example
  • USB ESC POS receipt printer (https://github.com/gdsports/USBPrinter_uhls)

Building the development environment

Early versions of this library required patches to the SAMD board package. The current version does not, so it works like a regular Arduino library.

The following script works for a Linux system. The enviroment uses the Arduino IDE portable feature to insulate this project from the standard Arduino directories. This is no longer needed since it no longer patches the SAMD board package.

The script use the IDE command line interface (CLI) which is documented here.

IDEVER="1.8.7"
# Change to home directory
cd
# Create work directory
mkdir arduino_samd_usb_host
cd arduino_samd_usb_host
WORKDIR=`pwd`
# Install Ardino IDE in work directory
wget -O arduino.tar.xz https://downloads.arduino.cc/arduino-${IDEVER}-linux64.tar.xz
tar xf arduino.tar.xz -C ${WORKDIR}
rm arduino.tar.xz
# Create portable sketchbook and library directories
# Using portable prevents these changes from affecting other Arduino projects.
IDEDIR="${WORKDIR}/arduino-${IDEVER}"
LIBDIR="${IDEDIR}/portable/sketchbook/libraries"
mkdir -p "${LIBDIR}"
cd ${IDEDIR}
# Install board package
./arduino --pref "compiler.warning_level=default" --save-prefs
./arduino --install-boards "arduino:samd"
BOARD="arduino:samd:arduino_zero_edbg"
./arduino --board "${BOARD}" --save-prefs
# Install MIDI library for USBH_MIDI examples
./arduino --install-library "MIDI Library"
cd ${LIBDIR}
# Install TinyGPS for pl2303 example
git clone https://github.com/mikalhart/TinyGPS.git
# Install USB host library for SAMD
git clone https://github.com/gdsports/USB_Host_Library_SAMD
cd ${IDEDIR}
./arduino &

More Repositories

1

usbhostcopro

USB Host Co-processor
C++
73
star
2

midiuartusbh

MIDI DIN to MIDI USB Host Converter
C++
59
star
3

NSGadget_Pi

Raspberry Pi impersonates Nintendo Switch controller
Python
51
star
4

ble-usb-devices

Convert USB keyboard, mouse, MIDI to Bluetooth
C++
40
star
5

ESC_POS_Printer

Arduino ESC POS printer library
C++
39
star
6

rpi-usb-host-midi-hub

Raspberry Pi USB host MIDI hub
Shell
36
star
7

esp8266-usb-host-demos

ESP8266 USB host demos
32
star
8

midi-wifi-demos

MIDI WiFi Demos
Arduino
29
star
9

MIDIUARTUSB

DIY MIDI UART DIN USB converter
C++
27
star
10

USBPassThru

Arduino USB pass through demos
C++
26
star
11

NSGadget_Teensy

Nintendo Switch Gamepad using Teensy LC/3/4
C
23
star
12

usb-metamorph

USB Metamorph
C++
21
star
13

usbkbdble

Convert USB keyboard to Bluetooth LE
C++
21
star
14

imu-wifi

Send IMU orientation data over WiFi
C++
20
star
15

DS4Gadget_HID

USB Gadget emulating a PlayStation Dual Shock 4 compatible gamepad
C++
18
star
16

USBHIDKbd2MIDI

DIY MIDI button controller from QWERTY USB keyboard
C++
18
star
17

M5StackUSBExamples

M5Stack USB Host Examples
C++
16
star
18

sidekick

USB Sidekick
C++
15
star
19

print-pics

Print pictures on a USB thermal receipt printer
C
15
star
20

XYmodem

Arduino XYMODEM file transfer protocol
C++
13
star
21

USBPrinter_uhs2

USB Printer driver for USB Host Shield 2.0 Library
C++
12
star
22

xac_joystick_pipico

USB joystick compatible with Xbox Adaptive Controller using Raspberry Pi Pico
C
11
star
23

dspg1

Portable MIDI dsp-G1 Synth
C++
11
star
24

usbmseble

Convert USB mouse to Bluetooth LE
C++
10
star
25

circuitpython_usb_host_midi

CircuitPython USB Host MIDI
Python
10
star
26

usbhostmidix2

USB host MIDI for Two
10
star
27

xac-mouse2joy

Xbox Adaptive Controller Mouse to Joystick Converter
C++
10
star
28

xbox1motor

Control DC motor using an Xbox One controller
C++
10
star
29

p5-js-ws281x

p5.js WS281x RGB LEDs
Arduino
9
star
30

gamepad_tinyusb

USB Gamepad/Joystick example using Adafruit TinyUSB
C++
8
star
31

rfm69-usb-devices

RFM69 USB extender
C++
8
star
32

xac-joystick-splitter

Xbox Adaptive Controller Joystick Splitter
C++
8
star
33

MIDIDump

Display USB MIDI events on M5Stack display
C++
8
star
34

bafx3608

Python example reading dB from BAFX3608 Sound Pressure Level meter
Python
7
star
35

NSGadget_HID

Nintendo Switch Gamepad Gadget
C++
7
star
36

IntelliKeys_uhls

IntelliKeys USB host driver for the SAMD boards
C
6
star
37

cdcarduino_uhs2

USB CDC ACM Arduino board library for use with the USB Host Shield 2.0 library
C++
5
star
38

AXIC

Arduino XInput Converter For Teensy 3.6
C++
4
star
39

xac_joystick_tinyusb

XAC compatible USB joystick using TinyUSB
Python
4
star
40

usbh_midi_samd

USB Host MIDI for Arduino SAMD boards
C++
4
star
41

keyboard-lag

Measure keyboard scan rate
Python
3
star
42

USBPrinter_t36

USB printer driver for Teensy 3.6 USB host library
C++
2
star
43

USBPrinter_uhls

USB Printer driver for USB Host Library for SAMD
C++
2
star
44

IntelliKeys_t36

IntelliKeys USB Arduino library for Teensy 3.6 USB host
Objective-C
2
star
45

Teensy_Typewriter

Teensy Typewriter using a Teensy 3.6 with USB keyboard and USB printer
C++
1
star
46

howsmyssl

Compare Arduino WiFi TLS
C++
1
star
47

miniuntz

Mini Untztrument Demo, Arduino Style
C++
1
star
48

keymouse_t3

Keyboard and Mouse playback
Objective-C
1
star
49

buttons4

Stick-on Four Button USB MIDI Controller
C++
1
star