Posts

USB Host Shield library Version 2.0 released.

Hub demo

Hub demo


What started as a quick re-factoring effort transformed to a major redevelopment, but finally all pieces fit together tightly and I am pleased to announce that initial release of USB Host Shield library ver.2.0 has been posted to github. This new version contains several major improvements:

  1. Only 5 Arduino pins are now required for USB Host Shield to function – 3 standard SPI pins (SCK, MISO, MOSI) and 2 remappable pins (SS and INT).
  2. The low-level interface to MAX3421E has been re-designed. Arduino pin manipulation routines has been replaced with mechanism inspired by Konstantin Chizhov’s C++ AVR pin templates. As a result, low-level transfers became approximately 3.5 times faster. Also, pin reassignment can be done much easier by passing pin numbers into MAX3421E template during instantiation.
  3. The high-level interface to USB devices has been re-designed as well. It is now possible to connect USB hub to the shield and have many devices on USB bus, up to 7 daisy-chained 8-port hubs plus up to 44 devices connected to hub ports left after daisy-chaining, memory permitting. Also, a standard mechanism of device initialization/polling/releasing has been added to enumeration.

Several minor code improvements has also been made. NAK_LIMIT is now tied to an endpoint – it is now possible to have NAK_LIMIT set to 1 for interrupt endpoint and 32000 for bulk endpoint of the same device simultaneously. Control transfer function now accepts callback in order to split long chunks of data, if necessary. inTranser() function now is able to return actual number of bytes received.

Support for several popular device classes has been added. Device initialization and event handling is now moved to a library specific to device class, therefore user application does’n need to do this and only needs to process actual device data. The following devices are now supported by the library code:

  • Human Interface Device AKA HID. Keyboards, mice, game controllers, bar code scanners, magnetic card and RFID readers – the list goes on. Initialization, polling, report descriptor parsing, as wellas reading and sending reports is possible.
  • Asynchronous Serial over USB AKA CDC. Devices of this class provide serial connectivity. For example, newer Arduino boards, such as UNO and Mega 2560 communicate to a PC using CDC ACM-class device, while older boards, such as Duemilanove, use FTDI FT232 USB-to-serial converter. 3 main types of converters are supported – CDC ACM (newer Arduinos and most modern cell phones), FTDI FT232 (older Arduinos plus a ton of standalone converters ) and Prolific PL2303 (mainly used in USB cables for various cellphones).

Several other device classes are in the works and will be available soon. They include:

  • Mass Storage Devices – Flash Drives, USB sticks, card readers, etc.
  • PTP – a protocol used in digital cameras. The PTP code is being transferred from current PTP project with minor changes.
  • Android ADK protocol, recently introduced in versions 3.1 and 2.3.4 of Android OS. Simple lightweight protocol for bi-directional communication with Android phone or tablet.

In addition to that, USB hub is supported by its own class; however, in order to use it nothing special needs to be done apart from defining an instance of hub class for each hub.

Library code is compatible with current revisions of USB Host Shield, i.e. full-size shield r2.0 and Mini shield r1.1. Older shields can be made compatible with new library by performing a simple hardware modification. I will add a section to hardware manual eventually, in the mean time, if you still have an old shield and want to know how to mod it to make it compatible with new library, drop me a line. It also should be noted that due to extra code needed for multi-device support binaries compiled from this library are larger than old one – before migrating your existing project make sure it will fit into your Arduino.

A hub_demo directory under examples contains a sketch demonstrating hub functionality. The sketch goes from hub to hub initializing devices and then prints their device and configuration descriptors. As can be seen on the title picture, I have a 24 port hub, which actually consists of four daisy-chained 7-port hubs, 3 cell phones, couple mice, USB-to-serial converter, Xbee plugged into Explorer board, digital scale, a pair of RC controllers, digital camera, and RFID reader. The output of a sketch running this setup can be seen here.

The following lines:

USBHub  Hub1(&Usb);
USBHub  Hub2(&Usb);
USBHub  Hub3(&Usb);
USBHub  Hub4(&Usb);

create hub instances, if you need more than four (up to 7), add USBHub Hub5(&Usb);, USBHub Hub6(&Usb);, USBHub Hub7(&Usb);. If you need to address more than 16 devices, including hubs, increase USB_NUMDEVICES in Usb.h.

Except for hubs, the sketch doesn’t make any attempts to configure any devices, it can be run with any USB devices which are available.

At present, I only have one other sample sketch in acm directory. It is a simple terminal intended to be used with cell phones. I will post details about using it soon. In the mean time, take a look at the cdoe, run sketches and let me know what you think.

Oleg.

