Arduino 1.0-compatible USB Host Library released

Fresh update of USB Host Library 2.0 has just been posted to GitHub. The primary purpose of this release is to maintain compatibility with Arduino releases – the USB Host Library is now compiles in 1.0 as well as pre-1.0 versions of Arduino IDE. Enjoy!

Several important changes have been made to the code, some related to 1.0 compatibility and some not. The library examples were all tested and corrected, the information below is intended for developers using the library in their own projects:

  1. PL2302 driver. Arduino 1.0 defines PL symbol internally (thank you, Paul for finding this out!), therefore, I needed to change name of Prolific class driver. The new name is PL2302; I updated library examples to compile correctly, if someone uses this class in their own development, the right way to define an instance of Prolific device is now PL2303 Pl(&Usb, &AsyncOper);
  2. NAK handling. A bug preventing long polls of an endpoint has been fixed. Previously, if bmNakPower member of epInfo structure was left unitialized the transfer to this endpoint would stop after receiving a single NAK. With current version, the endpoint would be polled for up to 5 seconds. This is rarely desirable, so please initialize bmNakPower with USB_NAK_DEFAULT or USB_NAK_MAX_POWER. If a single poll is desired, as is often the case with interrupt endpoints, specify USB_NAK_NOWAIT and if more than maximum number of NAKs (up to 5 seconds) is necessary, specify USB_NAK_NONAK.
  3. Code speed. An unnecessary delay of 20ms has been found (thank you, Alex for discovering this!) and removed from USB::setAddress() member function. As a result, every USB transfer is now 20ms faster. While generally a good thing, it could inadvertently affect data exchanges with slow endpoints. If after upgrading to the current version you start seeing more NAKs, that’s probably why.

One nice thing about Arduino 1.0 is built-in PROGMEM support for strings. It is now possible to free about 300-400 bytes of RAM by redefining USBTRACE and USBTRACE2 macros used in debugging output (thank you, John, for the tip!). For example, USBTRACE (Serial.print(F(s))) will move all USBTRACE strings to PROGMEM. The code size will increase so be careful with this feature if your code size is close to the limit for your Arduino board.

This is the end of announcement – download the code, play with it and if you have any issues please share your findings in the comments.


127 comments to Arduino 1.0-compatible USB Host Library released

  • Papier

    Hi Oleg,
    I have connected the TX and RX of the PL2303 (Rev. A) but I didn’t have loopback.
    Enabling debug feature seems that device answers always NAK until timeout
    With Windows everything is ok!

    Can you help me? Thank you,

  • Good morning, Oleg,

    I realised an USB camera control by means of your PTP2.2 library (New Version with record on /off). I need only focus control, zoom and video record on/off. All works fine, exept the termination of the record – function. On record OFF recording stops but after this there seems to be no further USB connection between camera and Arduino. Neither the Camra nor the Arduino “hang” so i see the problem in the USB field. When I reset the USB shield by its reset button, the system continues to work as before.
    Is there a better solution as the button and where may be reason for the problem?

  • Hi, Oleg ,

    I forgot: My camera is the EOS 600D.