百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
U

USB_Host_Shield_2.0

> 编程语言
开源

Arduino USB 主机库 2.0 版本。

1.9K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

Arduino USB 主机库 2.0 版本。

USB Host Library Rev. 2.0

The code is released under the GNU General Public License.


Summary

This is Revision 2.0 of MAX3421E-based USB Host Shield Library for AVR's.

Project main web site is: https://chome.nerpa.tech/arduino_usb_host_shield_projects/.

Some information can also be found at: http://blog.tkjelectronics.dk/.

The shield can be purchased from TKJ Electronics: http://shop.tkjelectronics.dk/product_info.php?products_id=43.

For more information about the hardware see the Hardware Manual.

Developed By

  • Oleg Mazurov - [email protected]
  • Alexei Glushchenko - [email protected]
    • Developers of the USB Core, HID, FTDI, ADK, ACM, and PL2303 libraries
  • Kristian Sloth Lauszus - [email protected]
    • Developer of the BTD, BTHID, SPP, PS5, PS4, PS3, Wii, Switch Pro, Xbox, and PSBuzz libraries
  • Andrew Kroll - [email protected]
    • Major contributor to mass storage code
  • guruthree
    • Xbox ONE controller support
  • Yuuichi Akagawa - @YuuichiAkagawa
    • Developer of the MIDI library
  • Aran Vink - [email protected]
    • Developer of the amBX library

Table of Contents

  • How to include the library
    • Arduino Library Manager
    • Manual installation
  • How to use the library
    • Documentation
    • Enable debugging
    • Boards
    • Bluetooth libraries
    • BTHID library
    • SPP library
    • PS5 Library
    • PS4 Library
    • PS3 Library
    • Xbox Libraries
      • Xbox library
      • Xbox 360 Library
      • Xbox ONE Library
      • Xbox ONE S Library
    • Wii library
    • Switch Pro Library
    • PS Buzz Library
    • HID Libraries
    • MIDI Library
    • amBX Library
  • Interface modifications
  • FAQ

How to include the library

Arduino Library Manager

First install Arduino IDE version 1.6.2 or newer, then simply use the Arduino Library Manager to install the library.

Please see the following page for instructions: http://www.arduino.cc/en/Guide/Libraries#toc3.

Manual installation

First download the library by clicking on the following link: https://github.com/felis/USB_Host_Shield_2.0/archive/master.zip.

Then uncompress the zip folder and rename the directory to "USB_Host_Shield_20", as any special characters are not supported by the Arduino IDE.

Now open up the Arduino IDE and open "File>Preferences". There you will see the location of your sketchbook. Open that directory and create a directory called "libraries" inside that directory. Now move the "USB_Host_Shield_20" directory to the "libraries" directory.

The final structure should look like this:

  • Arduino/
    • libraries/
      • USB_Host_Shield_20/

Now quit the Arduino IDE and reopen it.

Now you should be able to go open all the examples codes by navigating to "File>Examples>USB_Host_Shield_20" and then select the example you will like to open.

For more information visit the following sites: http://arduino.cc/en/Guide/Libraries and https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use.

How to use the library

Documentation

Documentation for the library can be found at the following link: https://felis.github.io/USB_Host_Shield_2.0/.

Enable debugging

By default serial debugging is disabled. To turn it on simply change ENABLE_UHS_DEBUGGING to 1 in settings.h like so:

#define ENABLE_UHS_DEBUGGING 1

Boards

Currently the following boards are supported by the library:

  • All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega ADK, Leonardo etc.)
  • Arduino Due, Intel Galileo, Intel Galileo 2, and Intel Edison
    • Note that the Intel Galileo uses pin 2 and 3 as INT and SS pin respectively by default, so some modifications to the shield are needed. See the "Interface modifications" section in the hardware manual for more information.
    • Note native USB host is not supported on any of these platforms. You will have to use the shield for now.
  • Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, Teensy 3.x, Teensy LC and Teensy 4.x)
    • Note if you are using the Teensy 3.x you should download this SPI library as well: https://github.com/xxxajk/spi4teensy3. You should then add #include <spi4teensy3.h> to your .ino file.
  • Balanduino
  • Sanguino
  • Black Widdow
  • Any board supported by MightyCore
  • RedBearLab nRF51822
  • Adafruit Feather nRF52840 Express
  • SEEED XIAO nRF52840 Sense
    • Note it uses pin 7 and 5 for SS and INT respectively
  • Digilent chipKIT
    • Please see: https://chome.nerpa.tech/mcu/usb/running-usb-host-code-on-digilent-chipkit-board.
  • STM32F4
    • Currently the NUCLEO-F446RE is supported featuring the STM32F446. Take a look at the following example code: https://github.com/Lauszus/Nucleo_F446RE_USBHost.
  • ESP8266 is supported using the ESP8266 Arduino core
    • Note it uses pin 15 and 5 for SS and INT respectively
    • Also please be aware that:
      • GPIO16 is NOT usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode.
      • GPIO6 to 11 is also NOT usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content.
  • ESP32 is supported using the arduino-esp32
    • GPIO5 : SS, GPIO17 : INT, GPIO18 : SCK, GPIO19 : MISO, GPIO23 : MOSI
  • Logic Green LGT8F328p using the LGT8fx