382 comments to USB Host Shield library Version 2.0 released.

  • Sigi

    HI
    I have a Logitech cordless gamepad and a cordless joystick.
    That units can be read from the arduino Mega using this?

    The porpuse is to use the controls on a home made Telescope that is now already working with and old PC 15pin gamepad…

  • jim

    Thank you for your excellent work. I have used version 1 of your library very successfully with Android ADK. However, when I try to use version 2, I get several errors. Do you plan to restore ADK compatibility to version 2 of your library? Version 2 seems to offer advantages over version 1 and I would like to use it.

  • dsahwe

    Hi Oleg, I just browsed through the (well structured!) sources. My aim is to use the library on a ARM7 or Cortex-M(0 or 3) based controller instead of Arduino. Do you think this could be done? As far as I can see, at least avrpins.h usbhost.h will have to be changed but maybe I overlook something.
    Cheers,
    Andreas

    • It would be difficult to modify avrpins.h to work with ARM hardware. I suggest developing your own pin support. usbhost.h can be used as-is except for SPI.

  • Martin

    I’m using latest version of code and am connecting to Xbox controller, the controller acts as a HID device but produces no report description, just supplies the data about which buttons have been pressed.
    I’ve modified the keyboard boot example and am polling the device.
    When a keyboard is plugged in my code initiates the usb control and returns a buffer showing which key has been pressed or all 0’s if no key pressed.
    With an Xbox controller,when the device is polled it returns the correct data in the buffer and then restarts the device every time. Constantly calling setup and then the main loop. I thought it may be due to insufficient power so have connected a 9v supply to the Arduino, but am still getting the same result. Do you have any ideas about what I could do to track down the problem.
    Thanks

  • Michael

    Hello, We are having an odd problem with the Mega ADK and the Nexus S. We are using the DemoKit APK and pde. When the program begins to run (i.e. after reset) it pops up and immediately closes. Any ideas?

    D/Tethering( 107): interfaceAdded :usb0
    D/UsbService( 107): entering USB accessory mode: UsbAccessory[mManufacturer=Google, Inc., mModel=DemoKit, mDescription=DemoKit Arduino Board, mVersion=1.0, mUr
    i=http://www.android.com, mSerial=0000000012345678]
    W/Vold ( 71): Ignoring unknown switch ‘usb_connected’
    I/ActivityManager( 107): Starting: Intent { act=android.hardware.usb.action.USB_ACCESSORY_ATTACHED flg=0x10000000 cmp=com.google.android.DemoKit/.UsbAccessoryA
    ctivity (has extras) } from pid 107
    I/DemoKitLaunch( 513): starting phone ui
    I/ActivityManager( 107): Starting: Intent { flg=0x14000000 cmp=com.google.android.DemoKit/.DemoKitPhone } from pid 513
    V/RenderScript_jni( 195): surfaceDestroyed
    D/DemoKit ( 513): accessory opened
    I/ActivityManager( 107): Displayed com.google.android.DemoKit/.DemoKitPhone: +734ms (total +753ms)
    D/UsbService( 107): exited USB accessory mode
    D/Vold ( 71): usb_mass_storage function enabled

  • alex

    ЗдравствуйтС ОлСг
    МнС ΠΎΡ‡Π΅Π½ΡŒ интСрСсна Π’Π°ΡˆΠ° Ρ€Π°Π±ΠΎΡ‚Π°.Но ΠΊ соТалСнию Ρƒ мСня Π½Π΅ Ρ…Π²Π°Ρ‚Π°Π΅Ρ‚ Π·Π½Π°Π½ΠΈΠΉ Π΄ΠΎ ΠΊΠΎΠ½Ρ†Π° ΠΏΠΎΠ½ΡΡ‚ΡŒ вСсь Π°Π»Π³ΠΎΡ€ΠΈΡ‚ΠΌ Ρ€Π°Π±ΠΎΡ‚Ρ‹ USB shield.
    Π—Π°Π΄Π°Ρ‡Π° состоит Π² ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠΈ Ρ‡Π΅Ρ‚Ρ‹Ρ€Π΅Ρ… Arduino ΠΊ USB shield.
    Π‘ΡƒΠ΄Ρƒ вСсьма ΠΏΡ€ΠΈΠ·Π½Π°Ρ‚Π΅Π»ΡŒΠ½Ρ‹ΠΌ Ссли ΠΎΡ‚Π²Π΅Ρ‚ΠΈΡ‚Π΅.
    АлСксСй Н. (60 Π»Π΅Ρ‚)

  • Vik

    Hi,

    I just recieved your plug and play USB host shield and I have tried to run the Board_qc sketch. I am getting the below mentioned output

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
    GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
    Test failed. Value written: 00 Value read: FF
    Press any key to continue…

    Can you tell my why the GPIN test is being failed. I need to use this shield to communicate with a USB modem. What I need to do more to rectify this GPIN issue or I can move to communicate with the USB device without passing this test

    • GPIN pis are connected to GPOUT on my test fixture, that’s how I test them. You can either connect them like shown in the output or press any key to skip this part. If you do it in serial monitor, you need to click “Send” after pressing any key.

  • Vik

    One thing more. The test does not continue once I press any key on the keyboard. I am seeing the result using the serial monitor of the Arduino.

  • Robert

    Hi Oleg

    A use Arduino Mega ADK (bundle with USB), and I tried use newest library version (2.0) and Arduino 1.0 , but it doesn’t work.
    I tried examples and I have only “OSC did not start.”
    I thougt that my arduino is wrong

    but

    If I use Arduino 0023 and older library (3 year old) and examples from http://www.circuitsathome.com/mcu/arduino-usb-host-part-3-descriptors everything is OK

    Where is problem?

  • Mahmoud

    Will the mass storage class be supported soon, if you can share the code for now so I can try to get it to work it will be great.
    we have a graduation project relies on the shield.

    thanks,
    Mahmoud

  • Martin

    In the method USB::inTransfer the payload is read using the token tokIN rather than tokINHS, but in other places such as the status read tokINHS is used. Why is tokIN used regardless of the speed of the line?

    thanks

  • Martin

    I’ve spotted it… the “HS” is not “High Speed”.. rather it’s “Hand Shake”, a bit instructing the controller to perform the special handshake logic as noted in AN3785.

    Thanks for a great board & sw.

  • Hararion

    Hello! i wrote to you, because i need some advice to connect an old Xbox wireless mad catz controller, like this one: http://xd5.xanga.com/90cf8b2628233280849318/w223733111.jpg

    note that this controller isn’t an xbox 360, this is for the first xbox.

    i’ve read a lot around about that xbox controller, and i found that this use a complex USB protocol, based on this, i’ll buy the USB shield to use with my arduino duemilanove, so i need some help to make this a success.
    thanks in advance…

  • beard42

    Бпасибо Π·Π° Shield ΠΈ Π±ΠΈΠ±Π»ΠΈΠΎΡ‚Π΅ΠΊΡƒ!

    А Π½Π° ΠΊΠ°ΠΊΠΎΠΌ этапС находится Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠΈ Mass Storage Devices?
    МоТно Π»ΠΈ ΠΊΠ°ΠΊ-Ρ‚ΠΎ ΠΏΠΎΠ»ΡƒΡ‡ΠΈΡ‚ΡŒ доступ ΠΊ ΡΡƒΡ‰Π΅ΡΡ‚Π²ΡƒΡŽΡ‰Π΅ΠΉ вСрсии ΠΈ, Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ, ΠΏΠΎΡƒΡ‡Π°Π²ΡΡ‚Π²ΠΎΠ²Π°Ρ‚ΡŒ (ΠΏΠΎ ΠΊΡ€Π°ΠΉΠ½Π΅ΠΉ ΠΌΠ΅Ρ€Π΅ Π² качСствС тСстСра) Π² Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅?

    Π‘ ΡƒΠ²Π°ΠΆΠ΅Π½ΠΈΠ΅ΠΌ,
    beard42

    • Mass Storage Π½Π° ΠΏΠΎΠ»ΠΏΡƒΡ‚ΠΈ – ΠΊΠΎΠΌΠ°Π½Π΄Ρ‹ ΠΎΡ‚ хоста ΡƒΠΆΠ΅ ΡˆΠ»ΡŽΡ‚ΡΡ, Π½ΠΎ дСвайс ΠΈΡ… ΠΏΠΎΠΊΠ° Π½Π΅ ΠΏΠΎΠ½ΠΈΠΌΠ°Π΅Ρ‚. Бпасибо Π·Π° ΠΏΡ€Π΅Π΄Π»ΠΎΠΆΠ΅Π½ΠΈΠ΅, тСстСры ΠΏΠΎΠΊΠ° Π½Π΅ Ρ‚Ρ€Π΅Π±ΡƒΡŽΡ‚ΡΡ, ΠΏΠΎΡΠΊΠΎΠ»ΡŒΠΊΡƒ Ρ‚Π΅ΡΡ‚ΠΈΡ‚ΡŒ Π½Π΅Ρ‡Π΅Π³ΠΎ ΠΏΠΎΠΊΠ°.

      • beard42

        Π‘Π»Π°Π³ΠΎΠ΄Π°Ρ€ΡŽ Π·Π° ΠΎΡ‚Π²Π΅Ρ‚.
        О сроках Ρ€Π΅Π»ΠΈΠ·Π° ΡΠΏΡ€Π°ΡˆΠΈΠ²Π°Ρ‚ΡŒ Π½Π΅ Π±ΡƒΠ΄Ρƒ – сам знаю, Ρ‡Ρ‚ΠΎ Π·Π½Π°Ρ‡ΠΈΡ‚ “вСсти ΠΏΡ€ΠΎΠ΅ΠΊΡ‚ Π² свободноС ΠΎΡ‚ Ρ€Π°Π±ΠΎΡ‚Ρ‹ врСмя”. Мог Π±Ρ‹ ΠΏΠΎΡƒΡ‡Π°Π²ΡΡ‚ΠΎΠ²Π°Ρ‚ΡŒ Π² Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ΅, Π½ΠΎ, чСстно говоря, Π½Π΅ ΠΏΡ€Π΅Π΄ΡΡ‚Π°Π²Π»ΡΡŽ сСбС ΠΊΠ°ΠΊ это тСхничСски Π΄ΠΎΠ»ΠΆΠ½ΠΎ Π²Ρ‹Π³Π»ΡΠ΄Π΅Ρ‚ΡŒ (имССтся Π² Π²ΠΈΠ΄Ρƒ ΠΏΠ°Ρ€Π°Π»Π»Π΅Π»ΡŒΠ½ΠΎΠ΅ Π²Π΅Π΄Π΅Π½ΠΈΠ΅ ΠΊΠΎΠ΄Π°). Π’ любом случаС всСгда Π³ΠΎΡ‚ΠΎΠ² ΠΏΠΎΠΌΠΎΡ‡ΡŒ.

        Π‘ Π½Π°Π΄Π΅ΠΆΠ½ΠΎΠΉ Π½Π° всС-Ρ‚Π°ΠΊΠΈ скорый Ρ€Π΅Π»ΠΈΠ·,
        beard42.

  • donald

    How much code space do Mass Storage Devices take up ?

    I would like to do a data logger with only a single USB thumb drive.

    I want to know which Arduino I should use.

    Thanks

    donald

  • Jose L

    Hi,

    I would like to know when we can see the code for mass storage, I just bought the shield hopping I can save some txt files in a memory stick but I see in this forum that itΒ΄s not possible yet, I would be so glad if you say that the code is working or at least if I can get the code to analyze and to make it works.

    Thank you very much.

    Jose L.

  • alex

    ЗдравствуйтС ОлСг
    МнС ΠΎΡ‡Π΅Π½ΡŒ интСрСсна Π’Π°ΡˆΠ° Ρ€Π°Π±ΠΎΡ‚Π°, ΠΏΡ€ΠΎΡˆΡƒ Вас ΠΏΠΎΠΌΠΎΡ‡ΡŒ.. Π²ΠΎΠ·ΠΌΠΎΠΆΠ½ΠΎ Π»ΠΈ ΠΏΠΎΠ΄ΠΊΠ»ΡŽΡ‡Π΅Π½ΠΈΠ΅ Ρ‡Π΅Ρ€Π΅Π· НАБ Π½Π΅ΡΠΊΠΎΠ»ΡŒΠΊΠΈΡ… Ардуино, Π½Π°ΠΏΡ€ΠΈΠΌΠ΅Ρ€ 4-Ρ….
    Π£ мСня полноразмСрная ΠΏΠ»Π°Ρ‚Π° DEFROBOT USB host Shield, всС тСсты проходят. ΠŸΡ€ΠΎΠ±ΠΎΠ²Π°Π» ΡΠΎΠ΅Π΄ΠΈΠ½ΠΈΡ‚ΡŒ Π΄Π²Π° Ардуино с ΠΏΠΎΠΌΠΎΡ‰ΡŒΡŽ USBFTDILoopback_25_3 – Ρ€Π°Π±ΠΎΡ‚Π°Π΅Ρ‚. НС ΠΌΠΎΠ³Ρƒ ΠΏΠΎΠ½ΡΡ‚ΡŒ ΠΊΠ°ΠΊ ΡƒΠΏΡ€Π°Π²Π»ΡΡ‚ΡŒ(ΠΏΠ΅Ρ€Π΅ΠΊΠ»ΡŽΡ‡Π°Ρ‚ΡŒ) Hub. Бпасибо..
    АлСксСй (60 Π»Π΅Ρ‚)

    • DFROBOT – Π²ΠΎΡ€Ρ‹, ΠΎΠ½ΠΈ ΡƒΠΊΡ€Π°Π»ΠΈ ΠΌΠΎΠΉ Π΄ΠΈΠ·Π°ΠΉΠ½. Π― Π½Π΅ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΈΠ²Π°ΡŽ ΠΈΡ… ΠΏΡ€ΠΎΠ΄ΡƒΠΊΡ‚Ρ‹.

  • alex

    ОлСг
    ΠŸΡ€ΠΎΡˆΡƒ прощСния..ΠΏΠ΅Ρ‡Π°Π»ΡŒΠ½ΠΎ ΠΊΠΎΠ½Π΅Ρ‡Π½ΠΎ, искрСннС Π’Π°ΠΌ ΡΠΎΡ‡ΡƒΠ²ΡΡ‚Π²ΡƒΡŽ,Π½ΠΎ.. я ΠΊΡƒΠΏΠΈΠ» Ρ‡Ρ‚ΠΎ смог ( Π² ΠΏΡ€Π΅Π΄Π΅Π»Π°Ρ… своСй доступности)..
    спасибо Π·Π° ΠΎΡ‚Π²Π΅Ρ‚..
    АлСксСй

  • gokn

    hello,

    i’ve read:
    “Several other device classes are in the works and will be available soon. They include:

    Mass Storage Devices – Flash Drives, USB sticks, card readers, etc.”

    When is a lib to open and read txt data from the flash drive avalaible?

  • khayeanne

    can i use it for transferring files from usb to another usb without pc? I am developing a file transferring device includes usbs. tnx.

  • BH

    Hi, I’m also really interested in using the mass storage functionality for a time-sensitive project we have that requires talking with a thermal imager. Would be happy to serve as a beta tester for this software. Is there any way you could provide the pre-release version? Your help is greatly appreciated.

  • marco

    Hello!

    Right now I’m using the USB Host Shield 2.0 and the Arduino Duemilanove. I want to receive MIDI Signals and display them on the Serial Monitor like Collin did:

    http://www.circuitsathome.com/mcu/interfacing-midi-devices-with-arduino-using-usb-host-shield

    When i run the code, i get the Error “EP_RECORD does not name a type”. I don’t have much experience with the Arduino, can someone help me?

  • Rohan

    Hi Oleg,

    I am trying to used you USB Host Shield for a project of mine that requires storing and acquiring data from a USB mass storage.
    it seems from the comments above, that the code is still development.
    would it be possible to obtain a per-release/beta of the code, so that i can look into it and maybe get it to work, even if its helps as a guider, would be gr8.

    Regards,
    Rohan

    • The current state of development is in the source on github, files masstorage.cpp, masstorage.h. The device gets initialized and SCSI is working, more or less.

  • marco

    Hi Oleg!

    I’ve asked you two weeks before about Collins Code (http://www.circuitsathome.com/mcu/interfacing-midi-devices-with-arduino-using-usb-host-shield). The Code doesn’t have any errors anymore, I also use the Akai LPK25 Keyboard like Collin. But when I upload the code and open the Serial Monitor, the program only initialized the Akai LPK25, but when i press a key i don’t receive any data. Do you know what the problem is?

    I use the USB Host Shield 2.0 and Arduino Duemilanove w/ATmega328.
    Please help me!

  • dh

    I am using the mini usb shield to communicate between an Arduino and an Android tablet. I works quite well and I am able to pass data in either direction.

    Recently I have run into a peculiar situation.

    When I plug in or remove the usb shield connection from the Android tablet my ADB connection over tcpip disconnects and needs to be re-connected. This makes debugging connection issues a bit of a challenge.

    Any thoughts?

    dh

  • Jesse

    How hard would this be to port to a PIC microprocessor? I am using a pic24 which does not have USB support as the core of a robot, but I want to use an xbox or ps3 controller to control it directly without needing to route the signals through a PC. The pic has SPI, so is it just a matter of mapping the proper pins, or is there some other changes that would need to be made?

    • You will also need to modify the code to compile using C compiler as PIC24 doesn’t have C++.

      • Jesse

        Yeah, I realized that after I posted this. I am very proficient in C and decently skilled in C++ so I think it’s a manageable task, but I probably would just port a fraction of the code because I only need support for the 360 controller and I only care about the packets it sends containing button state information, and I’m in a bit of a time-crunch as this is for a class project. Any help or suggestions on how to accomplish this would be greatly appreciated, Thanks for all your hard work thus far, it will make my task much easier than having to learn all about the USB protocol and programming for the max4321e all by myself, this project is a great starting point for learning.

        • you can skip the hub support but you still need to get all the transfers working otherwise you won’t be able to initialize your device. I suggest looking at legacy library, it has all you need but the structure is simpler. In addition, there is abandoned project I started before Arduino which is written in C -> https://github.com/felis/lightweight-usb-host . You can add OUT transfer to it and get functional stack.

          • Jesse

            Thanks so much for all your hard work, this is awesome information and will help me greatly. Cheers πŸ™‚

          • Jesse

            Well I have taken a good look at your source code,I think I can manage to port it to the PIC24H sometime this week (or at least I hope so, otherwise I will need a backup plan for my project). Your code really is quite a thing of beauty, there have been times when I have thought “what the heck is that supposed to do” then when I figured it out thought “thats a nifty little piece of code” it’s smart, clean, and efficient. I particularly liked this little snippet

            while( ++i ) {
            if(( regRd( rUSBIRQ ) & bmOSCOKIRQ )) {
            break;
            }
            }
            At first it didn’t make sense to me why you would have the incrementer as a condition of the while loop, until I realized that at some point it will loop back to zero when you go past the maximum of that datatype, very interesting way to detect a timeout, very efficient, I never would have thought of that.

            Anyway, onto my question…
            It looks to me like the SPI interface is clocked at 1/2 the CPU speed, is that correct? If so, at this speed, do you ever find that there are errors in the transfers because the CPU is executing code to load the data register while the SPI clock is pumping out data?

            Also, arduinos run on a 16 mhz processor, so does that mean that the SPI interface is running at 8 MHZ = 8 Mbits/second? Is this fast enough to sustain a USB 2.0 Full speed link? If not, does some data get missed because of this, or are the chips buffers large enough to makeup for the slightly slower speed, or does the chip just scale down the speed, like 12 Mbps is maximum, but it can transfer at 8Mbps, or am I completely misunderstanding something?

            Just curious… I like to fully understand how things work rather than looking at them as a black box.

            Cheers,

            Jesse

          • Max.SPI speed of MAX3421E is 26MHz. I heard that at ~20MHz it becomes unstable, never saw it happening myself, could simply be bad decoupling. IIRC , the max.SPI clock on PIC24H is lower than that. MAX3421E also has its own clock so USB timing requirements are satisfied regardless of SPI speed. On the next level of protocol, USB Host is setting the pace therefore it doesn’t matter how slow it is. Getting full 12Mbps is diffucult on small micros, maybe PIC24E at max. clock can get close. Do you know the throughput of Microchip’s own USB stack written for their USB Host-capable micros?

          • Jesse

            Yes, I was aware that the PIC24H has a lower maximum peripheral speed. I thought it was around 10 MHZ, just doublechecked the data sheet and it says 15 MHZ for half-Duplex in Host mode, or 9MHZ for full duplex in Host mode, this is why I was curious about the USB timing requirements in the first place.

            I can clock the PIC at up to 40 MIPS, but I am limited by the prescalers in what Peripheral clock can be set at, so if I used a 6:1 prescaler that only gives a 6.667 MHZ SPI clock, if instead I clocked it at 32 MHZ and used a factor of 4:1 for the prescaler, I could get up to 8 MHZ which should be in spec for the PIC’s SPI clock running in full-duplex as a host, the only thing I was worried about is whether or not it would give enough time for code to complete setting up data transfers so that they flow seamlessly in a multi-byte transfer. In your code you use a 2:1 prescaler, so if that works I guess 4:1 should be fine for mine.

            In the end I still will not get the 12Mbps transfer, but if the MAX3421 chip can still handle the USB timing requirements than thats fine. If I only needed to operate at half-duplex I could get 12Mbps for the SPI speed, but I wasnt sure if that is feasible. It seems like it could be, but I may be misunderstanding something. It appears like the code only transmits or receives, never both at the same time (or at least we dont care about the bytes that are clocked in when we transfer data out) so would it be ok to run in half-duplex mode?

            In the end, for my application, an 8 MHZ SPI clock should be fine, I am only concerned with receiving data about button presses of a joystick, I just like to be thorough in my research, and if I had more time I would experiment with this stuff a little bit more.

            Lastly, I am not sure about the throughput of Microchips USB stack, I am still waiting to receive a sample chip from them that I was going to try to get working, but I dont think I have enough time to test both solutions and have a working prototype for my project so I think I am going to stick with this route for now and may experiment in using the PIC24F’s USB functionality at a later date.

            Cheers,

            Jesse

          • In full-duplex, MAX3421E sends back its status register during first byte transfer (while SPI host transmits register number/direction). I was going to use this feature but never actually did so the code is essentially half-duplex. Speed is not an issue with joysticks, most of them are low-speed devices anyway.

  • Cetin

    Hi,

    Is there any simple sample for usb host.
    I wish connect a dslr to the usb host and then send/receive data from the dslr without any parser like NKEventParser or any other parser.
    I want to process the raw data on android phone. (the phone is connected with bluetooth)

    Thanks

    • You can’t send raw data to the camera – it needs PTP protocol.

      • Cetin

        ok, the problem is that I don’t know cpp.

        I think it is possible to create a PTP protocol to dslr and send all incomming data from bluetooth to dslr and send all data from dslr to bluetooth without any parse process. For example in all PTP/ptpsketches are parser’s like devpropparser.
        I hope you know what I mean

  • Sorin Irimies

    Hi Oleg, first I want to congratulate you for the tough work you have done in order for us to be able to use usb host shields that were not google official.I am quite new in the field but enthusiastic about it.
    I recently bought this host shield copy:
    http://www.ebay.de/itm/New-USB-Host-Shield-Support-Google-Android-ADK-UNO-MEGA-Duemilanove-1280-2560-/280933336083?pt=Wissenschaftliche_Ger%C3%A4te&hash=item4168ee8413
    I use the arduino 1.0.1 IDE on Ubuntu 12.10
    I own a nexus 7 with JB 4.2 and I want to connect it to my arduino uno. I tried to compile some examples from the USB Host Shield 2.0 library but I get alot of compile time errors, its quite long:


    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:3:54: error: variable β€˜ReportDescParserBase::usagePageTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:22:54: error: variable β€˜ReportDescParserBase::usagePageTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:31:55: error: variable β€˜ReportDescParserBase::genDesktopTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:43:55: error: variable β€˜ReportDescParserBase::genDesktopTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:71:55: error: variable β€˜ReportDescParserBase::genDesktopTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:94:55: error: variable β€˜ReportDescParserBase::genDesktopTitles3’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:106:55: error: variable β€˜ReportDescParserBase::genDesktopTitles4’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:117:49: error: variable β€˜ReportDescParserBase::simuTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:132:49: error: variable β€˜ReportDescParserBase::simuTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:141:49: error: variable β€˜ReportDescParserBase::simuTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:177:47: error: variable β€˜ReportDescParserBase::vrTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:190:47: error: variable β€˜ReportDescParserBase::vrTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:195:55: error: variable β€˜ReportDescParserBase::sportsCtrlTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:202:55: error: variable β€˜ReportDescParserBase::sportsCtrlTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:215:55: error: variable β€˜ReportDescParserBase::sportsCtrlTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:238:49: error: variable β€˜ReportDescParserBase::gameTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:244:49: error: variable β€˜ReportDescParserBase::gameTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:272:54: error: variable β€˜ReportDescParserBase::genDevCtrlTitles’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:282:47: error: variable β€˜ReportDescParserBase::ledTitles’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:362:51: error: variable β€˜ReportDescParserBase::telTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:372:51: error: variable β€˜ReportDescParserBase::telTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:393:51: error: variable β€˜ReportDescParserBase::telTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:400:51: error: variable β€˜ReportDescParserBase::telTitles3’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:408:51: error: variable β€˜ReportDescParserBase::telTitles4’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:426:51: error: variable β€˜ReportDescParserBase::telTitles5’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:445:49: error: variable β€˜ReportDescParserBase::consTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:454:49: error: variable β€˜ReportDescParserBase::consTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:460:49: error: variable β€˜ReportDescParserBase::consTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:471:49: error: variable β€˜ReportDescParserBase::consTitles3’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:483:49: error: variable β€˜ReportDescParserBase::consTitles4’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:493:49: error: variable β€˜ReportDescParserBase::consTitles5’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:533:49: error: variable β€˜ReportDescParserBase::consTitles6’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:567:49: error: variable β€˜ReportDescParserBase::consTitles7’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:581:49: error: variable β€˜ReportDescParserBase::consTitles8’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:590:49: error: variable β€˜ReportDescParserBase::consTitles9’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:607:49: error: variable β€˜ReportDescParserBase::consTitlesA’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:616:49: error: variable β€˜ReportDescParserBase::consTitlesB’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:630:49: error: variable β€˜ReportDescParserBase::consTitlesC’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:638:49: error: variable β€˜ReportDescParserBase::consTitlesD’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:713:49: error: variable β€˜ReportDescParserBase::consTitlesE’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:857:50: error: variable β€˜ReportDescParserBase::digitTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:873:50: error: variable β€˜ReportDescParserBase::digitTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:880:50: error: variable β€˜ReportDescParserBase::digitTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:906:54: error: variable β€˜ReportDescParserBase::aplphanumTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:911:54: error: variable β€˜ReportDescParserBase::aplphanumTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:960:54: error: variable β€˜ReportDescParserBase::aplphanumTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:984:53: error: variable β€˜ReportDescParserBase::medInstrTitles0’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:995:53: error: variable β€˜ReportDescParserBase::medInstrTitles1’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:1003:53: error: variable β€˜ReportDescParserBase::medInstrTitles2’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:1008:53: error: variable β€˜ReportDescParserBase::medInstrTitles3’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’
    /usr/share/arduino/libraries/AndroidUSBHost/hidescriptorparser.cpp:1021:53: error: variable β€˜ReportDescParserBase::medInstrTitles4’ must be const in order to be put into read-only section by means of β€˜__attribute__((progmem))’”

    Is there a way to sort this out? Could it be because I am not using the latest arduino IDE?
    Any help is wellcome.Thx alot.

  • marco

    Hi Oleg!

    I want to read the MIDI code from the Akai MPD18. I would use the Code from Collin (www.circuitsathome.com/mcu/interfacing-midi-devices-with-arduino-using-usb-host-shield), but I don’t know how to read the definitions out of the descriptor_parser.

    These are the definitions from the LPK25:

    #define LPK25_ADDR 1
    #define LPK25_VID_LO 0xFFFFFFE8 // Akai VID
    #define LPK25_VID_HI 0Γ—09
    #define LPK25_PID_LO 0Γ—76 // Batch Device
    #define LPK25_PID_HI 0Γ—00
    #define LPK25_CONFIG 1
    #define LPK25_IF 1
    #define LPK25_NUM_EP 2
    #define EP_MAXPKTSIZE 64
    #define EP_BULK 0Γ—02
    #define EP_POLL 0Γ—00 // 0x0B for Korg nanoKey
    #define CONTROL_EP 0
    #define OUTPUT_EP 1
    #define INPUT_EP 1
    #define LPK25_01_REPORT_LEN 0Γ—09
    #define LPK25_DESCR_LEN 0x0C

    And here is the descriptor of the Akai MPD18:

    Start
    Device addressed… Requesting device descriptor.
    Device descriptor:

    Descriptor Length: 12
    USB version: 1.10
    Class: 00 Use class information in the Interface Descriptor
    Subclass: 00
    Protocol: 00
    Max.packet size: 40
    Vendor ID: 09E8
    Product ID: 0074
    Revision ID: 0100
    Mfg.string index: 01 Length: 10 Contents: Akai
    Prod.string index: 02 Length: 22 Contents: Akai MPD18
    Serial number index: 00
    Number of conf.: 01

    Configuration number 0
    Total configuration length: 86 bytes

    Configuration descriptor:
    Total length: 0056
    Number of interfaces: 02
    Configuration value: 01
    Configuration string: 00
    Attributes: 80
    Max.power: FA 500ma

    Interface descriptor:
    Interface number: 00
    Alternate setting: 00
    Endpoints: 00
    Class: 01 Audio
    Subclass: 01
    Protocol: 00
    Interface string: 00

    Unknown descriptor:Length: 09
    Type: 24
    Contents: 010001090001010904

    Interface descriptor:
    Interface number: 01
    Alternate setting: 00
    Endpoints: 02
    Class: 01 Audio
    Subclass: 03
    Protocol: 00
    Interface string: 00

    Unknown descriptor:Length: 07
    Type: 24
    Contents: 01000132000624

    Unknown descriptor:Length: 06
    Type: 24
    Contents: 020101000924

    Unknown descriptor:Length: 09
    Type: 24
    Contents: 030102010101000905

    Endpoint descriptor:
    Endpoint address: 01 Direction: OUT
    Attributes: 02 Transfer type: Bulk
    Max.packet size: 0040
    Polling interval: 00 0 ms

    Unknown descriptor:Length: 05
    Type: 25
    Contents: 0101010905

    Endpoint descriptor:
    Endpoint address: 02 Direction: IN
    Attributes: 02 Transfer type: Bulk
    Max.packet size: 0040
    Polling interval: 00 0 ms

    Unknown descriptor:Length: 05
    Type: 25
    Contents: 010102FFE9

    Please help me!

  • thoger

    PTP for Video Capture?
    I’ve used the USB shield & the EOS library to capture images with my Canon camera.

    Now I have a need to start / stop video recording with the same setup.

    I realise this is not included in the library yet, but does anyone have any clues to how this may be implemented?

    I see http://dslrsystems.com/ have achieved this, but the code is not available from Google code anymore, it’s only available as a .HEX file download.

    Any clues?

  • weigee

    Hi Oleg,

    I’m wondering if you can kindly help me out with my predicament. I have recently acquired both a teensy as a mini USB host shield. I have wired up my teensy 2.0 with the host shield exactly as documented in the page as follows:

    http://www.pjrc.com/teensy/td_libs_USBHostShield.html

    Using the libraries that is included in the page (http://www.pjrc.com/teensy/arduino_libraries/USBHostShield2.zip), I ran the board_qc program successfully with no errors. The output is as follows:

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K……………. SPI long test passed
    GPIO test. Connect GPIN0 to GPOUT7, GPIN1 to GPOUT6, and so on
    Test failed. Value written: 00 Value read: FF
    Press any key to continue…

    However, when I download the official latest host shield library from github (https://github.com/felis/USB_Host_Shield_2.0), I can’t get the software working. The output is as follows:

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision invalid. Value returned: 00
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test

    Since I could run the board_qc using the library in the teensy page, I’m assuming that the hardware assembly and soldering is fine. However, I’m not sure exactly how the official libraries have changed.

    I have a separate Arduino Leonardo with the full size USB host shield that interfaces directly with the Arduino that works with the official library. As I have already written some code that worked on this combination, my original intent was to port the whole setup in a smaller form factor using teensy 2 with the small host shield. However, since I can’t get the official libraries working, I can’t using my code directly as well on the teensy combination.

    Would you kindly give me some pointers as to where I can begin to troubleshoot my problem? Any guidance would be greatly appreciated and thanks for your time!

    Regards,
    Gee.

  • PaoloU

    Dear Oleg,

    I bought a USB Host Shield from DFRobot and tried to connect an RFXCOM transceiver RFXtrx433.
    It is a simple device (from USB point of view) as shown by its descriptors:

    Start
    01

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 00
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 0403
    Product ID: 6001
    Revision ID: 0600
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 03
    Number of conf.: 01

    Configuration descriptor:
    Total length: 0020
    Num.intf: 01
    Conf.value: 01
    Conf.string: 00
    Attr.: A0
    Max.pwr: 2D

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 02
    Intf. Class: FF
    Intf. Subclass: FF
    Intf. Protocol: FF
    Intf.string: 02

    Endpoint descriptor:
    Endpoint address: 81
    Attr.: 02
    Max.pkt size: 0040
    Polling interval: 00

    Endpoint descriptor:
    Endpoint address: 02
    Attr.: 02
    Max.pkt size: 0040
    Polling interval: 00

    Addr:1(0.0.1)

    I got the descriptors from the USB_desc sketch which seems to work perfectly.
    Unfortunately, I was not able to establish correct communication between Arduino Uno and the RFXCOM device.
    After many days of unsuccesful work, my idea is that there is currently a gap between simple sketches, like USB_desc, working perfectly but not complete enough, and complex ones, related to some device classes, based on specifically developed library modules (like HID, PS3, ACM and so on).
    The tutorial posts started very well but they do not really reach the point to explain how to use the library in order to link a not yet envisaged device, like it is my case.
    Calling the USB class methods directly is not simple and requires to browse the C++ code which is not an easy task.
    After studying http://www.beyondlogic.org/usbnutshell/usb1.shtml, I could understand much more about USB, but not enough to be sure to initialise all parameters correctly.
    Several examples from your past posts are no more valid with the 2.0 version of the library.
    So my suggestion is to possibly provide a documentation of the main USB library functions, and general examples about how to call them directly (from an Arduino sketch), so that it will be much quicker to have it working with new devices, without a need to modify and recompile the library.
    Another benefit will be not to link class specific library modules which can occupy most of available memory.
    I look forward to read your suggestions about how to solve my problem.
    Kind regards
    Paolo

    • How did you come to the conclusion that the device which descriptors you have posted is “simple”? It’s a proprietary device – do you know how to communicate with it?

  • PaoloU

    Dear Oleg, my (possibly too quick) conclusion was coming from seeing that there are only one interface and two endpoints.
    Moreover, I was able to communicate with the RFXCOM transceiver easily enough using a VBA program (under Excel). These are the main steps:

    1) first I initialise USB as a COM port

    ‘ Open COM port
    lngStatus = Foglio5.CommOpen(intPortID, “\\.\COM” & CStr(intPortID), _
    “baud=38400 parity=N data=8 stop=1”)

    2) then I send a short “reset” sequence (it seems not mandatory, however)

    val = &H20
    strData = Chr(val) + Chr(0) + Chr(0) + Chr(0) + Chr(0) ‘Reset RFXCom
    ‘Write data
    lngStatus = Foglio5.CommWrite(intPortID, strData)

    3) finally I start receiving data packets

    lngStatus = Foglio5.CommRead(intPortID, strData, 30)

    I am using a VBA USB library (http://dev.emcelettronica.com/serial-port-communication-excel-vba) which required minimal adjustments.
    There is no problem to parse the received data packet, as I found enough information on the Web (currently I am receiving, through the RFXCOM, temperature and humidity data from five Oregon sensors).
    Final goal will be to control the heating system in my house, and the idea was to use an Arduino Uno, instead of a Windows PC.
    So I need to connect the RFXCOM to Arduino using a USB Host adapter and the USB Library, but I found problems, as explained in my previous post.

    As the USB-desc sketch was running succesfully, I thought to integrate it with send and receive functionality, taking hints from other example sketches, like acm_terminal.
    I copy here the added parts:

    boolean first=true;
    EpInfo ep_record[3];
    EpInfo* Eptr;

    #define CONTROL_PIPE 0
    #define DATAIN_PIPE 1
    #define DATAOUT_PIPE 2
    #define EP_BULK 2
    #define COMMAND_REQ 0

    void loop()
    {
    Usb.Task();

    uint8_t rcode;
    uint8_t buf[64];

    if (first && (Usb.getUsbTaskState() == USB_STATE_RUNNING) )
    //if (millis() >= next_time)
    {
    Usb.ForEachUsbDevice(&PrintAllDescriptors);
    Usb.ForEachUsbDevice(&PrintAllAddresses);

    /* Initialize data structures for endpoints of device 1*/
    Eptr = ep_record;
    ep_record[ CONTROL_PIPE ] = *( Usb.getEpInfoEntry( 0,0 )); //copy endpoint 0 parameters
    ep_record[ DATAIN_PIPE ].epAddr = 0x01; // data endpoint
    //ep_record[ DATAIN_PIPE ].Attr = EP_BULK;
    ep_record[ DATAIN_PIPE ].maxPktSize = 0x40;
    //ep_record[ DATAIN_PIPE ].Interval = 0;
    //ep_record[ DATAIN_PIPE ].sndToggle = bmSNDTOG0;
    //ep_record[ DATAIN_PIPE ].rcvToggle = bmRCVTOG0;
    ep_record[ DATAOUT_PIPE ].epAddr = 0x02; // data endpoint
    //ep_record[ DATAOUT_PIPE ].Attr = EP_BULK;
    ep_record[ DATAOUT_PIPE ].maxPktSize = 0x40;
    //ep_record[ DATAOUT_PIPE ].Interval = 0;
    //ep_record[ DATAOUT_PIPE ].sndToggle = bmSNDTOG0;
    //ep_record[ DATAOUT_PIPE ].rcvToggle = bmRCVTOG0;
    rcode=Usb.setEpInfoEntry( 1, 3, Eptr );
    if( rcode ) {
    Serial.print(“\r\nErrore Tabella Ep: “);
    Serial.print(rcode);
    while(1); // halt in case of errors
    }

    //reset RFXCOM
    buf[0] = 0x20;
    buf[1] = 0x00;
    buf[2] = 0x00;
    buf[3] = 0x00;

    // rcode=Usb.ctrlReq( 1, ep_record[ CONTROL_PIPE ].epAddr, bmREQ_SET, COMMAND_REQ, 0x00, 0x00 ,0, 3, 3, buf, 0);
    rcode=Usb.outTransfer (1, 0x01, 4, buf);
    if (rcode)
    ErrorMessage(PSTR(“Control “), rcode);

    first=false; //do not do it again
    Serial.println(“\r\n Inizio ricezione”);
    delay(100);
    }

    if( Usb.getUsbTaskState() == USB_STATE_RUNNING ){
    delay(50);

    for (uint8_t i=0; i<64; i++)
    buf[i] = 0;

    rcode=0;
    uint16_t rcvd = 64;
    rcode = Usb.inTransfer(1, 0x01, &rcvd, buf); // legge dati dal device

    if (rcode && rcode != hrNAK)
    ErrorMessage(PSTR(“Ret”), rcode);

    // The device reserves the first two bytes of data
    // to contain the current values of the modem and line status registers.
    if( rcvd ) { //more than zero bytes received
    Serial.print(“\r\nRicevuto: “);
    for(uint16_t i=0; i < rcvd; i++ ) {
    //print_hex(buf[i],8); //printing on the screen
    Serial.print(buf[i],HEX);
    }
    }
    delay(10);
    }
    }

    I thought to use some default values for some of the parameters.
    Probably things are not so simple, as I always got errors.
    In the beginning there was a 0xDB error EP_NOT_FOUND_IN_TBL, so I added the endpoint registration in the table (following suggestions as from post
    "PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3", trying to update and complete it).
    The current version returns a continuous sequence of errors 0x0D, which I think is error hrJERR from the MAX3421.
    I am not a deep expert of USB, nor C++, so I have problems understanding how to use the USB library.
    Therefore my conclusions in my previous post. As my holidays are now at the end, I decided to ask for your help.
    The solution can be interesting for other people, as it appears in the Arduino Forum: Arduino + 433.92mhz rx + Oregon Scientific Weather
    Unfortunately, no solution is presented there.
    The RFXCOM transceiver can take the job of receiving and decoding the incoming radio data, leaving to Arduino "only" the task to parse the payload.
    It looked as a more efficient architecture, rather than to use a 433 MHz radio receiver shield and decode the complete serial stream (including synch, checksums and so on).
    Unfortunately, the normally user-friendly USB interface currently appears to be a difficult obstacle.
    If I could overcome it, I plan to integrate several more shields (display, RTC, relays, Wi-Fi, etc.) which I already bought, so as to build a complete home heating-control station. Security sensors and actuators can be added as well, through the RFXCOM device.
    Thank you for your help
    Paolo

    • In Windows, you have a driver which initializes the device and performs serial port emulation. In USB Host library, you don’t. The manufacturer (typically) won’t release any technical information about their device. Try to find out how to initialize the device – check, for example, Linux source to see if your device is supported. If it is not, I suggest giving up and switching to USB to serial converter which is supported in USB Host library.

  • PaoloU

    Dear Oleg, I am not sure I fully understand your suggestion. I thought that the USB Host Shield plus USB Library 2.0 was building up a USB to serial converter for the Arduino. Which USB to serial converter do you suggest? Which type of initialization is missing?

    • USB Host shields communicates with USB devices of various kinds, not necessarily USB to serial converters. Prolific PL2303 and FTDI FT232 based USB to serial converters are supported (as well as generic CDC ACM – for example, current Arduinos are CDC ACM devices on USB side).

  • Tuncay Cakmak

    Hey Oleg!

    First i want to thank you for the Informations here! Your Work is really great!
    I have a question about the USB Hub function with the Host Shield.
    I want to connect a second mouse on the Usb Hub and get the Information of both mice in my serial monitor. How can i realise that? I only get the coordinates of the mouse which i first connect to the hub. Can u help me with that?

    Best Regards
    Cakmak Tuncay

  • QFAN

    I’m getting the “OSC did not start” error. Arduino UNO R3, sparkfun.com USB Host Shield (red board).
    Is there any way I can troubleshoot this?

  • QFAN

    Tried the board_qc example, here’s the serial output:

    /*********
    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision 03
    SPI long test. Transfers 1MB of data. Each dot is 64K
    Test failed. Value written: 01 read: 00
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test
    *********/

    It seems that the UNO can get the die version , but cannot write or read data.

  • Alex

    hi oleg
    i have arduino mega2560 and arduino duemilanove and usb host shield
    usb host shield work perfect with arduino mega2560
    but
    i have problem with arduino duemilanove
    load board_qc
    in serial i receive

    Circuits At Home 2011
    USB Host Shield Quality Control Routine
    Reading REVISION register… Die revision invalid. Value returned: FF(or 00)
    Unrecoverable error – test halted!!
    0x55 pattern is transmitted via SPI
    Press RESET to restart test

    Usb.Init() return “-1”
    please help me
    i use last usb_host_shield_2.0 library and last arduino 1.0.3

  • Tuncay Cakmak

    Hey Oleg!

    Im really trying hard to understand the library but im still at the point that i can get the Data from one mouse on the Hub, i need to get the Data of a second mouse on the hub, plzzzzz can u help me?

    Best Regards
    Tuncay Cakmak

    • There is possibly a bug in the library affecting mice on a hub. I heard about it but can’t replicate it reliably. You could have a mouse affected by a bug.

      • Tuncay Cakmak

        Ok, hmm ill try to find out where it is, do i have to understand the whole library or have you a clou in which area of the library it could be? I found out that my Adresses of the Hub are 09, 0A, 0B, 0C, so i thought i could tell my Arduino that he shall check where mice are connected and then try to make a serial procedure that he gets first the data of mouse on 09 then the data on mouse on 0A for instance but im not good in programming microcontroller, first i have to understand which pins the usb uses and how the connection works, maybe u have some kind of tutorial for this? I need to understand how the communication between the USB Device and the Microcontroller works, are there digital signals on 1 input register or are there more input register involved? Thanks Oleg!!

  • Alessio Bianchetti

    Hi Oleg, I’m using the Sparkfun USB Host Shield (yes, I ordered before I saw circuitsathome) connected to a Arduino UNO Rev 3. I successfully got the quality test working with a USB Pen and a RFID Reader (actually “board_qc.pde”). I tested than the “USBHID_desc.pde” and at compiling time I got many many errors code (like expected classes and variables out of scope)…. I was wondering then how can I just read data from the USB Host shield? Something like read all data that passes through usb (RFID card codes)…

    • The easiest way would be to fix the compiler errors you’re having and use provided examples.

      • Alessio Bianchetti

        Now I fixed all the errors, and all the example runs fine. I have posted the output of USB_desc with my RFID Reader at the end. Now, some people said to me that what i want to do is impossible.. i want that when i pass a card through my rfid reader i can read the codes of that card (and do some operation). (I should have the drivers too somewhere). Thank you very much!
        Start

        01

        Device descriptor:
        Descriptor Length: 12
        Descriptor type: 01
        USB version: 0200
        Device class: 00
        Device Subclass: 00
        Device Protocol: 00
        Max.packet size: 08
        Vendor ID: 076B
        Product ID: 5321
        Revision ID: 0520
        Mfg.string index: 01
        Prod.string index: 02
        Serial number index: 05
        Number of conf.: 01

        Configuration descriptor:
        Total length: 005D
        Num.intf: 01
        Conf.value: 01
        Conf.string: 03
        Attr.: A0
        Max.pwr: 7D

        Interface descriptor:
        Intf.number: 00
        Alt.: 00
        Endpoints: 03
        Intf. Class: 0B
        Intf. Subclass: 00
        Intf. Protocol: 00
        Intf.string: 00
        Unknown descriptor:
        Length: 36
        Type: 21
        Contents: 0001000703000000C0120000401F000004002A0000E74C06006AFE0000000700000000000000B00301000F010000FFFF000000010705

        Endpoint descriptor:
        Endpoint address: 83
        Attr.: 03
        Max.pkt size: 0008
        Polling interval: 18

        Endpoint descriptor:
        Endpoint address: 84
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 00

        Endpoint descriptor:
        Endpoint address: 05
        Attr.: 02
        Max.pkt size: 0040
        Polling interval: 00

        Addr:1(0.0.1)

  • douwe

    Hi Oleg,

    I have an RFID-reader which behaves as an usb keyboard.
    When i connect it through your usb host shied and use the keyboard example it wont work; it outputs:
    Start
    BM Init
    Addr:1
    then nothing.. when i scan a card..

    When i use the HID_Descr example i get the following;

    Start
    HU Init
    Addr:1
    NC:1

    Cnf:1
    HU configured
    0000: 05 01 09 06 A1 01 05 07 19 E0 29 E7 15 00 25 01
    0010: 75 01 95 08 81 02 95 01 75 08 25 65 19 00 29 65
    0020: 81 00 C0
    Usage Page Gen Desktop Ctrls(01)
    Usage Keypad
    Collection Application
    Usage Page Kbrd/Keypad(07)
    Usage Min(E0)
    Usage Max(E7)
    Logical Min(00)
    Logical Max(01)
    Report Size(01)
    Report Count(08)
    Input(00000010)
    Report Count(01)
    Report Size(08)
    Logical Max(65)
    Usage Min(00)
    Usage Max(65)
    Input(00000000)
    End Collection

    When i scan a card it gives;
    Buf: 0027
    Keypad(00)(00)(00)(00)(00)(00)(00)(00)
    (27)

    Buf: 0000
    Keypad(00)(00)(00)(00)(00)(00)(00)(00)
    (00)

    When i use the rfid-stick directly on my mac i get the string: 0005138055

    can you give me any pointer why this doesn’t work?

    Regards,

    Douwe

    • Which shield are you using? In your e-mail you mentioned mini, is this correct? In this case you need to provide 5V to VBUS since mini has 3.3V there by default. See hardware manual for details.

  • Arvin

    Hey Oleg,

    The resources in the HID library are really comprehensive and super helpful for my task at hand!

    However, being a noob, I was getting stuck while compiling the code for the Keyboard.

    Can you look at the following errors and probably suggest what is going wrong?

    kbd_usb_passthrough:21: error: expected class-name before ‘{‘ token
    kbd_usb_passthrough.pde: In member function ‘void KbdRptParser::PrintKey(uint8_t, uint8_t)’:
    kbd_usb_passthrough:32: error: ‘MODIFIERKEYS’ was not declared in this scope
    kbd_usb_passthrough:32: error: expected `;’ before ‘mod’
    kbd_usb_passthrough:33: error: ‘mod’ was not declared in this scope
    kbd_usb_passthrough:40: error: ‘PrintHex’ was not declared in this scope
    kbd_usb_passthrough:40: error: expected primary-expression before ‘>’ token
    kbd_usb_passthrough.pde: In member function ‘virtual void KbdRptParser::OnKeyDown(uint8_t, uint8_t)’:
    kbd_usb_passthrough:53: error: ‘OemToAscii’ was not declared in this scope
    kbd_usb_passthrough.pde: At global scope:
    kbd_usb_passthrough:71: error: ‘USB’ does not name a type
    kbd_usb_passthrough:73: error: expected constructor, destructor, or type conversion before ‘<' token
    kbd_usb_passthrough.pde: In function 'void setup()':
    kbd_usb_passthrough:84: error: 'Usb' was not declared in this scope
    kbd_usb_passthrough:91: error: 'Keyboard' was not declared in this scope
    kbd_usb_passthrough:91: error: 'HIDReportParser' was not declared in this scope
    kbd_usb_passthrough:91: error: expected primary-expression before ')' token
    kbd_usb_passthrough.pde: In function 'void loop()':
    kbd_usb_passthrough:96: error: 'Usb' was not declared in this scope

    I really appreciate any help.

  • Gramuk

    I know this is going to sound real basic but I just got the USB host shield yesterday as I want to transmit MIDI over the USB shield (to a music keyboard which needs a host). I have not seen any examples of this direction of flow anywhere on-line and wondered if anyone has or know of a simple sketch example to transmit a simple note on / off command. After that then I could start to figure things out myself. Just this initial hint would be great.
    I’ve seen “Colins'” MIDI project (which I can’t get working due to compiler error anyway) – but they all read from a USB midi keyboard – they don’t appear to transmit and so am really stuck with what commands to use.. as you can tell – another newbie but learning fast – just need this last little bit to finish up the project.

  • L

    Is there any chance you could change the license to LGPL so it could be used in closed-source projects?

  • Louis

    Hi Oleg

    I was wondering when the “Mass Storage Devices – Flash Drives, USB sticks” etc example code would be available. It would be of great help to amateurs like me. I am trying for the past 4 months to get some kind of example or just a starting point for this. I have 3 of your shields, although I slightly damaged one when its smoke seal broke slight voltage spike followed by water due to a faulty ps. I would really appreciate any help and so would my friends that are attempting the same thing. You are the master. Master guide us your servants await πŸ™‚

  • Wilson

    Hi everybody

    Hi everybody,

    I’m doing a project with arduino and the telosb platform. I have to communicate them, and for this I bought a USB shield and is already work. But I just managed to send the data from telosb to arduino,and I have to send from arduino to telosb, so I need some help :/

    When I try to send a data through the usb shield, I only receives empty packets on telosb. I don’t know if the problem is the arduino shield’s code or the telosb’s code.

    I would like to know if I can send data in the sense arduino-telosb through the usb shield, because I just managed this through the serial pins without the shield.

    I apologize if my question is very simple, I’m new with the shield and C.

    If someone can help me, thanks in advance.

  • Kevin

    Hi Oleg,

    I’m playing a space sim (X3) that only recognizes one joystick. I was thinking about using a Teensy 3.0 combined with the USB host shield connected to a hub to act as a joystick ‘combiner’ which will take the axes and buttons from multiple joysticks and present them to Windows as a single controller.

    Does this seems like a feasible idea to you?

  • Hello Oleg,

    I’m attempting to use this library on an Arduino Mega ADK to read a USB keyboard and process the keystrokes in an existing application on the Arduino. I find that when I call Usb.Task(), it retains control until a key is pressed or a long time has passed, which is stopping the rest of the functionality on the Arduino. Is there a way to configure the library to have Usb.Task() return immediately if there is nothing to service on the USB port?

    Thanks!

    • I dug into this more and unless I hit a key, calls to Usb.Task() are not returning until the 5000 mS timeout passes. (I verified this by decreasing the timeout to 250 mS.) I’m also getting what appears to be exceptions or errors with “Poll:00” and “Poll:FF” being printed. I’m still investigating…

      • Please try the latest revision of the library on github – the bugfix has been pushed several hours ago. I actually thought it was you commenting on github so I didn’t answer to your original comment here.

  • Guy

    I could use a little guidance. I’m trying to connect a Mega ADK to a USB ELM327 OBD II cable/adapter and I’m not quite sure how to go about this. I have verified the ELM device works fine when connected to a PC with a terminal program, and it basically responds to simple ASCII commands like β€œATZ\r” which resets the device and responds with an ASCII string like β€œelm327 1.3b”. What would be a good example sketch to use as a starting point using the Mega ADK? I tried a modified test_term program after installing the shield host 2.0 library (modified for ADK), but it gets stuck in adk.isReady() = false. Am I going about this wrong? I’m not that familiar with USB type devices, so I don’t know if it’s HID, FTDI, etc… Thanks.