Shopping Cart

Posts

USB Host Shield 2.0 released

USB Host 2.0 connected to Arduino Mega 2560

USB Host 2.0 connected to Arduino Mega 2560

A major revision of USB Host Shield for Arduino has been released and is available in the store. The board’s improved layout makes this shield compatible with more Arduinos, makes it easier to use and opens new possibilities. The main differences from rev.1xx are outlined below:

  1. The SPI interface has been moved to ICSP header making shield compatible out of the box with “big” Arduinos – Mega and 2560. Standard size boards, such as Duemilanove, UNO, as well as clones with classic connector layout, are also compatible with this revision of the shield. This compatibility is maintained on a software level as well – all necessary code changes are performed using conditional compilation preprocessor directives.
  2. USB connector has been moved to the opposite side of the board. All external connectors are now in the same place making enclosure layout easier.
  3. MAX3421E RESET line is no longer handled by dedicated Arduino pin. While MAX_RESET pin is still used in current version of USB Host library, it will be dropped from the next major revision of the code.
USB Host Shield 2.0 with AVR Dragon

USB Host Shield 2.0 with AVR Dragon

Besides “Mega-formfactor” compatibility, connecting to Arduino SPI signals on ICSP connector has several advantages. First of all, in this layout traces are much shorter and as a result, the shield works more reliably at higher SPI speeds and/or larger signal and power noise. Second, since the 2X3 connector, which comes bundled with the shield, is of ‘stackable’ variety, it is possible to connect AVR Dragon or other ICSP programmer to Arduino while USB Host Shield is mounted – picture on the left shows the arrangement. Finally, pins 11-13, occupied by SPI signals on “classic” Arduinos, are vacant on Megas and also uncommitted on the shield. Therefore, they can be used for other purposes without USB library code modifications.

The shield comes in 2 configurations. One, called “Standard” is compatible with official full-size Arduino boards (Duemilanove, UNO, Mega, Mega 2560, and possibly others), as well as clones which supply both 3.3V and 5V to the shield. One example of such clone is BlackWidow; if you are aware about other compatible clones, please let me know.

Another configuration, called “3.3V” is designed for battery-operated projects. It is compatible with Sparkfun’s Arduino Pro 3.3V board (I’m not aware of any other 3.3V-only full-size clones). It also supplies 3.3V to VBUS instead of spec’d 5V, therefore some bus-powered devices may function erratically (but not necessarily; I actually use bus-powered USB flash drive during final testing of production 3.3V shields). Self-powered devices, such as digital cameras, usually don’t care about VBUS voltage at all. Additionally, board layout makes it possible to mount external power supplies to generate 5V from 3.3V and vice versa, if necessary.

The shield is compatible with current version of USB library. It is also very similar to rev.1.xx shield and information from previously posted articles is mostly valid for 2.0 board. Schematic and Eagle CAD files are also available for download. I am currently working on detailed description of the shield and hoping to get it ready in a week or two.

Along with this shield I will continue producing rev.1.21 board – there are still “not-so-compatible” Arduino clones around. However, next major revision of USB library will not be compatible with rev.1xx shields; it will be possible to make it work after minor hardware/software modifications.

As always, your questions and comments about the product are welcome and appreciated.

Oleg.

Related posts:

  1. Arduino USB Host Shield build log. Part 1.
  2. Arduino USB Host Shield build log. Part 4.
  3. Arduino USB Host Shield build log. Part 3.
  4. USB Host Shield for Arduino – first prototype.
  5. Arduino USB Host Shield build log. Part 2.
  6. Towards an FT232 Driver for the USB Host Shield- Part 0
  7. Troubleshooting Arduino USB Host Shield
  8. Next revision of USB Host Shield goes to production
  9. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 3
  10. PS3 and Wiimote Game Controllers on the Arduino Host Shield: Part 1