The following boards need to be activated manually in settings.h:

  • Arduino Mega ADK
    • If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega ADK manually
  • Black Widdow

Simply set the corresponding value to 1 instead of 0.

Bluetooth libraries

The BTD library is a general purpose library for an ordinary Bluetooth dongle. This library make it easy to add support for different Bluetooth services like a PS3 or a Wii controller or SPP which is a virtual serial port via Bluetooth. Some different examples can be found in the example directory.

The BTD library also makes it possible to use multiple services at once, the following example sketch is an example of this: PS3SPP.ino.

BTHID library

The Bluetooth HID library allows you to connect HID devices via Bluetooth to the USB Host Shield.

Currently HID mice and keyboards are supported.

It uses the standard Boot protocol by default, but it is also able to use the Report protocol as well. You would simply have to call setProtocolMode() and then parse HID_RPT_PROTOCOL as an argument. You will then have to modify the parser for your device. See the example: BTHID.ino for more information.

The PS4 library also uses this class to handle all Bluetooth communication.

For information see the following blog post: http://blog.tkjelectronics.dk/2013/12/bluetooth-hid-devices-now-supported-by-the-usb-host-library/.

SPP library

SPP stands for "Serial Port Profile" and is a Bluetooth protocol that implements a virtual comport which allows you to send data back and forth from your computer/phone to your Arduino via Bluetooth. It has been tested successfully on Windows, Mac OS X, Linux, and Android.

Take a look at the SPP.ino example for more information.

More information can be found at these blog posts:

  • http://chome.nerpa.tech/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released
  • http://blog.tkjelectronics.dk/2012/07/rfcommspp-library-for-arduino/

To implement the SPP protocol I used a Bluetooth sniffing tool called PacketLogger developed by Apple. It enables me to see the Bluetooth communication between my Mac and any device.

PS5 Library

The PS5 library is split up into the PS5BT and the PS5USB library. These allow you to use the Sony PS5 controller via Bluetooth and USB.

The PS5BT.ino and PS5USB.ino examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and USB respectively. It is also possible to control the rumble, lightbar, microphone LED and player LEDs on the controller. Furthermore the new haptic trigger effects are also supported.

To pair with the PS5 controller via Bluetooth you need create the PS5BT instance like so: PS5BT PS5(&Btd, PAIR); and then hold down the Create button and then hold down the PS without releasing the Create button. The PS5 controller will then start to blink blue indicating that it is in pairing mode.

It should then automatically pair the dongle with your controller. This only have to be done once.

Thanks to Joseph Duchesne for the initial USB code.

The driver is based on the official Sony driver for Linux: https://patchwork.kernel.org/project/linux-input/cover/[email protected]/.

Also thanks to Ludwig Füchsl's https://github.com/Ohjurot/DualSense-Windows for his work on the haptic triggers.

PS4 Library

The PS4 library is split up into the PS4BT and the PS4USB library. These allow you to use the Sony PS4 controller via Bluetooth and USB.

The PS4BT.ino and PS4USB.ino examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and USB respectively. It is also possible to control the rumble and light on the controller and get the battery level.

Before you can use the PS4 controller via Bluetooth you will need to pair with it.

Simply create the PS4BT instance like so: PS4BT PS4(&Btd, PAIR); and then hold down the Share button and then hold down the PS without releasing the Share button. The PS4 controller will then start to blink rapidly indicating that it is in pairing mode.

It should then automatically pair the dongle with your controller. This only have to be done once.

For information see the following blog post: http://blog.tkjelectronics.dk/2014/01/ps4-controller-now-supported-by-the-usb-host-library/.

Also check out this excellent Wiki by Frank Zhao about the PS4 controller: http://eleccelerator.com/wiki/index.php?title=DualShock_4 and this Linux driver: https://github.com/chrippa/ds4drv.

Several guides on how to use the PS4 library has been written by Dr. James E. Barger and are available at the following link: https://sites.google.com/view/crosswaystation/ps4-tutorials.

PS3 Library

These libraries consist of the PS3BT and PS3USB. These libraries allows you to use a Dualshock 3, Navigation or a Motion co

Issues· 0 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

C++

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类编程语言
定价开源

> 相关工具

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言