USB_Host_Shield_2.0/index.html
2021-05-09 20:48:09 +00:00

423 lines
36 KiB
HTML

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<meta name="generator" content="Doxygen 1.8.17"/>
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<title>USB Host Shield 2.0: USB Host Library Rev. 2.0</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/searchdata.js"></script>
<script type="text/javascript" src="search/search.js"></script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
<link href="imageStyle.css" rel="stylesheet" type="text/css"/>
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
<tbody>
<tr style="height: 56px;">
<td id="projectalign" style="padding-left: 0.5em;">
<div id="projectname">USB Host Shield 2.0
</div>
</td>
</tr>
</tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.17 -->
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
var searchBox = new SearchBox("searchBox", "search",false,'Search');
/* @license-end */
</script>
<script type="text/javascript" src="menudata.js"></script>
<script type="text/javascript" src="menu.js"></script>
<script type="text/javascript">
/* @license magnet:?xt=urn:btih:cf05388f2679ee054f2beb29a391d25f4e673ac3&amp;dn=gpl-2.0.txt GPL-v2 */
$(function() {
initMenu('',true,false,'search.php','Search');
$(document).ready(function() { init_search(); });
});
/* @license-end */</script>
<div id="main-nav"></div>
</div><!-- top -->
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
onmouseover="return searchBox.OnSearchSelectShow()"
onmouseout="return searchBox.OnSearchSelectHide()"
onkeydown="return searchBox.OnSearchSelectKey(event)">
</div>
<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0"
name="MSearchResults" id="MSearchResults">
</iframe>
</div>
<div class="PageDoc"><div class="header">
<div class="headertitle">
<div class="title"><a class="el" href="class_u_s_b.html">USB</a> Host Library Rev. 2.0 </div> </div>
</div><!--header-->
<div class="contents">
<div class="textblock"><p>The code is released under the GNU General Public License.</p>
<hr />
<p> <a href="https://github.com/felis/USB_Host_Shield_2.0/actions?query=branch%3Amaster"><object type="image/svg+xml" data="https://github.com/felis/USB_Host_Shield_2.0/workflows/CI/badge.svg" style="pointer-events: none;"></object></a></p>
<h1>Summary</h1>
<p>This is Revision 2.0 of MAX3421E-based <a class="el" href="class_u_s_b.html">USB</a> Host Shield Library for AVR's.</p>
<p>Project main web site is: <a href="https://chome.nerpa.tech/arduino_usb_host_shield_projects/">https://chome.nerpa.tech/arduino_usb_host_shield_projects/</a>.</p>
<p>Some information can also be found at: <a href="http://blog.tkjelectronics.dk/">http://blog.tkjelectronics.dk/</a>.</p>
<p>The shield can be purchased from <a href="http://tkjelectronics.com/">TKJ Electronics</a>: <a href="http://shop.tkjelectronics.dk/product_info.php?products_id=43">http://shop.tkjelectronics.dk/product_info.php?products_id=43</a>.</p>
<p><img src="http://shop.tkjelectronics.dk/images/USB_Host_Shield1.jpg" alt="USB Host Shield" class="inline"/></p>
<p>For more information about the hardware see the <a href="https://chome.nerpa.tech/usb-host-shield-hardware-manual/">Hardware Manual</a>.</p>
<h1>Developed By</h1>
<ul>
<li><b>Oleg Mazurov</b> - <a href="#" onclick="location.href='mai'+'lto:'+'maz'+'ur'+'ov@'+'gm'+'ail'+'.c'+'om'; return false;">mazur<span style="display: none;">.nosp@m.</span>ov@g<span style="display: none;">.nosp@m.</span>mail.<span style="display: none;">.nosp@m.</span>com</a></li>
<li><b>Alexei Glushchenko</b> - <a href="#" onclick="location.href='mai'+'lto:'+'ale'+'x-'+'gl@'+'ma'+'il.'+'ru'; return false;">alex-<span style="display: none;">.nosp@m.</span>gl@m<span style="display: none;">.nosp@m.</span>ail.r<span style="display: none;">.nosp@m.</span>u</a><ul>
<li>Developers of the <a class="el" href="class_u_s_b.html">USB</a> Core, HID, <a class="el" href="class_f_t_d_i.html">FTDI</a>, <a class="el" href="class_a_d_k.html">ADK</a>, <a class="el" href="class_a_c_m.html">ACM</a>, and <a class="el" href="class_p_l2303.html">PL2303</a> libraries</li>
</ul>
</li>
<li><b>Kristian Sloth Lauszus</b> - <a href="#" onclick="location.href='mai'+'lto:'+'lau'+'sz'+'us@'+'gm'+'ail'+'.c'+'om'; return false;">lausz<span style="display: none;">.nosp@m.</span>us@g<span style="display: none;">.nosp@m.</span>mail.<span style="display: none;">.nosp@m.</span>com</a><ul>
<li>Developer of the <a href="#bluetooth-libraries">BTD</a>, <a href="#bthid-library">BTHID</a>, <a href="#spp-library">SPP</a>, <a href="#ps5-library">PS5</a>, <a href="#ps4-library">PS4</a>, <a href="#ps3-library">PS3</a>, <a href="#wii-library">Wii</a>, <a href="#switch-pro-library">Switch Pro</a>, <a href="#xbox-library">Xbox</a>, and <a href="#ps-buzz-library">PSBuzz</a> libraries</li>
</ul>
</li>
<li><b>Andrew Kroll</b> - <a href="#" onclick="location.href='mai'+'lto:'+'xxx'+'aj'+'k@g'+'ma'+'il.'+'co'+'m'; return false;">xxxaj<span style="display: none;">.nosp@m.</span>k@gm<span style="display: none;">.nosp@m.</span>ail.c<span style="display: none;">.nosp@m.</span>om</a><ul>
<li>Major contributor to mass storage code</li>
</ul>
</li>
<li><b>guruthree</b><ul>
<li><a href="#xbox-one-library">Xbox ONE</a> controller support</li>
</ul>
</li>
<li><b>Yuuichi Akagawa</b> - <a href="https://twitter.com/yuuichiakagawa">@YuuichiAkagawa</a><ul>
<li>Developer of the <a href="#midi-library">MIDI</a> library</li>
</ul>
</li>
<li><b>Aran Vink</b> - <a href="#" onclick="location.href='mai'+'lto:'+'ara'+'nv'+'ink'+'@g'+'mai'+'l.'+'com'; return false;">aranv<span style="display: none;">.nosp@m.</span>ink@<span style="display: none;">.nosp@m.</span>gmail<span style="display: none;">.nosp@m.</span>.com</a><ul>
<li>Developer of the <a href="#amBX-library">amBX</a> library</li>
</ul>
</li>
</ul>
<h1>Table of Contents</h1>
<ul>
<li><a href="#how-to-include-the-library">How to include the library</a><ul>
<li><a href="#arduino-library-manager">Arduino Library Manager</a></li>
<li><a href="#manual-installation">Manual installation</a></li>
</ul>
</li>
<li><a href="#how-to-use-the-library">How to use the library</a><ul>
<li><a href="#documentation">Documentation</a></li>
<li><a href="#enable-debugging">Enable debugging</a></li>
<li><a href="#boards">Boards</a></li>
<li><a href="#bluetooth-libraries">Bluetooth libraries</a></li>
<li><a href="#bthid-library">BTHID library</a></li>
<li><a href="#spp-library">SPP library</a></li>
<li><a href="#ps5-library">PS5 Library</a></li>
<li><a href="#ps4-library">PS4 Library</a></li>
<li><a href="#ps3-library">PS3 Library</a></li>
<li><a href="#xbox-libraries">Xbox Libraries</a><ul>
<li><a href="#xbox-library">Xbox library</a></li>
<li><a href="#xbox-360-library">Xbox 360 Library</a></li>
<li><a href="#xbox-one-library">Xbox ONE Library</a></li>
<li><a href="#xbox-one-s-library">Xbox ONE S Library</a></li>
</ul>
</li>
<li><a href="#wii-library">Wii library</a></li>
<li><a href="#switch-pro-library">Switch Pro Library</a></li>
<li><a href="#ps-buzz-library">PS Buzz Library</a></li>
<li><a href="#hid-libraries">HID Libraries</a></li>
<li><a href="#midi-library">MIDI Library</a></li>
<li><a href="#amBX-library">amBX Library</a></li>
</ul>
</li>
<li><a href="#interface-modifications">Interface modifications</a></li>
<li><a href="#faq">FAQ</a></li>
</ul>
<h1>How to include the library</h1>
<h3>Arduino Library Manager</h3>
<p>First install Arduino IDE version 1.6.2 or newer, then simply use the Arduino Library Manager to install the library.</p>
<p>Please see the following page for instructions: <a href="http://www.arduino.cc/en/Guide/Libraries#toc3">http://www.arduino.cc/en/Guide/Libraries#toc3</a>.</p>
<h3>Manual installation</h3>
<p>First download the library by clicking on the following link: <a href="https://github.com/felis/USB_Host_Shield_2.0/archive/master.zip">https://github.com/felis/USB_Host_Shield_2.0/archive/master.zip</a>.</p>
<p>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.</p>
<p>Now open up the Arduino IDE and open "File&gt;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.</p>
<p>The final structure should look like this:</p>
<ul>
<li>Arduino/<ul>
<li>libraries/<ul>
<li>USB_Host_Shield_20/</li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Now quit the Arduino IDE and reopen it.</p>
<p>Now you should be able to go open all the examples codes by navigating to "File&gt;Examples&gt;USB\_Host\_Shield\_20" and then select the example you will like to open.</p>
<p>For more information visit the following sites: <a href="http://arduino.cc/en/Guide/Libraries">http://arduino.cc/en/Guide/Libraries</a> and <a href="https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use">https://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use</a>.</p>
<h1>How to use the library</h1>
<h3>Documentation</h3>
<p>Documentation for the library can be found at the following link: <a href="https://felis.github.io/USB_Host_Shield_2.0/">https://felis.github.io/USB_Host_Shield_2.0/</a>.</p>
<h3>Enable debugging</h3>
<p>By default serial debugging is disabled. To turn it on simply change <code>ENABLE_UHS_DEBUGGING</code> to 1 in <a href="settings.h">settings.h</a> like so:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">#define ENABLE_UHS_DEBUGGING 1</div>
</div><!-- fragment --><h3>Boards</h3>
<p>Currently the following boards are supported by the library:</p>
<ul>
<li>All official Arduino AVR boards (Uno, Duemilanove, Mega, Mega 2560, Mega <a class="el" href="class_a_d_k.html">ADK</a>, Leonardo etc.)</li>
<li>Arduino Due, Intel Galileo, Intel Galileo 2, and Intel Edison<ul>
<li>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 <a href="https://chome.nerpa.tech/usb-host-shield-hardware-manual">hardware manual</a> for more information.</li>
<li>Note native <a class="el" href="class_u_s_b.html">USB</a> host is not supported on any of these platforms. You will have to use the shield for now.</li>
</ul>
</li>
<li>Teensy (Teensy++ 1.0, Teensy 2.0, Teensy++ 2.0, Teensy 3.x, Teensy LC and Teensy 4.x)<ul>
<li>Note if you are using the Teensy 3.x you should download this SPI library as well: <a href="https://github.com/xxxajk/spi4teensy3">https://github.com/xxxajk/spi4teensy3</a>. You should then add <code>#include &lt;spi4teensy3.h&gt;</code> to your .ino file.</li>
</ul>
</li>
<li>Balanduino</li>
<li>Sanguino</li>
<li>Black Widdow</li>
<li>RedBearLab nRF51822</li>
<li>Adafruit Feather nRF52840 Express</li>
<li>Digilent chipKIT<ul>
<li>Please see: <a href="https://chome.nerpa.tech/mcu/usb/running-usb-host-code-on-digilent-chipkit-board">https://chome.nerpa.tech/mcu/usb/running-usb-host-code-on-digilent-chipkit-board</a>.</li>
</ul>
</li>
<li>STM32F4<ul>
<li>Currently the <a href="http://www.st.com/web/catalog/tools/FM116/SC959/SS1532/LN1847/PF262063">NUCLEO-F446RE</a> is supported featuring the STM32F446. Take a look at the following example code: <a href="https://github.com/Lauszus/Nucleo_F446RE_USBHost">https://github.com/Lauszus/Nucleo_F446RE_USBHost</a>.</li>
</ul>
</li>
<li>ESP8266 is supported using the <a href="https://github.com/esp8266/Arduino">ESP8266 Arduino core</a><ul>
<li>Note it uses pin 15 and 5 for SS and INT respectively</li>
<li>Also please be aware that:<ul>
<li>GPIO16 is <b>NOT</b> usable, as it will be used for some other purposes. For example, reset the SoC itself from sleep mode.</li>
<li>GPIO6 to 11 is also <b>NOT</b> usable, as they are used to connect SPI flash chip and it is used for storing the executable binary content.</li>
</ul>
</li>
</ul>
</li>
<li>ESP32 is supported using the <a href="https://github.com/espressif/arduino-esp32/">arduino-esp32</a><ul>
<li>GPIO5 : SS, GPIO17 : INT, GPIO18 : SCK, GPIO19 : MISO, GPIO23 : MOSI</li>
</ul>
</li>
</ul>
<p>The following boards need to be activated manually in <a href="settings.h">settings.h</a>:</p>
<ul>
<li>Arduino Mega <a class="el" href="class_a_d_k.html">ADK</a><ul>
<li>If you are using Arduino 1.5.5 or newer there is no need to activate the Arduino Mega <a class="el" href="class_a_d_k.html">ADK</a> manually</li>
</ul>
</li>
<li>Black Widdow</li>
</ul>
<p>Simply set the corresponding value to 1 instead of 0.</p>
<h3><a href="BTD.cpp">Bluetooth libraries</a></h3>
<p>The <a href="BTD.cpp">BTD library</a> 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 <a class="el" href="class_s_p_p.html">SPP</a> which is a virtual serial port via Bluetooth. Some different examples can be found in the <a href="examples/Bluetooth">example directory</a>.</p>
<p>The <a class="el" href="class_b_t_d.html">BTD</a> library also makes it possible to use multiple services at once, the following example sketch is an example of this: <a href="examples/Bluetooth/PS3SPP/PS3SPP.ino">PS3SPP.ino</a>.</p>
<h3><a href="BTHID.cpp">BTHID library</a></h3>
<p>The <a href="BTHID.cpp">Bluetooth HID library</a> allows you to connect HID devices via Bluetooth to the <a class="el" href="class_u_s_b.html">USB</a> Host Shield.</p>
<p>Currently HID mice and keyboards are supported.</p>
<p>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 <code>setProtocolMode()</code> and then parse <code>HID_RPT_PROTOCOL</code> as an argument. You will then have to modify the parser for your device. See the example: <a href="examples/Bluetooth/BTHID/BTHID.ino">BTHID.ino</a> for more information.</p>
<p>The <a href="#ps4-library">PS4 library</a> also uses this class to handle all Bluetooth communication.</p>
<p>For information see the following blog post: <a href="http://blog.tkjelectronics.dk/2013/12/bluetooth-hid-devices-now-supported-by-the-usb-host-library/">http://blog.tkjelectronics.dk/2013/12/bluetooth-hid-devices-now-supported-by-the-usb-host-library/</a>.</p>
<h3><a href="SPP.cpp">SPP library</a></h3>
<p><a class="el" href="class_s_p_p.html">SPP</a> 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.</p>
<p>Take a look at the <a href="examples/Bluetooth/SPP/SPP.ino">SPP.ino</a> example for more information.</p>
<p>More information can be found at these blog posts:</p>
<ul>
<li><a href="http://chome.nerpa.tech/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released">http://chome.nerpa.tech/mcu/bluetooth-rfcommspp-service-support-for-usb-host-2-0-library-released</a></li>
<li><a href="http://blog.tkjelectronics.dk/2012/07/rfcommspp-library-for-arduino/">http://blog.tkjelectronics.dk/2012/07/rfcommspp-library-for-arduino/</a></li>
</ul>
<p>To implement the <a class="el" href="class_s_p_p.html">SPP</a> protocol I used a Bluetooth sniffing tool called <a href="http://www.tkjelectronics.com/uploads/PacketLogger.zip">PacketLogger</a> developed by Apple. It enables me to see the Bluetooth communication between my Mac and any device.</p>
<h3>PS5 Library</h3>
<p>The PS5 library is split up into the <a href="PS5BT.h">PS5BT</a> and the <a href="PS5USB.h">PS5USB</a> library. These allow you to use the Sony PS5 controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>The <a href="examples/Bluetooth/PS5BT/PS5BT.ino">PS5BT.ino</a> and <a href="examples/PS5USB/PS5USB.ino">PS5USB.ino</a> examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a> 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.</p>
<p>To pair with the PS5 controller via Bluetooth you need create the <a class="el" href="class_p_s5_b_t.html">PS5BT</a> instance like so: <code><a class="el" href="class_p_s5_b_t.html">PS5BT</a> PS5(&amp;Btd, PAIR);</code> 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.</p>
<p>It should then automatically pair the dongle with your controller. This only have to be done once.</p>
<p>Thanks to Joseph Duchesne for the initial <a class="el" href="class_u_s_b.html">USB</a> code.</p>
<p>The driver is based on the official Sony driver for Linux: <a href="https://patchwork.kernel.org/project/linux-input/cover/20201219062336.72568-1-roderick@gaikai.com/">https://patchwork.kernel.org/project/linux-input/cover/20201219062336.72568-1-roderick@gaikai.com/</a>.</p>
<p>Also thanks to Ludwig Füchsl's <a href="https://github.com/Ohjurot/DualSense-Windows">https://github.com/Ohjurot/DualSense-Windows</a> for his work on the haptic triggers.</p>
<h3>PS4 Library</h3>
<p>The PS4 library is split up into the <a href="PS4BT.h">PS4BT</a> and the <a href="PS4USB.h">PS4USB</a> library. These allow you to use the Sony PS4 controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>The <a href="examples/Bluetooth/PS4BT/PS4BT.ino">PS4BT.ino</a> and <a href="examples/PS4USB/PS4USB.ino">PS4USB.ino</a> examples shows how to easily read the buttons, joysticks, touchpad and IMU on the controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a> respectively. It is also possible to control the rumble and light on the controller and get the battery level.</p>
<p>Before you can use the PS4 controller via Bluetooth you will need to pair with it.</p>
<p>Simply create the <a class="el" href="class_p_s4_b_t.html">PS4BT</a> instance like so: <code><a class="el" href="class_p_s4_b_t.html">PS4BT</a> PS4(&amp;Btd, PAIR);</code> 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.</p>
<p>It should then automatically pair the dongle with your controller. This only have to be done once.</p>
<p>For information see the following blog post: <a href="http://blog.tkjelectronics.dk/2014/01/ps4-controller-now-supported-by-the-usb-host-library/">http://blog.tkjelectronics.dk/2014/01/ps4-controller-now-supported-by-the-usb-host-library/</a>.</p>
<p>Also check out this excellent Wiki by Frank Zhao about the PS4 controller: <a href="http://eleccelerator.com/wiki/index.php?title=DualShock_4">http://eleccelerator.com/wiki/index.php?title=DualShock_4</a> and this Linux driver: <a href="https://github.com/chrippa/ds4drv">https://github.com/chrippa/ds4drv</a>.</p>
<p>Several guides on how to use the PS4 library has been written by Dr. James E. Barger and are available at the following link: <a href="https://sites.google.com/view/crosswaystation/ps4-tutorials">https://sites.google.com/view/crosswaystation/ps4-tutorials</a>.</p>
<h3>PS3 Library</h3>
<p>These libraries consist of the <a href="PS3BT.cpp">PS3BT</a> and <a href="PS3USB.cpp">PS3USB</a>. These libraries allows you to use a Dualshock 3, Navigation or a Motion controller with the <a class="el" href="class_u_s_b.html">USB</a> Host Shield both via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>In order to use your Playstation controller via Bluetooth you have to set the Bluetooth address of the dongle internally to your PS3 Controller. This can be achieved by first plugging in the Bluetooth dongle and wait a few seconds. Now plug in the controller via <a class="el" href="class_u_s_b.html">USB</a> and wait until the LEDs start to flash. The library has now written the Bluetooth address of the dongle to the PS3 controller.</p>
<p>Finally simply plug in the Bluetooth dongle again and press PS on the PS3 controller. After a few seconds it should be connected to the dongle and ready to use.</p>
<p><b>Note:</b> You will have to plug in the Bluetooth dongle before connecting the controller, as the library needs to read the address of the dongle. Alternatively you could set it in code like so: <a href="examples/Bluetooth/PS3BT/PS3BT.ino#L20">PS3BT.ino::L20</a>.</p>
<p>For more information about the PS3 protocol see the official wiki: <a href="https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information">https://github.com/felis/USB_Host_Shield_2.0/wiki/PS3-Information</a>.</p>
<p>Also take a look at the blog posts:</p>
<ul>
<li><a href="http://blog.tkjelectronics.dk/2012/01/ps3-controller-bt-library-for-arduino/">http://blog.tkjelectronics.dk/2012/01/ps3-controller-bt-library-for-arduino/</a></li>
<li><a href="http://chome.nerpa.tech/mcu/sony-ps3-controller-support-added-to-usb-host-library">http://chome.nerpa.tech/mcu/sony-ps3-controller-support-added-to-usb-host-library</a></li>
<li><a href="http://chome.nerpa.tech/mcu/arduino/interfacing-ps3-controllers-via-usb">http://chome.nerpa.tech/mcu/arduino/interfacing-ps3-controllers-via-usb</a></li>
</ul>
<p>A special thanks go to the following people:</p>
<ol type="1">
<li><em>Richard Ibbotson</em> who made this excellent guide: <a href="http://chome.nerpa.tech/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part">http://chome.nerpa.tech/mcu/ps3-and-wiimote-game-controllers-on-the-arduino-host-shield-part</a></li>
<li><em>Tomoyuki Tanaka</em> for releasing his code for the Arduino <a class="el" href="class_u_s_b.html">USB</a> Host shield connected to the wiimote: <a href="http://chome.nerpa.tech/mcu/rc-car-controlled-by-wii-remote-on-arduino">http://chome.nerpa.tech/mcu/rc-car-controlled-by-wii-remote-on-arduino</a></li>
</ol>
<p>Also a big thanks all the people behind these sites about the Motion controller:</p>
<ul>
<li><a href="http://thp.io/2010/psmove/">http://thp.io/2010/psmove/</a></li>
<li><a href="http://www.copenhagengamecollective.org/unimove/">http://www.copenhagengamecollective.org/unimove/</a></li>
<li><a href="https://github.com/thp/psmoveapi">https://github.com/thp/psmoveapi</a></li>
<li><a href="http://code.google.com/p/moveonpc/">http://code.google.com/p/moveonpc/</a></li>
</ul>
<h3>Xbox Libraries</h3>
<p>The library supports both the original Xbox controller via <a class="el" href="class_u_s_b.html">USB</a> and the Xbox 360 controller both via <a class="el" href="class_u_s_b.html">USB</a> and wirelessly.</p>
<h4>Xbox library</h4>
<p>The <a href="XBOXOLD.cpp">XBOXOLD</a> class implements support for the original Xbox controller via <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>All the information are from the following sites:</p>
<ul>
<li><a href="https://github.com/torvalds/linux/blob/master/Documentation/input/xpad.txt">https://github.com/torvalds/linux/blob/master/Documentation/input/xpad.txt</a></li>
<li><a href="https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c">https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c</a></li>
<li><a href="http://euc.jp/periphs/xbox-controller.ja.html">http://euc.jp/periphs/xbox-controller.ja.html</a></li>
<li><a href="https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L15">https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL#L15</a></li>
</ul>
<h4>Xbox 360 Library</h4>
<p>The library support one Xbox 360 via <a class="el" href="class_u_s_b.html">USB</a> or up to four Xbox 360 controllers wirelessly by using a <a href="http://blog.tkjelectronics.dk/wp-content/uploads/xbox360-wireless-receiver.jpg">Xbox 360 wireless receiver</a>.</p>
<p>To use it via <a class="el" href="class_u_s_b.html">USB</a> use the <a href="XBOXUSB.cpp">XBOXUSB</a> library or to use it wirelessly use the <a href="XBOXRECV.cpp">XBOXRECV</a> library.</p>
<p><b>Note that a Wireless controller can NOT be used via USB!</b></p>
<p>Examples code can be found in the <a href="examples/Xbox">examples directory</a>.</p>
<p>Also see the following blog posts:</p>
<ul>
<li><a href="http://chome.nerpa.tech/mcu/xbox360-controller-support-added-to-usb-host-shield-2-0-library">http://chome.nerpa.tech/mcu/xbox360-controller-support-added-to-usb-host-shield-2-0-library</a></li>
<li><a href="http://blog.tkjelectronics.dk/2012/07/xbox-360-controller-support-added-to-the-usb-host-library/">http://blog.tkjelectronics.dk/2012/07/xbox-360-controller-support-added-to-the-usb-host-library/</a></li>
<li><a href="http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/">http://blog.tkjelectronics.dk/2012/12/xbox-360-receiver-added-to-the-usb-host-library/</a></li>
</ul>
<p>All the information regarding the Xbox 360 controller protocol are form these sites:</p>
<ul>
<li><a href="http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo">http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/UsbInfo</a></li>
<li><a href="http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo">http://tattiebogle.net/index.php/ProjectRoot/Xbox360Controller/WirelessUsbInfo</a></li>
<li><a href="https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL">https://github.com/Grumbel/xboxdrv/blob/master/PROTOCOL</a></li>
</ul>
<h4>Xbox ONE Library</h4>
<p>A Xbox ONE controller is supported via <a class="el" href="class_u_s_b.html">USB</a> in the <a href="XBOXONE.cpp">XBOXONE</a> class. It is heavily based on the 360 library above. In addition to cross referencing the above, information on the protocol was found at:</p>
<ul>
<li><a href="https://github.com/quantus/xbox-one-controller-protocol">https://github.com/quantus/xbox-one-controller-protocol</a></li>
<li><a href="https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c">https://github.com/torvalds/linux/blob/master/drivers/input/joystick/xpad.c</a></li>
<li><a href="https://github.com/kylelemons/xbox/blob/master/xbox.go">https://github.com/kylelemons/xbox/blob/master/xbox.go</a></li>
</ul>
<h4>Xbox ONE S Library</h4>
<p>A Xbox ONE controller is supported via Bluetooth in the <a href="XBOXONESBT.cpp">XBOXONESBT</a> class.</p>
<p>Special thanks to <a href="https://github.com/HisashiKato">HisashiKato</a> for his help: <a href="https://github.com/felis/USB_Host_Shield_2.0/issues/252#issuecomment-716912362">https://github.com/felis/USB_Host_Shield_2.0/issues/252#issuecomment-716912362</a>.</p>
<h3><a href="Wii.cpp">Wii library</a></h3>
<p>The <a href="Wii.cpp">Wii</a> library support the Wiimote, but also the Nunchuch and Motion Plus extensions via Bluetooth. The Wii U Pro Controller and Wii Balance Board are also supported via Bluetooth.</p>
<p>First you have to pair with the controller, this is done automatically by the library if you create the instance like so:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">WII Wii(&amp;Btd, PAIR);</div>
</div><!-- fragment --><p>And then press 1 &amp; 2 at once on the Wiimote or the SYNC buttons if you are using a Wii U Pro Controller or a Wii Balance Board.</p>
<p>After that you can simply create the instance like so:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">WII Wii(&amp;Btd);</div>
</div><!-- fragment --><p>Then just press any button on the Wiimote and it will then connect to the dongle.</p>
<p>Take a look at the example for more information: <a href="examples/Bluetooth/Wii/Wii.ino">Wii.ino</a>.</p>
<p>Also take a look at the blog post:</p>
<ul>
<li><a href="http://blog.tkjelectronics.dk/2012/08/wiimote-added-to-usb-host-library/">http://blog.tkjelectronics.dk/2012/08/wiimote-added-to-usb-host-library/</a></li>
</ul>
<p>The Wii IR camera can also be used, but you will have to activate the code for it manually as it is quite large. Simply set <code>ENABLE_WII_IR_CAMERA</code> to 1 in <a href="settings.h">settings.h</a>.</p>
<p>The <a href="examples/Bluetooth/WiiIRCamera/WiiIRCamera.ino">WiiIRCamera.ino</a> example shows how it can be used.</p>
<p>All the information about the Wii controllers are from these sites:</p>
<ul>
<li><a href="http://wiibrew.org/wiki/Wiimote">http://wiibrew.org/wiki/Wiimote</a></li>
<li><a href="http://wiibrew.org/wiki/Wiimote/Extension_Controllers">http://wiibrew.org/wiki/Wiimote/Extension_Controllers</a></li>
<li><a href="http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck">http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Nunchuck</a></li>
<li><a href="http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus">http://wiibrew.org/wiki/Wiimote/Extension_Controllers/Wii_Motion_Plus</a></li>
<li><a href="http://wiibrew.org/wiki/Wii_Balance_Board">http://wiibrew.org/wiki/Wii_Balance_Board</a></li>
<li>The old library created by <em>Tomoyuki Tanaka</em>: <a href="https://github.com/moyuchin/WiiRemote_on_Arduino">https://github.com/moyuchin/WiiRemote_on_Arduino</a> also helped a lot.</li>
</ul>
<h3>Switch Pro Library</h3>
<p>The Switch Pro library is split up into the <a href="SwitchProBT.h">SwitchProBT</a> and the <a href="SwitchProUSB.h">SwitchProUSB</a> library. These allow you to use the Nintendo Switch Pro controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>The <a href="examples/Bluetooth/SwitchProBT/SwitchProBT.ino">SwitchProBT.ino</a> and <a href="examples/SwitchProUSB/SwitchProUSB.ino">SwitchProUSB.ino</a> examples shows how to easily read the buttons, joysticks and IMU on the controller via Bluetooth and <a class="el" href="class_u_s_b.html">USB</a> respectively. It is also possible to control the rumble and LEDs on the controller.</p>
<p>To pair with the Switch Pro controller via Bluetooth you need create the <a class="el" href="class_switch_pro_b_t.html">SwitchProBT</a> instance like so: <code><a class="el" href="class_switch_pro_b_t.html">SwitchProBT</a> SwitchPro(&amp;Btd, PAIR);</code> and then press the Sync button next to the <a class="el" href="class_u_s_b.html">USB</a> connector to put the controller into pairing mode.</p>
<p>It should then automatically pair the dongle with your controller. This only have to be done once.</p>
<p>All the information about the controller are from these sites:</p>
<ul>
<li><a href="https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering">https://github.com/dekuNukem/Nintendo_Switch_Reverse_Engineering</a></li>
<li><a href="https://github.com/Dan611/hid-procon">https://github.com/Dan611/hid-procon</a></li>
</ul>
<h3><a href="PSBuzz.cpp">PS Buzz Library</a></h3>
<p>This library implements support for the Playstation Buzz controllers via <a class="el" href="class_u_s_b.html">USB</a>.</p>
<p>It is essentially just a wrapper around the <a href="hiduniversal.cpp">HIDUniversal</a> which takes care of the initializing and reading of the controllers. The <a href="PSBuzz.cpp">PSBuzz</a> class simply inherits this and parses the data, so it is easy for users to read the buttons and turn the big red button on the controllers on and off.</p>
<p>The example <a href="examples/PSBuzz/PSBuzz.ino">PSBuzz.ino</a> shows how one can do this with just a few lines of code.</p>
<p>More information about the controller can be found at the following sites:</p>
<ul>
<li><a href="http://www.developerfusion.com/article/84338/making-usb-c-friendly/">http://www.developerfusion.com/article/84338/making-usb-c-friendly/</a></li>
<li><a href="https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c">https://github.com/torvalds/linux/blob/master/drivers/hid/hid-sony.c</a></li>
</ul>
<h3>HID Libraries</h3>
<p>HID devices are also supported by the library. However these require you to write your own driver. A few example are provided in the <a href="examples/HID">examples/HID</a> directory. Including an example for the <a href="examples/HID/SRWS1/SRWS1.ino">SteelSeries SRW-S1 Steering Wheel</a>.</p>
<h3><a href="usbh_midi.cpp">MIDI Library</a></h3>
<p>The library support MIDI devices. You can convert <a class="el" href="class_u_s_b.html">USB</a> MIDI keyboard to legacy serial MIDI.</p>
<ul>
<li><a href="examples/USBH_MIDI/USB_MIDI_converter/USB_MIDI_converter.ino">USB_MIDI_converter.ino</a></li>
<li><a href="examples/USBH_MIDI/USB_MIDI_converter_multi/USB_MIDI_converter_multi.ino">USB_MIDI_converter_multi.ino</a></li>
</ul>
<p>For more information see : <a href="https://github.com/YuuichiAkagawa/USBH_MIDI">https://github.com/YuuichiAkagawa/USBH_MIDI</a>.</p>
<h3><a href="AMBX.cpp">amBX Library</a></h3>
<p>This library support Philips amBX lights. You can set the colors of the lights individually or all at once. The rumble pad and fans are not supported.</p>
<ul>
<li><a href="examples/ambx/AMBX.ino">AMBX.ino</a></li>
</ul>
<h1>Interface modifications</h1>
<p>The shield is using SPI for communicating with the MAX3421E <a class="el" href="class_u_s_b.html">USB</a> host controller. It uses the SCK, MISO and MOSI pins via the ICSP on your board.</p>
<p>Note this means that it uses pin 13, 12, 11 on an Arduino Uno, so these pins can not be used for anything else than SPI communication!</p>
<p>Furthermore it uses one pin as SS and one INT pin. These are by default located on pin 10 and 9 respectively. They can easily be reconfigured in case you need to use them for something else by cutting the jumper on the shield and then solder a wire from the pad to the new pin.</p>
<p>After that you need modify the following entry in <a href="UsbCore.h">UsbCore.h</a>:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">typedef MAX3421e&lt;P10, P9&gt; MAX3421E;</div>
</div><!-- fragment --><p>For instance if you have rerouted SS to pin 7 it should read:</p>
<div class="fragment"><div class="line"> {C++}</div>
<div class="line">typedef MAX3421e&lt;P7, P9&gt; MAX3421E;</div>
</div><!-- fragment --><p>See the "Interface modifications" section in the <a href="https://chome.nerpa.tech/usb-host-shield-hardware-manual">hardware manual</a> for more information.</p>
<h1>FAQ</h1>
<blockquote class="doxtable">
<p>When I plug my device into the <a class="el" href="class_u_s_b.html">USB</a> connector nothing happens? </p>
</blockquote>
<ul>
<li>Try to connect a external power supply to the Arduino - this solves the problem in most cases.</li>
<li>You can also use a powered hub between the device and the <a class="el" href="class_u_s_b.html">USB</a> Host Shield. You should then include the <a class="el" href="class_u_s_b.html">USB</a> hub library: <code>#include &lt;<a class="el" href="usbhub_8h.html">usbhub.h</a>&gt;</code> and create the instance like so: <code><a class="el" href="class_u_s_b_hub.html">USBHub</a> Hub1(&amp;Usb);</code>.</li>
</ul>
<blockquote class="doxtable">
<p>When I connecting my PS3 controller I get a output like this: </p>
</blockquote>
<div class="fragment"><div class="line">Dualshock 3 Controller Enabled</div>
<div class="line"> </div>
<div class="line">LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0</div>
<div class="line">LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0</div>
<div class="line">LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0</div>
<div class="line">LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0</div>
<div class="line">LeftHatX: 0 LeftHatY: 0 RightHatX: 0 RightHatY: 0</div>
</div><!-- fragment --><ul>
<li>This means that your dongle does not support 2.0+EDR, so you will need another dongle. Please see the following <a href="https://github.com/felis/USB_Host_Shield_2.0/wiki/Bluetooth-dongles">list</a> for tested working dongles.</li>
</ul>
<blockquote class="doxtable">
<p>When compiling I am getting the following error: "fatal error: SPI.h: No such file or directory". </p>
</blockquote>
<ul>
<li>Please make sure to include the SPI library like so: <code>#include &lt;SPI.h&gt;</code> in your .ino file. </li>
</ul>
</div></div><!-- PageDoc -->
</div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.17
</small></address>
</body>
</html>