87 comments to USB Host Shield 2.0 released

  • karsten

    Hello Oleg,

    does the statement “next major revision of USB library will not be compatible with rev.1xx shields” affect the mini shield as well?

  • RedGuy

    Hello Oleg,

    I’m trying to use a USB trackpad (Bamboo Touch) with your USB Host Shield (rev 1.21), but there is a type 5 Mouse polling error when I try to connect. Is this because the device is not recognized? If so, do you know how to mitigate this?

    Thanks,

  • RedGuy

    Hello,

    Update: I got a response when I used your
    /* Mouse communication via interrupt endpoint */ /* Assumes EP1 as interrupt IN ep */
    code (the second in the above link); sorry for not checking sooner.

  • RedGuy

    Hello Oleg,

    Currently, I’m able to run both a USB mouse and USB trackpad, but only in separate sketches.

    When using the control endpoint method, the mouse works but the trackpad returns a type 5 error (stall)
    When using the interrupt endpoint method, the trackpad workds, but the mouse returns a type 5 error

    It’s unusual that the device doesn’t support the request in one sketch but not the other…

    I looked at the device descriptors, and both devices are recognized:

    ==== FOR THE TRACKPAD ====

    Device addressed… Requesting device descriptor.
    Device descriptor:

    Descriptor Length: 12
    USB version: 2.0
    Class: 00 Use class information in the Interface Descriptor
    Subclass: 00
    Protocol: 00
    Max.packet size: 40
    Vendor ID: 056A
    Product ID: 00D0
    Revision ID: 0106
    Mfg.string index: 01 Length: 30 Contents: Wacom Co.,Ltd.
    Prod.string index: 02 Length: 16 Contents: CTT-460
    Serial number index: 00
    Number of conf.: 01

    Configuration number 0
    Total configuration length: 59 bytes

    Configuration descriptor:
    Total length: 003B
    Number of interfaces: 02
    Configuration value: 01
    Configuration string: 00
    Attributes: 80
    Max.power: 31 98ma

    Interface descriptor:
    Interface number: 00
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 01
    Protocol: 02
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.0
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:176 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 02
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 01
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
    Length: 1 Type: Global Tag: Usage Page Button Data: 09
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 05
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 05
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 03
    Length: 1 Type: Main Tag: Input Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 30
    Length: 1 Type: Local Tag: Usage Data: 31
    Length: 1 Type: Global Tag: Logical Minimum Data: 81
    Length: 1 Type: Global Tag: Logical Maximum Data: 7F
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Report Count Data: 02
    Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
    Length: 0 Type: Main Tag: End Collection
    Length: 0 Type: Main Tag: End Collection
    Length: 1 Type: Global Tag: Usage Page Digitizer Data: 0D
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 02
    Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
    Length: 2 Type: Global Tag: Usage Page Undefined Data: 00 Data: FF
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 2 Type: Global Tag: Logical Maximum Data: FF Data: 00
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Report Count Data: 08
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 0 Type: Main Tag: End Collection
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 03
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 04
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 05
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 10
    Length: 1 Type: Global Tag: Report Count Data: 02
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 11
    Length: 1 Type: Global Tag: Report Count Data: 10
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 13
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 20
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 21
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 06
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 07
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 14
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 0 Type: Main Tag: End Collection

    Endpoint descriptor:
    Endpoint address: 01 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0009
    Polling interval: 04 4 ms

    Interface descriptor:
    Interface number: 01
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 00
    Protocol: 00
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.0
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:75 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 02
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 01
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
    Length: 1 Type: Global Tag: Usage Page Button Data: 09
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 05
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 05
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 03
    Length: 1 Type: Main Tag: Input Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 30
    Length: 1 Type: Local Tag: Usage Data: 31
    Length: 1 Type: Global Tag: Logical Minimum Data: 81
    Length: 1 Type: Global Tag: Logical Maximum Data: 7F
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Report Count Data: 02
    Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
    Length: 0 Type: Main Tag: End Collection
    Length: 0 Type: Main Tag: End Collection
    Length: 1 Type: Global Tag: Usage Page Digitizer Data: 0D
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Report ID Data: 02
    Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
    Length: 2 Type: Global Tag: Usage Page Undefined Data: 00 Data: FF
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 2 Type: Global Tag: Logical Maximum Data: FF Data: 00
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Report Count

    Endpoint descriptor:
    Endpoint address: 02 Direction: IN

    ==== FOR THE MOUSE ====

    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: 08
    Vendor ID: 045E
    Product ID: 0040
    Revision ID: 0300
    Mfg.string index: 01 Length: 20 Contents: Microsoft
    Prod.string index: 03 Length: 90 Contents: Microsoft 3-Button Mouse with IntelliEye(TM)
    Serial number index: 00
    Number of conf.: 01

    Configuration number 0
    Total configuration length: 34 bytes

    Configuration descriptor:
    Total length: 0022
    Number of interfaces: 01
    Configuration value: 01
    Configuration string: 00
    Attributes: A0 Remote Wakeup
    Max.power: 32 100ma

    Interface descriptor:
    Interface number: 00
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 01
    Protocol: 02
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.10
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:72 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 02
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Local Tag: Usage Data: 01
    Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
    Length: 1 Type: Global Tag: Usage Page Button Data: 09
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 03
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 03
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Size Data: 05
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Input Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 30
    Length: 1 Type: Local Tag: Usage Data: 31
    Length: 1 Type: Local Tag: Usage Data: 38
    Length: 1 Type: Global Tag: Logical Minimum Data: 81
    Length: 1 Type: Global Tag: Logical Maximum Data: 7F
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Report Count Data: 03
    Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
    Length: 0 Type: Main Tag: End Collection
    Length: 1 Type: Global Tag: Usage Page Data: FF
    Length: 1 Type: Local Tag: Usage Data: 02
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,No preferred,No Null Position,Non-volatile(Ignore for Input), Data: 22
    Length: 1 Type: Global Tag: Report Size Data: 07
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Main Tag: Feature Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 0 Type: Main Tag: End Collection

    Endpoint descriptor:
    Endpoint address: 01 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0004
    Polling interval: 0A 10 ms

    Any ideas? Thanks again for your help thus far. It’s much appreciated.

  • The trackpad has several reports and consequently several report IDs in HID report while mouse has only one report and therefore doesn’t use report IDs. When polling via control endpoint, you need to either specify report ID which you are requesting, or use “0″ for report ID parameter when no report IDs are used. That’s why sketch works for mouse and doesn’t work for the trackpad – you need change report ID 0 to an actual report ID in “rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );” function call.

    When polling interrupt endpoint, you can’t specify report ID and are simply getting whatever reports are available at the moment. That’s why interrupt polling works with trackpad. I’m yet to find out why it’s not working with a mouse – I’ll keep looking.

  • RedGuy

    Hello again,

    I’ve been playing with the host shield (rev1.21) a bit more, and have been having issues running certain mice but not others. I’ve tried with 5 or so different models of mice, and have only had luck with 1. The only remarkable difference is that the HID version for the mouse that works is 1.10, while that of the mice that don’t work is either 1.0 or 1.11. The data packet size is 8 for all these mice, and the USB version is either 2.0 or 1.10.

    I’ve been using the control endpoint sketch, because as I mentioned, I’m unable to get mice working with the interrupt endpoint method. All the report descriptors for these mice are quite similar; the error involved is usually a stall. In the case of wireless USB mice, the serial monitor crashes entirely after returning many stall errors.

    Do you have any idea how the HID version could influence the workings of different mice? Also, are extra drivers required to support wireless USB mice?

    Thanks,

    • By USB spec, HID mouse must answer on interrupt endpoint. Can you send me your whole sketch – I’d like to take a look?

      • RedGuy

        Hello,

        I was using your control endpoint sketch. This allowed me to use only 1 variety of USB Mouse (HID Version 1.10):

        /* Mouse communication via control endpoint */
        #include
        #include
        #include

        #define DEVADDR 1
        #define CONFVALUE 1
        #define ledPin 2 // added

        void setup();
        void loop();

        MAX3421E Max;
        USB Usb;

        void setup()
        {
        pinMode(ledPin, OUTPUT); // added
        Serial.begin( 115200 );
        Serial.println(“Start”);
        Max.powerOn();
        delay( 200 );
        }

        void loop()
        {
        byte rcode;
        Max.Task();
        Usb.Task();
        if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
        mouse0_init();
        }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING…
        if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
        rcode = mouse0_poll();
        if( rcode ) {
        Serial.print(“Mouse Poll Error: “);
        Serial.println( rcode, HEX );
        }//if( rcode…
        }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING…
        }
        /* Initialize mouse */
        void mouse0_init( void )
        {
        byte rcode = 0; //return code
        /**/
        Usb.setDevTableEntry( 1, Usb.getDevTableEntry( 0,0 ) ); //copy device 0 endpoint information to device 1
        /* Configure device */
        rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
        if( rcode ) {
        Serial.print(“Error configuring mouse. Return code : “);
        Serial.println( rcode, HEX );
        while(1); //stop
        }//if( rcode…
        Usb.setUsbTaskState( USB_STATE_RUNNING );
        return;
        }
        /* Poll mouse using Get Report and print result */
        byte mouse0_poll( void )
        {
        byte rcode,i;
        char buf[ 4 ] = { 0 }; //mouse buffer
        static char old_buf[ 4 ] = { 0 }; //last poll
        /* poll mouse */
        rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
        if( rcode ) { //error
        return( rcode );
        }
        for( i = 0; i < 4; i++) { //check for new information
        if( buf[ i ] != old_buf[ i ] ) { //new info in buffer
        break;
        }
        }
        if( i == 4 ) {
        return( 0 ); //all bytes are the same
        }
        /* print buffer */
        if( buf[ 0 ] & 0×01 ) {
        Serial.print("Button1 pressed ");
        digitalWrite(ledPin, HIGH); // added from here…
        delay( 20 );
        digitalWrite(ledPin, LOW); // … to here
        }
        if( buf[ 0 ] & 0×02 ) {
        Serial.print("Button2 pressed ");
        }
        if( buf[ 0 ] & 0×04 ) {
        Serial.print("Button3 pressed ");
        }
        Serial.println("");
        Serial.print("X-axis: ");
        Serial.println( buf[ 1 ], DEC);
        Serial.print("Y-axis: ");
        Serial.println( buf[ 2 ], DEC);
        Serial.print("Wheel: ");
        Serial.println( buf[ 3 ], DEC);
        for( i = 0; i < 4; i++ ) {
        old_buf[ i ] = buf[ i ]; //copy buffer
        }
        Serial.println("");
        return( rcode );
        }

        I haven't changed anything from what you suggested. Here is a report descriptor for the mouse that does work. I obtained it using your report parser:

        ==== WORKING MOUSE DESCRIPTOR ====

        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: 08
        Vendor ID: 045E
        Product ID: 0040
        Revision ID: 0300
        Mfg.string index: 01 Length: 20 Contents: Microsoft
        Prod.string index: 03 Length: 90 Contents: Microsoft 3-Button Mouse with IntelliEye(TM)
        Serial number index: 00
        Number of conf.: 01

        Configuration number 0
        Total configuration length: 34 bytes

        Configuration descriptor:
        Total length: 0022
        Number of interfaces: 01
        Configuration value: 01
        Configuration string: 00
        Attributes: A0 Remote Wakeup
        Max.power: 32 100ma

        Interface descriptor:
        Interface number: 00
        Alternate setting: 00
        Endpoints: 01
        Class: 03 HID (Human Interface Device)
        Subclass: 01
        Protocol: 02
        Interface string: 00

        HID descriptor:
        Descriptor length: 09 9 bytes
        HID version: 1.10
        Country Code: 0 Not Supported
        Class Descriptors: 1
        Class Descriptor Type: 22 Report
        Class Descriptor Length:72 bytes

        HID report descriptor:

        Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
        Length: 1 Type: Local Tag: Usage Data: 02
        Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
        Length: 1 Type: Local Tag: Usage Data: 01
        Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
        Length: 1 Type: Global Tag: Usage Page Button Data: 09
        Length: 1 Type: Local Tag: Usage Minimum Data: 01
        Length: 1 Type: Local Tag: Usage Maximum Data: 03
        Length: 1 Type: Global Tag: Logical Minimum Data: 00
        Length: 1 Type: Global Tag: Logical Maximum Data: 01
        Length: 1 Type: Global Tag: Report Size Data: 01
        Length: 1 Type: Global Tag: Report Count Data: 03
        Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
        Length: 1 Type: Global Tag: Report Size Data: 05
        Length: 1 Type: Global Tag: Report Count Data: 01
        Length: 1 Type: Main Tag: Input Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
        Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
        Length: 1 Type: Local Tag: Usage Data: 30
        Length: 1 Type: Local Tag: Usage Data: 31
        Length: 1 Type: Local Tag: Usage Data: 38
        Length: 1 Type: Global Tag: Logical Minimum Data: 81
        Length: 1 Type: Global Tag: Logical Maximum Data: 7F
        Length: 1 Type: Global Tag: Report Size Data: 08
        Length: 1 Type: Global Tag: Report Count Data: 03
        Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
        Length: 0 Type: Main Tag: End Collection
        Length: 1 Type: Global Tag: Usage Page Data: FF
        Length: 1 Type: Local Tag: Usage Data: 02
        Length: 1 Type: Global Tag: Logical Minimum Data: 00
        Length: 1 Type: Global Tag: Logical Maximum Data: 01
        Length: 1 Type: Global Tag: Report Size Data: 01
        Length: 1 Type: Global Tag: Report Count Data: 01
        Length: 1 Type: Main Tag: Feature Data,Variable,Absolute,No Wrap,Linear,No preferred,No Null Position,Non-volatile(Ignore for Input), Data: 22
        Length: 1 Type: Global Tag: Report Size Data: 07
        Length: 1 Type: Global Tag: Report Count Data: 01
        Length: 1 Type: Main Tag: Feature Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
        Length: 0 Type: Main Tag: End Collection

        Endpoint descriptor:
        Endpoint address: 01 Direction: IN
        Attributes: 03 Transfer type: Interrupt
        Max.packet size: 0004
        Polling interval: 0A 10 ms

        Here is a descriptor for a mouse that doesn't work:

        ==== NON-WORKING MOUSE DESCRIPTOR ====

        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: 08
        Vendor ID: 045E
        Product ID: 00CB
        Revision ID: 0104
        Mfg.string index: 01 Length: 22 Contents: Microsoft
        Prod.string index: 02 Length: 72 Contents: Microsoft Basic Optical Mouse v2.0
        Serial number index: 00
        Number of conf.: 01

        Configuration number 0
        Total configuration length: 34 bytes

        Configuration descriptor:
        Total length: 0022
        Number of interfaces: 01
        Configuration value: 01
        Configuration string: 04 Length: 40 Contents: HID-compliant MOUSE
        Attributes: A0 Remote Wakeup
        Max.power: 32 100ma

        Interface descriptor:
        Interface number: 00
        Alternate setting: 00
        Endpoints: 01
        Class: 03 HID (Human Interface Device)
        Subclass: 01
        Protocol: 02
        Interface string: 00

        HID descriptor:
        Descriptor length: 09 9 bytes
        HID version: 1.11
        Country Code: 0 Not Supported
        Class Descriptors: 1
        Class Descriptor Type: 22 Report
        Class Descriptor Length:62 bytes

        HID report descriptor:

        Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
        Length: 1 Type: Local Tag: Usage Data: 02
        Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
        Length: 1 Type: Global Tag: Usage Page Button Data: 09
        Length: 1 Type: Local Tag: Usage Minimum Data: 01
        Length: 1 Type: Local Tag: Usage Maximum Data: 03
        Length: 1 Type: Global Tag: Logical Minimum Data: 00
        Length: 1 Type: Global Tag: Logical Maximum Data: 01
        Length: 1 Type: Global Tag: Report Count Data: 03
        Length: 1 Type: Global Tag: Report Size Data: 01
        Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
        Length: 1 Type: Global Tag: Report Count Data: 01
        Length: 1 Type: Global Tag: Report Size Data: 05
        Length: 1 Type: Main Tag: Input Constant,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 03
        Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
        Length: 1 Type: Local Tag: Usage Data: 01
        Length: 1 Type: Main Tag: Collection Physical (group of axes) Data: 00
        Length: 1 Type: Local Tag: Usage Data: 30
        Length: 1 Type: Local Tag: Usage Data: 31
        Length: 1 Type: Global Tag: Logical Minimum Data: 81
        Length: 1 Type: Global Tag: Logical Maximum Data: 7F
        Length: 1 Type: Global Tag: Report Size Data: 08
        Length: 1 Type: Global Tag: Report Count Data: 02
        Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
        Length: 0 Type: Main Tag: End Collection
        Length: 1 Type: Local Tag: Usage Data: 38
        Length: 1 Type: Global Tag: Logical Minimum Data: 81
        Length: 1 Type: Global Tag: Logical Maximum Data: 7F
        Length: 1 Type: Global Tag: Report Size Data: 08
        Length: 1 Type: Global Tag: Report Count Data: 01
        Length: 1 Type: Main Tag: Input Data,Variable,Relative,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 06
        Length: 0 Type: Main Tag: End Collection

        Endpoint descriptor:
        Endpoint address: 01 Direction: IN
        Attributes: 03 Transfer type: Interrupt
        Max.packet size: 0004
        Polling interval: 0A 10 ms

        Lastly, the sketch for the interrupt endpoint is also the same as on your page, but doesn't work:

        /* Mouse communication via interrupt endpoint */
        /* Assumes EP1 as interrupt IN ep */
        #include
        #include
        #include

        #define DEVADDR 1
        #define CONFVALUE 1
        #define EP_MAXPKTSIZE 5
        EP_RECORD ep_record[ 2 ]; //endpoint record structure for the mouse

        void setup();
        void loop();

        MAX3421E Max;
        USB Usb;

        void setup()
        {
        Serial.begin( 115200 );
        Serial.println(“Start”);
        Max.powerOn();
        delay( 200 );
        }

        void loop()
        {
        byte rcode;
        Max.Task();
        Usb.Task();
        if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
        mouse1_init();
        }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING…
        if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
        rcode = mouse1_poll();
        if( rcode ) {
        Serial.print(“Mouse Poll Error: “);
        Serial.println( rcode, HEX );
        }//if( rcode…
        }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING…
        }
        /* Initialize mouse */
        void mouse1_init( void )
        {
        byte rcode = 0; //return code
        byte tmpdata;
        byte* byte_ptr = &tmpdata;
        /**/
        ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters
        ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
        ep_record[ 1 ].sndToggle = bmSNDTOG0;
        ep_record[ 1 ].rcvToggle = bmRCVTOG0;
        Usb.setDevTableEntry( 1, ep_record ); //plug kbd.endpoint parameters to devtable
        /* Configure device */
        rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
        if( rcode ) {
        Serial.print(“Error configuring mouse. Return code : “);
        Serial.println( rcode, HEX );
        while(1); //stop
        }//if( rcode…
        rcode = Usb.getIdle( DEVADDR, 0, 0, 0, (char *)byte_ptr );
        if( rcode ) {
        Serial.print(“Get Idle error. Return code : “);
        Serial.println( rcode, HEX );
        while(1); //stop
        }
        Serial.print(“Idle Rate: “);
        Serial.print(( tmpdata * 4 ), DEC ); //rate is returned in multiples of 4ms
        Serial.println(” ms”);
        tmpdata = 0;
        rcode = Usb.setIdle( DEVADDR, 0, 0, 0, tmpdata );
        if( rcode ) {
        Serial.print(“Set Idle error. Return code : “);
        Serial.println( rcode, HEX );
        while(1); //stop
        }
        Usb.setUsbTaskState( USB_STATE_RUNNING );
        return;
        }
        /* Poll mouse via interrupt endpoint and print result */
        /* assumes EP1 as interrupt endpoint */
        byte mouse1_poll( void )
        {
        byte rcode,i;
        char buf[ 4 ] = { 0 }; //mouse report buffer
        /* poll mouse */
        rcode = Usb.inTransfer( DEVADDR, 1, 4, buf, 1 ); //
        //rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
        if( rcode ) { //error
        if( rcode == 0×04 ) { //NAK
        rcode = 0;
        }
        return( rcode );
        }
        /* print buffer */
        if( buf[ 0 ] & 0×01 ) {
        Serial.print(“Button1 pressed “);
        }
        if( buf[ 0 ] & 0×02 ) {
        Serial.print(“Button2 pressed “);
        }
        if( buf[ 0 ] & 0×04 ) {
        Serial.print(“Button3 pressed “);
        }
        Serial.println(“”);
        Serial.print(“X-axis: “);
        Serial.println( buf[ 1 ], DEC);
        Serial.print(“Y-axis: “);
        Serial.println( buf[ 2 ], DEC);
        Serial.print(“Wheel: “);
        Serial.println( buf[ 3 ], DEC);
        Serial.println(“”);
        return( rcode );
        }

        As I mentioned, the interrupt endpoint method doesn’t work with any USB mouse. The error is usually:

        Start
        Data Packet Error: 5Get Idle Error. Return code: 5

        OR

        Setup Packet Error: DError configuring mouse. Return Code: D

        D means “JERR” which I haven’t been able to figure out.

        • In interrupt sketch, change EP_MAXPKTSIZE from 5 to 4 and see if your mouse starts working

          • RedGuy

            Hello,

            I’d tried that previously with no luck. If I change EP_MAXPKTSIZE from 5 to 4 in the interrupt sketch:

            For the mouse with HID Version 1.10:

            Start
            Data packet error: 5Get Idle error. Return code : 5

            For the mouse with HID Version 1.0:

            Start
            Setup packet error: DError configuring mouse. Return code : D

          • Also,

            Are you getting

            Start
            Idle Rate: 0 ms

            when you start interrupt sketch?

          • I think I found the issue. Microsoft mouse returns Stall to GetIdle/SetIdle commands. The sketch stops on any error. Do this: find all while(1); //stop lines (should be 3, on line 60, 66 and 76 in interrupt sketch listing on this page -> http://www.circuitsathome.com/communicating-arduino-with-hid-devices-part-1 ) and comment them out. You will still be getting errors but sketch will continue and eventually you will see this:


            Start
            Data packet error: 5Get Idle error. Return code : 5
            Idle Rate: 512 ms
            Set Idle error. Return code : 5
            Button1 pressed
            X-axis: 0
            Y-axis: -1
            Wheel: 2

            Button1 pressed
            X-axis: 0
            Y-axis: -1
            Wheel: 0

            Button1 pressed
            X-axis: 0
            Y-axis: -1
            Wheel: 3

            You will need to move your mouse to see reports.

            Let me know if this helped.

          • This is odd – I’ve tested many different mice and none of them behaved like yours. Can you give me make/models of your mice and where you got them – I’ll try to source one locally and check on my system?

  • RedGuy

    Hello,

    Commenting out the while(1) did the trick. I’m now able to read every mouse, and the trackpad, all from the interrupt endpoint sketch! Thank you very much for your assistance, Oleg. You’ve helped paved the way forward.

    Here are the models I have been testing with:

    o RocketFish Nano Laptop Optical Mouse (wireless USB)
    o Logitech M570 Trackball Mouse (wireless USB)
    o Microsoft IntelliMouse Optical USB and PS/2 Compatible (Wired)
    o Microsoft Ready Mouse (Basic Optical, Wired)
    o Microsoft Wheel Mouse Optical 1.1A USB and PS/2 Compatible (Wired)

    The wired mice buttons are all interpreted the same way (left click is button 1, right click is button 2) but the wireless mouse has a different mapping of inputs (button 1 corresponds to one of the optical sensors instead). I’ll probably build a condition into my final sketch to identify the device and act accordingly.

    Interestingly, the Logitech wireless trackball I mentioned above gives no response to the interrupt method, nor is it detected in the control endpoint sketch. Here is the response:

    Start
    Idle Rate: 500 ms
    … nothing happens after this point. Clicking, re-starting, re-plugging in the dongle, etc. has not worked.

    I have increased the max packet size to both 8 and 0020 (0008 will not compile) to try and accommodate a larger bandwith, but that hasn’t worked.

    ==== TRACKBALL DESCRIPTOR ====

    Start
    Device addressed… Requesting device descriptor.
    Device descriptor:

    Descriptor Length: 12
    USB version: 2.0
    Class: 00 Use class information in the Interface Descriptor
    Subclass: 00
    Protocol: 00
    Max.packet size: 08
    Vendor ID: 046D
    Product ID: C52B
    Revision ID: 1201
    Mfg.string index: 01 Length: 18 Contents: Logitech
    Prod.string index: 02 Length: 26 Contents: USB Receiver
    Serial number index: 00
    Number of conf.: 01

    Configuration number 0
    Total configuration length: 84 bytes

    Configuration descriptor:
    Total length: 0054
    Number of interfaces: 03
    Configuration value: 01
    Configuration string: 04 Length: 30 Contents: RQR12.01_B0019
    Attributes: A0 Remote Wakeup
    Max.power: 31 98ma

    Interface descriptor:
    Interface number: 00
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 01
    Protocol: 01
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.11
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:59 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 06
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: E0
    Length: 1 Type: Local Tag: Usage Maximum Data: E7
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 08
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Main Tag: Input Constant,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 03
    Length: 1 Type: Global Tag: Report Count Data: 05
    Length: 1 Type: Global Tag: Usage Page LEDs Data: 08
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 05
    Length: 1 Type: Main Tag: Output Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 03
    Length: 1 Type: Main Tag: Output Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 06
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 2 Type: Global Tag: Logical Maximum Data: A4 Data: 00
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: 00
    Length: 2 Type: Local Tag: Usage Maximum Data: A4 Data: 00
    Length: 1 Type: Main Tag: Input Data,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 00
    Length: 0 Type: Main Tag: End Collection

    Endpoint descriptor:
    Endpoint address: 01 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0008
    Polling interval: 08 8 ms

    Interface descriptor:
    Interface number: 01
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 01
    Protocol: 02
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.11
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:148 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 06
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: E0
    Length: 1 Type: Local Tag: Usage Maximum Data: E7
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 08
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Main Tag: Input Constant,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 03
    Length: 1 Type: Global Tag: Report Count Data: 05
    Length: 1 Type: Global Tag: Usage Page LEDs Data: 08
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 05
    Length: 1 Type: Main Tag: Output Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 03
    Length: 1 Type: Main Tag: Output Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 06
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 2 Type: Global Tag: Logical Maximum Data: A4 Data: 00
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: 00
    Length: 2 Type: Local Tag: Usage Maximum Data: A4 Data: 00
    Length: 1 Type: Main Tag: Input Data,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 00
    Length: 0 Type: Main Tag: End Collection

    Endpoint descriptor:
    Endpoint address: 02 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0008
    Polling interval: 02 2 ms

    Interface descriptor:
    Interface number: 02
    Alternate setting: 00
    Endpoints: 01
    Class: 03 HID (Human Interface Device)
    Subclass: 00
    Protocol: 00
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.11
    Country Code: 0 Not Supported
    Class Descriptors: 1
    Class Descriptor Type: 22 Report
    Class Descriptor Length:98 bytes

    HID report descriptor:

    Length: 1 Type: Global Tag: Usage Page Generic Desktop Controls Data: 01
    Length: 1 Type: Local Tag: Usage Data: 06
    Length: 1 Type: Main Tag: Collection Application (mouse, keyboard) Data: 01
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: E0
    Length: 1 Type: Local Tag: Usage Maximum Data: E7
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 1 Type: Global Tag: Logical Maximum Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 08
    Length: 1 Type: Main Tag: Input Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Main Tag: Input Constant,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 03
    Length: 1 Type: Global Tag: Report Count Data: 05
    Length: 1 Type: Global Tag: Usage Page LEDs Data: 08
    Length: 1 Type: Local Tag: Usage Minimum Data: 01
    Length: 1 Type: Local Tag: Usage Maximum Data: 05
    Length: 1 Type: Main Tag: Output Data,Variable,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 02
    Length: 1 Type: Global Tag: Report Count Data: 01
    Length: 1 Type: Global Tag: Report Size Data: 03
    Length: 1 Type: Main Tag: Output Constant,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 01
    Length: 1 Type: Global Tag: Report Count Data: 06
    Length: 1 Type: Global Tag: Report Size Data: 08
    Length: 1 Type: Global Tag: Logical Minimum Data: 00
    Length: 2 Type: Global Tag: Logical Maximum Data: A4 Data: 00
    Length: 1 Type: Global Tag: Usage Page Keyboard/Keypad Data: 07
    Length: 1 Type: Local Tag: Usage Minimum Data: 00
    Length: 2 Type: Local Tag: Usage Maximum Data: A4 Data: 00
    Length: 1 Type: Main Tag: Input Data,Array,Absolute,No Wrap,Linear,Preferred State,No Null Position,Non-volatile(Ignore for Input), Data: 00
    Length: 0 Type: Main Tag: End Collection

    Endpoint descriptor:
    Endpoint address: 03 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 02 2 ms

    Just food for thought, I suppose.

    Lastly, I’ll be porting your Simple USB Shield design onto a new layout within a week or so. We’ve identified the necessary components for its operation, and plan to incorporate your design into a larger PCB to acommodate binary switch inputs and the like. Would you be alright with reviewing our changes and providing your input? My team and I would be very appreciative of your expertise.

    Thank you once again for your help thus far.

  • I have connected a mouse to the USB Host shield and when I run the code from http://www.circuitsathome.com/communicating-arduino-with-hid-devices-part-1 I get the error

    Mouse poll 4.

    Any idea why it is happening and any way to fix it?

    • There are two sketches on this page – which one you are referring to? Have you tried to move your mouse at all? 4 means NAK, it happens when no new data is available. Also, which shield variant are you using?

      • I am using the first sketch that was present in that page. Yes I tried moving the mouse and also tried clicking the buttons, but I kept on getting the same error.

        I am using the USB Host shield from Sparkfun with has the pins swapped. http://www.sparkfun.com/products/9628

        But I have made the following changes before proceeding.

        #define MAX_GPX 7
        #define MAX_RESET 8

        • Okay I found an interesting thing happening. If I don’t mouse the error, then I am getting the error Mouse Poll error: 4, which you explained as NAK.

          But when I try to move the mouse or click a button, I get a different error. The new error is “Data package error: E followed by Mouse Poll Error E”.

        • I’m not familiar with Sparkfun shield but I heard there are power issues – you may want to read comments on their product page.

  • João Gomes

    Hello Oleg

    Following your suggestion and forgetting Ligthweigth_USB for PIC, I’m trying to take the logic of this code and the MicroBridge application that is written in C.

    My goal is to read pendrive. When trying to run the sequence GET_MAX_LUN, UNITY_READY, SENSE_INFO, READ_CAPACITY and INQUIRE to establish the Mass Storage Device the error 0x0D appears in the first step.

    This error and much talked about in various forums and no solution is available.

    The first step GET_MAX_LUN for Mass Storage Device Class, I inserted into the case (USB_STATE_CONFIGURING).

    Is it possible for you to indicate someone or some place that has treated the Mass Storage Device with this library for MAX3421.

    Thanks

    JGomes

    • You can’t issue mass storage commands before device is configured. Error 0x0d happens when device doesn’t understand what’s being sent to it and caused by either incorrect data or bad power. The solution is to program correctly and make sure adequate power is provided to VBUS.

      I saw some mass storage code for my shield posted on old Arduino forum. Microchip also has mass storage code in its’ USB stack – it is not really controller-specific.

  • Roger Howard

    Are the extra row of pin holes along the digital and analog pin rows already connected to the main row, to use as pass-throughs for the unused digital/analog pins from the Arduino below?

  • krulkip

    Hallo Oleg,

    I am trying to make a USB mail notifier work using your USB host shield.
    http://www.dreamcheeky.com/webmail-notifier
    It seems straight forward but somehow i can not get it to work.
    I need to send report ID 00 to the unit to innitiate it and to get it to change its RGB led.
    The innitiation codes are:
    msg1[7] = { 0x1F, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×03 };
    msg2[7] = { 0×00, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×04 };
    Then you send the colour code eg:
    msg3[7] = { 0xFF, 0xFF, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };
    The first three bytes are the brightness and colour coding. RR GG BB. I think it has 0x3F brightness as higher values do not increase the brightness.
    How do you send this data to the unit. I have tried outTransfer but am not sure how to use.
    I know the USB host works because i can read the RFID codes from the Violet Mirror RFID device.
    I know the mail notifier works because i can switch it using simpleHIDWrite from http://www.lvr.com/hidpage.htm

  • krulkip

    Thank you Oleg,

    Its now working and here is the code. Its just a simple program to light up the RGB LED in the different basic colours.
    Now to find something usefull to do with it. :-) As you can see i did use the setReport function as you had done in the keyboard example.
    I still dont understand anything about USB though. eg why does the setConf require the 0x1F conf_value and still require the initiation sequence to be sent.
    Anyhow if it works maybe it does not matter.

    /* MAX3421E USB Host controller Mail Notifier demonstration */
    // http://www.dreamcheeky.com/webmail-notifier
    #include
    #include
    #include
    #include

    /* Mail Notifier data taken from configuration descriptor */
    #define MailNotifier_ADDR 1
    #define MailNotifier_EP 1
    #define MailNotifier_IF 0
    #define EP_MAXPKTSIZE 8
    #define EP_POLL 0x0a

    EP_RECORD ep_record[ 1 ]; //endpoint record structure for the Mail Notifier

    MAX3421E Max;
    USB Usb;
    Max_LCD LCD;

    void setup() {
    Serial.begin( 9600 );
    Serial.println(“Start”);
    Max.powerOn();
    delay( 200 );
    }

    void loop() {
    Max.Task();
    Usb.Task();
    if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) { //wait for addressing state
    MailNotifier_init();
    Usb.setUsbTaskState( USB_STATE_RUNNING );
    }
    if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the Mail Notifier
    MailNotifier_poll();
    }
    }
    /* Initialize Mail Notifier */
    void MailNotifier_init( void )
    {
    byte rcode = 0; //return code
    /* Initialize data structures */
    ep_record[ 0 ] = *( Usb.getDevTableEntry( 0,0 )); //copy endpoint 0 parameters
    ep_record[ 1 ].MaxPktSize = EP_MAXPKTSIZE;
    ep_record[ 1 ].Interval = EP_POLL;
    ep_record[ 1 ].sndToggle = bmSNDTOG0;
    ep_record[ 1 ].rcvToggle = bmRCVTOG0;
    Usb.setDevTableEntry( 1, ep_record ); //plug MailNotifier.endpoint parameters to devtable
    /* Configure device */
    rcode = Usb.setConf( MailNotifier_ADDR, 0, 0x1F );
    // byte addr, byte ep, byte conf_value, unsigned int nak_limit
    if( rcode ) {
    Serial.print(“Error attempting to configure keyboard. Return code :”);
    Serial.println( rcode, HEX );
    while(1); //stop
    }
    /* Set boot protocol */
    rcode = Usb.setProto( MailNotifier_ADDR, 0, 0, 0 );
    // byte addr, byte ep, byte interface, byte protocol, unsigned int nak_limit
    if( rcode ) {
    Serial.print(“Error attempting to configure boot protocol. Return code :”);
    Serial.println( rcode, HEX );
    while( 1 ); //stop
    }
    delay(2000);
    Serial.println(“Mail Notifier initialized”);
    }
    /* Poll Mail Notifier and update intensity colour */
    void MailNotifier_poll( void )
    {
    char init1[] = { 0x1F, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×03 };
    char init2[] = { 0×00, 0×01, 0×25, 0×00, 0xC4, 0×00, 0×25, 0×04 };
    char msg1[] = { 0xFF, 0×00, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };Red
    char msg2[] = { 0×00, 0xFF, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };Green
    char msg3[] = { 0xFF, 0xFF, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };Yellow
    char msg4[] = { 0×00, 0×00, 0xFF, 0×00, 0×00, 0×00, 0×25, 0×05 };Blue
    char msg5[] = { 0xFF, 0×00, 0xFF, 0×00, 0×00, 0×00, 0×25, 0×05 };Magenta
    char msg6[] = { 0×00, 0xFF, 0xFF, 0×00, 0×00, 0×00, 0×25, 0×05 };Cyan
    char msg7[] = { 0xFF, 0xFF, 0xFF, 0×00, 0×00, 0×00, 0×25, 0×05 };White
    char msg8[] = { 0×00, 0×00, 0×00, 0×00, 0×00, 0×00, 0×25, 0×05 };Off
    byte rcode = 0; //return code
    // byte addr, byte ep, unsigned int nbytes, byte interface, byte report_type, byte report_id, char* dataptr, unsigned int nak_limit
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, init1 );
    delay(500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, init2 );
    delay(500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg1 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg2 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg3 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg4 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg5 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg6 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg7 );
    delay(1500);
    rcode = Usb.setReport( MailNotifier_ADDR,0×00,0×08,MailNotifier_IF,0×02,0×00, msg8 );
    delay(1500);
    }

  • johncohn

    Oleg,
    I just got my usb-shield and am enjoying learning how it works. My goal is to get it to talk to an ST/Ericcson GSM modem I have using simple AT commands. I see many others on the web trying to do the same thing. I’ve seen several example arduino codes that you and others have written to do all sorts of fancy stuff via USB.. What I haven’t found is a simple ‘hello world’ example on how to use the usb-host shield to issue simple string commands (eg. ‘AT…’) and retrieve the responses from soemthing like a modem. Do you or anyone else here have such an example ? Thanks so much !
    -jc

  • I’ve just got the Sparkfun-branded USB host shield (silkscreen date 5-28-10) and I was looking at the MAX3421E datasheet. It can act as a USB host, which is why I wanted the shield in the first place, but it also supports acting as a USB peripheral. So now I’m thinking that this would be a good way to get my Arduino to imitate a real USB HID device of its own.

    As an example, using the 12Mbps high-speed interface to dump ADC data into a PC’s Notepad application faster than it can be transferred through the FTDI COM port.

    Obviously, the Arduino would have to be programmed differently to set the 3421 to act as a peripheral rather than a host, and the various USB identifiers would have to be set, etc

    But the real question is one of hardware: is there an easy way to add a mini- or micro-USB jack to the board? I assume it’s just a matter of tapping into the same VBus, D-, D+, and GND that’s on the USB-A jack and adding a USB-B jack, but will that mess up the signals and/or voltage elsewhere?

    –Joe

  • Ivan

    And as you can with your USB Host Schild recorded on Flash drive a text file?

  • Daniel

    If I plugged in two ps3 controllers into a usb bus and then into the USB Host Shield 2.0 that was connected to an arduino, would the arduino identify and recognize that button presses are coming from two different controllers or would it assume that button presses from any of the buttons on the two controllers are coming from a single controller input?

  • Daniel

    Please bear with me as I am not an expert in electronics. Yes I have seen Richard Ibbotson’s code and I realize you are just hosting his articles. My question is which specific arduino usb shield (that you sell) do need to use with Richard Ibbotson’s ps3 library code so that I can read button presses from a ps3 controller? The arduino I will be using is an Arduino Duemilanove.

  • I Have little bit error when i try compile the code,
    I get error : bt_h.h:104: error: ‘EP_RECORD’ does not name a type. How to fix it.

    Thankyou…

    Regards

    Welly

  • rh

    If I stack a shield that uses standard SPI pins 11-13 on top of the USB 2.0 shield, which is on a Duemilanove/Uno, it will work as long as the other shield does not use pin 10 for SS, right?

    • In general, yes. However, some shields/chips won’t switch MISO line into high-Z state while not selected – this may cause issues.

      • rh

        The shield that I’m using is the Adafruit data logging shield.

        I’m posting to report that it works fine with the USB Host shield 2.0, logging GPS data from a Pharos GPS-500.

  • Arthur

    Hi,
    I wonder whether there is a way to reset and initialize the Usb shield and the library (legacy version) by software.
    (Sometimes, the library and arduino crashes while reading data from USB, i could probably solve the problem by reset everything after certain actions)
    Thanks!

  • maxmachine

    Hello, Any luck with mass storage code/communication?
    Thanks in advance.

  • homer

    Hello Oleg,

    I would ask how to make any usb peripheral i.e. USB to Ethernet adapter or any GPRS usb modem work to USB host shield 2.0?

  • homer

    Thank you for reply Oleg.
    What example should I use as base code to make USB to Ethernet converter work to usb host shield?
    Is is pl2303 terminal?
    Thank you.

  • Martin

    Hello Oleg,
    You have a very nice and understandable page.
    I hope this is the right position for tis post.
    For a student project, I took your code / * Mouse control via communication endpoint * / from the http://www.circuitsathome.com/communicating-arduino-with-hid-devices-part-1 page.
    I have problems with the code of the current libary from the following page: https://github.com/felis/USB_Host_Shield
    my problem is the difference between the library from your Projet state to the current library state.
    Could you tell me the name of the appropriate library or a complete package with a sample program?

    Thank you for your efforts

  • Martin

    Hello Oleg,
    Thank you for your fast response.

    My specific problem is the cyclical polling of the mouse.
    The “boot protocol” is not possible in my application,
    because in your code the Arduino “loop()” stops vor 5 seconds if the mouse does not provide new signals.
    How could I change this code (boot protocol)?

    Thank you.

  • Martin

    Hello Oleg,

    my current error message reads as follow:

    In file included from Projekt__rev_01_02_01_Mouse_Endpoint_ir_ino.cpp:2:
    C:\Dokumente und Einstellungen\Martin\Desktop\arduino-1.0\libraries\USB_Host_Shield_2_0/adk.h:20:1: error: unterminated #if
    Projekt__rev_01_02_01_Mouse_Endpoint_ir_ino.cpp: In function ‘void mouse0_init()’:
    Projekt__rev_01_02_01_Mouse_Endpoint_ir_ino:78: error: no matching function for call to ‘USB::setEpInfoEntry(int, EpInfo*)’
    C:\Dokumente und Einstellungen\Martin\Desktop\arduino-1.0\libraries\USB_Host_Shield_2_0/Usb.h:232: note: candidates are: uint8_t USB::setEpInfoEntry(uint8_t, uint8_t, EpInfo*)

    The library: 71dcc7e534 for the USB_Host_Shield_2.0

    The Code:

    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include
    #include

    int i;

    /* Mouse communication via control endpoint */
    #include
    #include
    //#include

    #define DEVADDR 1
    #define CONFVALUE 1

    void setup();
    void loop();

    MAX3421E Max;
    USB Usb;

    void setup()
    {
    Serial.begin( 115200 );
    Serial.println(“Start”);
    // Max.powerOn();
    delay( 200 );
    }

    void loop()
    {
    byte rcode;
    Max.Task();
    Usb.Task();
    if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING ) {
    mouse0_init();
    }//if( Usb.getUsbTaskState() == USB_STATE_CONFIGURING…
    if( Usb.getUsbTaskState() == USB_STATE_RUNNING ) { //poll the keyboard
    rcode = mouse0_poll();
    if( rcode ) {
    Serial.print(“Mouse Poll Error: “);
    Serial.println( rcode, HEX );
    }//if( rcode…
    }//if( Usb.getUsbTaskState() == USB_STATE_RUNNING…
    }
    /* Initialize mouse */
    void mouse0_init( void )
    {
    byte rcode = 0; //return code
    /**/
    Usb.setEpInfoEntry( 1, Usb.getEpInfoEntry( 0,0 ) );//copy device 0 endpoint information to device 1
    /* Configure device */
    // rcode = Usb.setConf( DEVADDR, 0, CONFVALUE );
    // if( rcode ) {
    // Serial.print(“Error configuring mouse. Return code : “);
    // Serial.println( rcode, HEX );
    // while(1); //stop
    // }//if( rcode…
    Usb.setUsbTaskState( USB_STATE_RUNNING );
    return;
    }
    /* Poll mouse using Get Report and print result */
    byte mouse0_poll( void )
    {
    // byte rcode,i;
    char buf[ 4 ] = { 0 }; //mouse buffer
    static char old_buf[ 4 ] = { 0 }; //last poll
    /* poll mouse */
    // rcode = Usb.getReport( DEVADDR, 0, 4, 0, 1, 0, buf );
    // if( rcode ) { //error
    // return( rcode );
    // }
    for( i = 0; i < 4; i++) { //check for new information
    if( buf[ i ] != old_buf[ i ] ) { //new info in buffer
    break;
    }
    }
    if( i == 4 ) {
    return( 0 ); //all bytes are the same
    }
    /* print buffer */
    if( buf[ 0 ] & 0×01 ) {
    Serial.print("Button1 pressed ");
    /*
    }
    if( buf[ 0 ] & 0×02 ) {
    Serial.print("Button2 pressed ");
    }
    if( buf[ 0 ] & 0×04 ) {
    Serial.print("Button3 pressed ");
    */
    }

    Serial.println("");
    Serial.print("X-axis: ");
    Serial.println( buf[ 1 ], DEC);
    Serial.print("Y-axis: ");
    Serial.println( buf[ 2 ], DEC);
    /*
    Serial.print("Wheel: ");
    Serial.println( buf[ 3 ], DEC);
    for( i = 0; i < 4; i++ ) {
    old_buf[ i ] = buf[ i ]; //copy buffer
    }
    Serial.println("");
    */
    // return( rcode );
    return( 0 );
    }

  • Martin

    Hi Oleg,
    and how can I modify the code to my requirements?
    which library should I use for this example?
    I use the Arduino software 1.0 and your host shield.

    Thank you.

  • Martin

    Hi Oleg,
    yes this is the link to the Library “71dcc7e534″
    But this is not kompatibelmit with the program line:
    44 Usb.setEpInfoEntry (1, Usb.getEpInfoEntry (0,0));
    from your legacy example / * Mouse control via communication endpoint * /
    I neet the old Library or a modify code which is running on the
    Arduino 1.0 software.

    Thank you.

  • 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!

  • Chuck

    Hi – I’m enjoying the USB shield with a bluetooth dongle, works great every time.

    My only issue is trying to send some floating point numbers, from a self-balancing robot experiment, back to a processing gui to display sensors and motor outputs and also adjust the PID loop – BT is nice as I won’t have a usb cable pulling the robot off balance ;)

    However, the SerialBT.print does not appear to support float like the normal Serial.print – and everyone else suggests using dtostrf() which looks like a real pain ;)

    Any other suggestions?

    Thanks for a great board, the supporting libraries are fantastic.

  • mxmillercell

    Can you tell me from the following descriptor what i need to change in the mouse sketch to get a valid report fom this mad catz xbox 360 controller?

    HID report descriptor
    Start
    Device addressed… Requesting device descriptor.
    Device descriptor:

    Descriptor Length: 12
    USB version: 2.0
    Class: FF Vendor Specific
    Subclass: FF
    Protocol: FF
    Max.packet size: 08
    Vendor ID: 1BAD
    Product ID: F02E
    Revision ID: 0490
    Mfg.string index: 01 Length: 30 Contents: Mad Catz, Inc.
    Prod.string index: 02 Length: 36 Contents: Mad Catz FightPad
    Serial number index: 03 Length: 18 Contents: 1871E18B
    Number of conf.: 01

    Configuration number 0
    Total configuration length: 153 bytes

    Configuration descriptor:
    Total length: 0099
    Number of interfaces: 04
    Configuration value: 01
    Configuration string: 00
    Attributes: A0 Remote Wakeup
    Max.power: FA 500ma

    Interface descriptor:
    Interface number: 00
    Alternate setting: 00
    Endpoints: 02
    Class: FF Vendor Specific
    Subclass: 5D
    Protocol: 01
    Interface string: 00

    HID descriptor:
    Descriptor length: 11 17 bytes
    HID version: 1.10
    Country Code: 19 Norwegian
    Class Descriptors: 37
    Class Descriptor Type: 81 Invalid Reserved
    Class Descriptor Length:788 bytes

    HID report descriptor:

    Endpoint descriptor:
    Endpoint address: 01 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 04 4 ms

    Endpoint descriptor:
    Endpoint address: 02 Direction: OUT
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 08 8 ms

    Interface descriptor:
    Interface number: 01
    Alternate setting: 00
    Endpoints: 04
    Class: FF Vendor Specific
    Subclass: 5D
    Protocol: 03
    Interface string: 00

    HID descriptor:
    Descriptor length: 1B 27 bytes
    HID version: 1.10
    Country Code: 1 Arabic
    Class Descriptors: 1
    Class Descriptor Type: 83 Invalid Reserved
    Class Descriptor Length:320 bytes

    HID report descriptor:

    Endpoint descriptor:
    Endpoint address: 03 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 02 2 ms

    Endpoint descriptor:
    Endpoint address: 04 Direction: OUT
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 04 4 ms

    Endpoint descriptor:
    Endpoint address: 05 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 40 64 ms

    Endpoint descriptor:
    Endpoint address: 05 Direction: OUT
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 10 16 ms

    Interface descriptor:
    Interface number: 02
    Alternate setting: 00
    Endpoints: 01
    Class: FF Vendor Specific
    Subclass: 5D
    Protocol: 02
    Interface string: 00

    HID descriptor:
    Descriptor length: 09 9 bytes
    HID version: 1.10
    Country Code: 1 Arabic
    Class Descriptors: 34
    Class Descriptor Type: 86 Invalid Reserved
    Class Descriptor Length:7 bytes

    HID report descriptor:

    Endpoint descriptor:
    Endpoint address: 06 Direction: IN
    Attributes: 03 Transfer type: Interrupt
    Max.packet size: 0020
    Polling interval: 10 16 ms

    Interface descriptor:
    Interface number: 03
    Alternate setting: 00
    Endpoints: 00
    Class: FF Vendor Specific
    Subclass: FD
    Protocol: 13
    Interface string: 04 Length: 178 Contents: Xbox Security Method 3, Version 1.00, © 2005 Microsoft Corporation. All rights reserved.

    Unknown descriptor:Length: 06
    Type: 41
    Contents: 0001010321A8

  • mxmillercell

    I am not sure which report descriptor parameters to plug into the getreport method. I used usb.getReport(DEVADDR,0,20,0,1,0,buf) Does that look right?

  • mxmillercell

    I don’t see a way to download that library. Can you put up a link that directs me to an actual download.
    I actually wanted to adapt the mouse program to read the xbox reports so that I understood better how it works. It seems, you simply need to know the endpoint and report you want, or just set ep to zero to get any report that updates. But I cant tell from the descriptor above which report parameters to use. I should be able to simply serial.print the actual hex string to my serial monitor when an event occurs. Then I can watch it for changes when I press buttons or whatever, it’s more of a learning exercise.

  • mxmillercell

    Ok, I got it to sort of work. Following is the part of the code I think is wrong. I do get a response when I press the buttons, but I believe I am not reading the correct buf memory bytes in the “if( buf[ 2 ] & 0×00 )” statements. Is there a section that shows the report’s bit mapping for the different inputs?

    rcode = Usb.getReport( DEVADDR, 0, 20, 0, 1, 0, buf );
    if( rcode ) { //error
    return( rcode );
    }
    for( i = 0; i < 20; i++) { //check for new information
    if( buf[ i ] != old_buf[ i ] ) { //new info in buffer
    break;
    }
    }
    if( i == 20 ) {
    return( 0 ); //all bytes are the same
    }
    /* print buffer */
    if( buf[ 2 ] & 0×00 ) {
    Serial.print("Dup pressed ");
    }
    if( buf[ 2 ] & 0×01 ) {
    Serial.print("Ddn pressed ");
    }
    if( buf[ 2 ] & 0×02 ) {
    Serial.print("Dlt pressed ");
    }
    if( buf[ 2 ] & 0×03 ) {
    Serial.print("Drt pressed ");
    }
    if( buf[ 2 ] & 0×04 ) {
    Serial.print("Start pressed ");
    }
    if( buf[ 2 ] & 0×05 ) {
    Serial.print("Back pressed ");
    }
    if( buf[ 2 ] & 0×06 ) {
    Serial.print("Lstick pressed ");
    }
    if( buf[ 2 ] & 0×07 ) {
    Serial.print("Rstick pressed ");
    }
    Serial.println("");
    Serial.print("Lstick X-axis: ");
    Serial.println( buf[ 12 ], DEC);
    Serial.print("Lstick Y-axis: ");
    Serial.println( buf[ 14 ], DEC);
    Serial.print("Rstick X-axis: ");
    Serial.println( buf[ 16 ], DEC);
    Serial.print("Rstick Y-axis: ");
    Serial.println( buf[ 18 ], DEC);

  • mxmillercell

    OK, so I got thru that successfully and have moved on to trying out the Open Accessory mode on an HTC Droid Incredible. It shows SW version 2.3.4 so it should be compatible with the ADK libraries.
    Vendor ID: 0BB4
    Product ID: 0C9E
    I dont’t believe the Vendor ID and Product ID are compatible though…how do I make this phone work with my Arduino Mega ADK USB Host thru Open Accessory mode?

  • mxmillercell

    So, I have the Mega ADK Board. So, I need the USB ver.2 correct? I would have to adapt your sample code to use USB ver.2?

  • Rick

    Where would I find error codes for values returned from a HID SetReport()? I getting “D” hex back as the response.

  • Kareem

    Hello Oleg,
    I’ve just purchase USB Host Shield v2.0
    because I want to interface 3G USB Modem (Huawei E303 Cloud+ OR Huawei MF 1805) to my Arduino Mega
    I think both of them don’t have pl2303 !!

    What example should I use as base code to make it work with usb host shield?
    Is is pl2303 terminal?
    if not could you guide me, how can I make it work ?

    Thanks

  • zimmes

    Hi Oleg!
    Maby i have been bad at searching in the posts but can u use an usb flashdrive as flash memory
    on the arduino uno ? i really want to have a possibility to have more then 32kb storage for my code.
    can be fun if you can direct to files in the usb storage in the code to save memory.
    Is this possible ?

    Thanks in advance :D

Leave a Reply

  

  

  



You can use these HTML tags

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong> <pre lang="" line="" escaped="" highlight="">