Shopping Cart

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.

No related posts.

322 comments to USB Host Shield library Version 2.0 released.

  • Guy

    Nevermind. It turns out the FTDI loopback example worked for me. I just had to adjust baud rates and command timing specific to my application.

  • Eric

    Guys, I haven’t found any clue that you released “Mass Storage Devices” support, any progress now? I am interesting in your shield and wondering whether it can make arduino to read the flash drive and show on LCD.

    Thanks.

  • mat66mat

    Good Morning,

    USB HOST SHIELD 2.0
    USB HOST SHIELD LIBRARY 2.0
    ARDUINO UNO R3

    It’s my first project in arduino environment. I must dialog with a health usb card reader (french project Sesam vital)

    If i connect this reader directly to windows system i can see in device manager “XIRING USB CDC 14 (COM57)”

    I use your acm_terminal example and i get FailGetDevDescr with return code 04, Can you explain what it mean ?

    Thank you very much for your help

    Here’s informations given by USB_desc
    Start

    01

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 02
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 40
    Vendor ID: 0F14
    Product ID: 0014
    Revision ID: 0100
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 03
    Number of conf.: 01

    Configuration descriptor:
    Total length: 0043
    Num.intf: 02
    Conf.value: 01
    Conf.string: 00
    Attr.: 80
    Max.pwr: FA

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 01
    Intf. Class: 02
    Intf. Subclass: 02
    Intf. Protocol: 01
    Intf.string: 00
    Unknown descriptor:
    Length: 05
    Type: 24
    Contents: 0010010424
    Unknown descriptor:
    Length: 04
    Type: 24
    Contents: 02060524
    Unknown descriptor:
    Length: 05
    Type: 24
    Contents: 0600010524
    Unknown descriptor:
    Length: 05
    Type: 24
    Contents: 0103010705

    Endpoint descriptor:
    Endpoint address: 82
    Attr.: 03
    Max.pkt size: 0010
    Polling interval: 01

    Interface descriptor:
    Intf.number: 01
    Alt.: 00
    Endpoints: 02
    Intf. Class: 0A
    Intf. Subclass: 00
    Intf. Protocol: 00
    Intf.string: 00

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

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

    Addr:1(0.0.1)

    • It means Get Device Descriptor request has failed. This is strange since USB_desc outputs it easily. Your device may need additional delays in initialization, try to add them and see if it makes any difference.

  • tab

    Hi Oleg,

    Im using the FTDI loopback example and everything is working fine, but Im unsure of how to use the hub function. What Im trying to do is send “Deadbeef1″ to one device and “Deadbeef2″ to another device, and make them both output on the serial monitor. Im just not sure how to address each device using the USBhub class. any help would be much appreciated.

    Thankyou

    • Hub is automatic, you just need to instantiate it. Devices are the same; if you need two, create two instances of FTDI, like this:

      FTDI             Ftdi1(&Usb, &FtdiAsync);
      FTDI             Ftdi2(&Usb, &FtdiAsync);
  • tab

    Thankyou for the immediate response Oleg, this clears up a lot of things.
    So, because I want deadbeef1 and deadbeef2 to alternate in the serial monitor, do I have to extra lines like this:
    rcode2 = Ftdi2.SndData(strlen(strbuf), (uint8_t*)strbuf);
    ?

    or is it something much more trivial, which Im too dopey to even think about lol,

    thankyou so much ! :)

  • tab

    ended up working, just repeated the first loop again, with different variable names. Thankyou Oleg! :)

  • Stuart Clark

    I have an arduino uno r3, and am trying to get the usb host shield 2.0 compiled so i can communicate with the android phone.

    i get the following errors

    In file included from HelloAndroid.cpp:3:
    C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\AndroidAccessory/AndroidAccessory.h:37: error: ‘EP_RECORD’ does not name a type

    C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\AndroidAccessory/AndroidAccessory.h:50: error: ‘EP_RECORD’ has not been declared

    C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\AndroidAccessory/AndroidAccessory.h:50: error: ‘EP_RECORD’ has not been declared

    C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\AndroidAccessory/AndroidAccessory.h:64: error: ‘USB_NAK_LIMIT’ was not declared in this scope

    help please

    • Stuart Clark

      if i use the “original” usb host shield instead i get the following errors on compile

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp: In static member function ‘static void MAX3421E::setRST(uint8_t)’:

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:58: error: ‘PORTJ’ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:58: error: ‘PJ2′ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:60: error: ‘PORTJ’ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:60: error: ‘PJ2′ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp: In static member function ‘static uint8_t MAX3421E::readINT()’:

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:65: error: ‘PINE’ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:65: error: ‘PE6′ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp: In static member function ‘static void MAX3421E::pinInit()’:

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:77: error: ‘DDRE’ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:77: error: ‘PE6′ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:78: error: ‘DDRJ’ was not declared in this scope

      C:\Documents and Settings\Stuart.CLARK\My Documents0 Software Development\arduino\arduino-1.0.1-windows\arduino-1.0.1\libraries\USB_Host_Shield\Max3421e.cpp:78: error: ‘PJ2′ was not declared in this scope

    • Stuart Clark

      note i am using ADK_release_20120606 for

      AndroidAccessory.h and .cpp

      the “original” USB_Host_Shield is from here also

    • Stuart Clark

      EP_RECORD appears to be missing from Usb.h, someone from stackoverflow suggested adding

      typedef struct {
      byte epAddr;
      byte Attr;
      unsigned int MaxPktSize;
      byte Interval;
      byte sndToggle;
      byte rcvToggle;
      } EP_RECORD;

      is this correct ???

    • It doesn’t look like you are using the newest version of the USB Host library, but the version hosted by Google which is just a modified version of the old version.

      Simply just download the newest verison of the library: https://github.com/felis/USB_Host_Shield_2.0 and follow these instructions on how to add the library: https://github.com/felis/USB_Host_Shield_2.0#how-to-include-the-library.

      After you have installed the library, then see the following example: https://github.com/felis/USB_Host_Shield_2.0/blob/master/examples/adk/ArduinoBlinkLED/ArduinoBlinkLED.ino – that should get you started :)

  • Stuart Clark

    add the missing EP_RECORD typdef and then got a bunch of AndroidAccessory.cpp compile errors. Obviously not compatible, is there an updated version of AndroidAccessory is should be using

  • Vanessa

    Hi Oleg,

    I tried the acm_terminal example with a CDC-ACM device. It seems to work because I don’t receive any errors and see “ACM configured” printed out at the end. But from what I understand, since the acm_terminal example was successful, then the device I am using should be enumerated but I don’t think it is. The device I am using should send a signal once it’s enumerated and this is not happening. Do you know what could be going wrong in the enumeration process even though I receive a successful “ACM configured” message?

    • After “ACM configured” you should see data coming from device – if said device is sending something. If you have access to serial side of the converter, short TX and RX together and then type something in the terminal, the characters you’re typing should echo back to the screen.

  • Jeff

    Oleg,
    Just started coding again after long absence and just picked up USB Shield for Arduino UNO and am testing with Logitech Gamepad. Ran the HID Joystick code in library examples and the hardware is working fine.

    It’s been a long time since working with C++, so am trying to figure out a way to access the GamePadEventData. I tried calling JoystickEvents::OnGamePadChanged and passing in a pointer to a GamePadEventData variable, but obviously since I don’t know if the data has changed, or is available from the device that will not work. Was looking for a high level function I could call and check for changed data, but could not find one.

    I saw some PS3 examples where there were functions to test for changed data, then you could use a function to read the joystick or button values. That is what I am ultimately trying to develop. Since this is an HID device, which could be pretty generic, do I need to write my own routines to accomplish this? I see in your code example where you check the buffer for a change, and then call the various event handlers, so I guess my ultimate question is do I need to emulate the bulk of this code on my own to get usable data out?

    I have a degree in Computer Engineering, so I feel really dumb right now not being able to figure this out. My C++ knowledge has evaporated with age it seems.

    Thanks for your help.

    Jeff

  • Jeff

    Oleg,
    Stepped away from the computer to take a break and clear my head. Think I figured this out. If I add a boolean flag variable to the JoystickReportParser class, then when the Parse function is called and the data has changed I can set the variable to True. I can also add a few member functions to the class, one that returns the state if the flag, and another JoystickValue function that can return the GamePadEventData structure values passed in by pointer. I could then reset the flag to False, so I don’t keep reading the same data within my main program.

    Will see how this works in a bit.

    Jeff

    BTW, I am inspired by the effort you have taken to support this code library. Great stuff. I am mentoring a USFirst.org FRC robotics team, and am having a lot of fun working with the high school students on this kind of fun programming. A lot different from the code I wrote while in the military.

  • Jeff

    Oleg,
    Thanks for the references. The approach I mentioned in earlier comment works just fine. The only minor glitch I found is if I stop moving the joystick then the JoystickEvents::OnGamePadChanged function does not get called and motion of my driven servo stops. As long as the joystick is changing values, things move just fine. So I thought about storing old joystick values to use when new data is not present. Trying this required me to determine and/or monitor polling frequency to calculate a time basis for desired rate of servo movement over time. Seeing your code from the Poll() function shed some light on a better way to try and implement smooth motion.

    Thanks again for all of your help,

    Jeff

  • Henrique

    Hi, i’m using a Samsung Galaxy S4 and my arduino mega adk did not recognize the device, but some weeks ago, it recognized my Samsung Galaxy Ace.
    Any possible solutions?

  • Henrique

    Someone have some example about how i send data from arduino to android, and read it on android.

  • Ben

    Is there any way to shrink the code size of the Wiimote code to fit on a 32Kb AVR like the Uno or the Leonardo? I don’t need things like hub support or any of the bluetooth profiles not supported by the Wiimote. This is one of the many times I’ve wished Atmel would release a chip with more than 32Kb flash in a small package… Mega1284P is probably going to be my best bet :/

  • Hello Oleg. I’m relative new using the Arduino Board and the USB-Shield. I’m using a Arduino Leonardo and the USB-Shield from circuits@home. I use it for reprogramming a Keyboardlayout. the programm function good. But when I plug the Arduino with the Keyboard in another PC it doesn’t function anymore. It should works as a Plug and Play. can you help me? Because with the old USB-Shield Library it function normally. I also wrote an art extention for a mouse function in the same programm but it doesn’t work like it should.
    Thank You for your answer.
    Carolina

  • Scott

    Hi Oleg,

    I’m using a generic medical device – I need to send it simple commands like FF 02 01 and FF 04 00.
    When I plug the device into the laptop, it presents itself as a COM (virtual serial port).
    I’ve been able to use the board_qc test and everything works fine on my USB host shield.

    What sketch in your library would you suggest that would enable me to send serial commands through a virtual port using your shield? Are there any modifications I would need to make to the code to get it to work with my specific device?

    Thank you so much.

    • There are 3 USB to serial converter types supported by the library: CDC ACM, FTDI, and Prolific PL2303. First type can be determined by class/subclass/protocol (same as Arduino UNO ), other two have unique VID/PID. Run USB_Desc and post output here – I’ll take a look.

      There are also other USB to serial converters which are not yet supported.

      • Scott

        Here’s the output of USB_desc

        Thanks for your help!

        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)

  • Scott

    I got the FTDI example code to send a char [0xFF, 0x02, 0x01] to the medical device. It received the command and turned on. I can’t figure out how to send it a second command after a short delay in the program. I tried inputting a delay(500) and then copied and pasted the send code but it didn’t work. What aspects do I need to repeat, what can I erase?

    Thank you for helping so far, if I can get this working our company plans on buying 50-100 units of your shield in the next year or two so I hope it’s worth your time.

    • Scott

      I found a crude workaround. I can run the Ftdi.Release(); and then Usb.Init(); commands and when I go to send another command, it goes through correctly. There has got to be a simpler way to do this?

      Thanks

      • Scott

        This actually doesn’t work. I’m missing some key element to do that either clears the RX/TX lines or resets the board to send the 2nd command. If I hit reset on the arduino it will then send through the 2nd command. As if it was waiting in the buffer for some signal to push it through.

        Is there some function I need to use between issuing multiple commands? Is there a function that could simply reset everything?

        • You need to understand what your peripheral needs. Trying random things won’t help – there is too much to try.

          • Scott

            Thank you for your response. I’ve spent about 30 hours trying things, luckily I won’t waste anymore time.

            Using an executable that the company provided, I then monitored my serial port and found a sequence of events that the laptop sends to the device to operate it. Every command is prefaced with these events:
            COM is open

            Baud rate 9600

            RTS off

            DTR off

            Data bits=8, Stop bits=1, Parity=None

            Set chars: Eof=0x1A, Error=0×00, Break=0×00, Event=0x1A, Xon=0×11, Xoff=0×13

            Handflow: ControlHandShake=(), FlowReplace=(), XonLimit=1024, XoffLimit=1024

            Baud rate 9600

            RTS off

            DTR off

            Data bits=8, Stop bits=1, Parity=None

            Set chars: Eof=0x1A, Error=0×00, Break=0×00, Event=0x1A, Xon=0×11, Xoff=0×13

            Handflow: ControlHandShake=(), FlowReplace=(), XonLimit=1024, XoffLimit=1024

            DTR off

            Set timeouts: ReadInterval=-1, ReadTotalTimeoutMultiplier=-1, ReadTotalTimeoutConstant=30, WriteTotalTimeoutMultiplier=0, WriteTotalTimeoutConstant=10

            In/out queue size 4096/2048

            Purge the serial port: RXABORT, RXCLEAR

            Purge the serial port: TXABORT, TXCLEAR

            *Command is then sent in hex code*

            DTR off

            Purge the serial port: RXABORT, RXCLEAR

            Purge the serial port: TXABORT, TXCLEAR

            COM is closed

            Can I perform these same operations with your FTDI code? It looks like I just need to purge the RX and TX ports. Or should I be using the ‘set characters’ that it just shows?

  • Dan C

    Hi Oleg,
    I’ve been trying to use an ACM device to receive data from (its a Serial USB thermistor) and transmit that data to an Android tablet. I am unable to recognize both the ACM device and the android at once (through a powered Hub). Both are able to be recognized and communicated to individually, but not simultaneously.
    I setup the code like so:

    USB Usb;
    USBHub Hub1(&Usb);

    ACMAsyncOper AsyncOper;
    ACM Acm(&Usb, &AsyncOper);

    ADK adk(&Usb,”Example”,
    “Example”,
    “Example,
    “1.0″,
    “1.0″,
    “1.0″);

    If I list the acm device first, it reads that just fine and ignores the android
    If I list the ADK first, it connects to the android but ignores the ACM device.
    Any thoughts on what I am doing wrong?
    Thanks for ll your help!
    Dan

  • Dan C

    It is in fact a 7 port hub. However, using two Hub instances makes no difference..
    I switched to a 4 port hub and only one instance and still the same behavior.
    This sounds similar to the 2 mouse issue I saw some people were having in the comments…could it be related?
    Thanks again for your fast responses!

  • Krit

    Hello

    I bought the USB host shield for arduino a couple weeks ago, but I just started playing with it a couple days ago
    I have arduino uno r2.
    Somehow when I connected the usb host shield and arduino board together, then
    plugged in my Bluetooth device/ PS3 controller, my computer did not recognize the devices that connected through the usb host shield at all.
    I tried to run the sample codes from usb host shield library that I downloaded online, and they give me the same result whether I have the usb host shield
    connected to the arduino uno board or not.

    For example when I upload the example code “acm_terminal” with and without the usb host shield on, it didn’t give me any error.
    And when I upload the example code “PS3BT” with and without the usb host shield on, it gave me

    avrdude: stk500_paged_write(): (a) protocol error, expect=0×14, resp=0×64
    avrdude: stk500_cmd(): programmer is out of sync

    It didn’t give me any compiling error.
    Only gave me error when I tried to upload the codes.

    I don’t know how to fix this problem,
    Is it because that the shield not working or it doesn’t work with arduino uno r2?

    Thank you.
    Krit S.

    • Maybe you don’t have enough memory? Try to disable debug and see if it makes any difference.

      • Krit S.

        Thank you.
        That’s probably the reason.
        I borrowed my friend’s arduino uno r3 to test it out, and it works great.

        But I run into another problem.
        when I run PS3USB code, all the buttons work and also show on the serial monitor.
        But, when I tried to run PS3BT code and link the Bluetooth and PS3 controller together, everything works except L2 & R2.

        • Oliver

          Same here. I can’t get L2 R2 to work with bluetooth. Also the accelerometer does not work with bluetooth. These work ok with USB connection.

          • That is caused by your dongle not supporting EDR (Enhanced Data Rate). If it doesn’t support it, it won’t be able to read all the data from the PS3 controller.
            You will have to get another dongle, as it’s a hardware issue with the dongle.

  • Jono

    I am unable to get the USB host board to connect to my Arduino Mega 2560 R3 board. It does not get past the following code:

    Serial.begin(115200);
    while (!Serial);
    if (Usb.Init() == -1) {
    Serial.print(F(“\r\nOSC did not start”));
    while (1); //halt
    }

    I always get the OSC did not start message.

    I am using the XBOXRECV tutorial code to connect and Xbox 360 wireless controller to a wireless receiver. I am powering it with an external power supply and it works just fine on an Arduino UNO R3 board.

    Thanks for any help.

    Jono

  • Jono

    The Sparkfun DEV-09947 USB Host Shield

  • manitou

    I hooked up logic analyzer to SPI pins (mega2560) with a USB mouse. As expected SPI clock was 8mhz. I see lots of 4 byte SPI events with 37.3 us between events. And about every 10.2 ms there is a more complex SPI sequence, poll request? I figured I’d just see SPI activty every 10ms. I was surpised at the higher rate of SPI events (NAKs?).

    • MAX3421E gets polled by several processes. 37us is likely the turnaround time of loop(), from which Usb.Task() is called. If you’re curious, run UsbTask() every millisecond or so, you’ll likely see traffic every millisecond or so. To see what it does look at the source code.

  • Filipe Jorge

    Hi,
    Is there any example that can send for example {0×33 0×44} to a specific endpoint?
    I’ve looked into the github examples and i didnt found anything that would do that. Also i´ve looked into the max3421e library to see that such functions exist in a similar way.
    Im asking for this because i want to send instructions to another device that uses usb without using a pc.
    Cheers

    • In USB, you can’t send random data to random endpoints. The device first needs to be initialized and initialization depends on the device type. Once this is done, the device class provides SndData() and RcvData() methods which can be used.

      • Filipe Jorge

        I understand how USB works, perhaps i didnt explain well what i wanted to ask.
        I already have a program in windows that communicates to a device through usb, i know that to communicate you need the vid, pid, the endpoints to write on the host and device and their length, etc…
        I wanted to ask if there was an example that could provide me some light on how to utilize the libraries available for any type of device. For example, ill show you some of the code i used on windows to send data to a usb device:

        uint8_t answear[5]; //answear from device
        uint8_t comando_on0[2]={0×04, 0×66}; //A1 ON
        uint8_t comando_on1[2]={0×06, 0×62}; //A1 ON
        uint8_t OK[1]={0×00}; //OK for transmission

        uint8_t endpoint;
        int length;
        int actual_length;
        int r;

        memset(answear, 0, sizeof(answear));
        length=2;
        endpoint = 0×02; //From Host to Device
        r=libusb_interrupt_transfer(CM15_handle, endpoint, (unsigned char*)&comando_on0, length, &actual_length, 1000);

        length=5;
        endpoint = 0×81; //From Device to Host
        r=libusb_interrupt_transfer(CM15_handle, endpoint, (unsigned char*)&answear, length, &actual_length, 1000);
        /*****************************************************************************************/

        //Send OK for transmission
        r=libusb_interrupt_transfer(CM15_handle, 0×02, (unsigned char*)&OK, 1, &actual_length, 1000);

        //Should receive 0×55 Interface ready.
        memset(answear, 0, sizeof(answear));
        r=libusb_interrupt_transfer(CM15_handle, 0×81, (unsigned char*)&answear, 5, &actual_length, 1000);

        length=2;
        endpoint = 0×02; //From Host to Device
        r=libusb_interrupt_transfer(CM15_handle, endpoint, (unsigned char*)&comando_on1, length, &actual_length, 1000);

        printf(“\n\n—>Equipment ON…\n”);

        Sry for my english

  • Ray Cho

    Hi
    I’m using arduino uno with usb host shield 2.0.
    I try to connect one keyboard and one mouse to the shiled one by one.
    The keyboard work fine when I try to use the code “USBHIDBootKbdAndMouse”, but the six button can’t(No any output on serial Monitor).
    On the other hand, I try to connect these through a usb hub,I combine the code “hub_demo” and “USBHIDBootKbdAndMouse”. The serial monitor seem detect the hub only.

    What I have missed?
    *************************
    Start

    41

    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0200
    Device class: 09
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 40
    Vendor ID: 1A40
    Product ID: 0101
    Revision ID: 0111
    Mfg.string index: 00
    Prod.string index: 01
    Serial number index: 00
    Number of conf.: 01

    Configuration descriptor:
    Total length: 0019
    Num.intf: 01
    Conf.value: 01
    Conf.string: 00
    Attr.: E0
    Max.pwr: 32

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 01
    Intf. Class: 09
    Intf. Subclass: 00
    Intf. Protocol: 00
    Intf.string: 00

    Endpoint descriptor:
    Endpoint address: 81
    Attr.: 03
    Max.pkt size: 0001
    Polling interval: FF

    Addr:41(1.0.1)

    *************************

  • Ray Cho

    Just to say thank you

  • Peter O

    Hello
    I have a hard time making the USB Host Shield run with my Arduino (both Mini). USB seems to be properly initialized, but the task loop remains in “USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE” no matter if the board comes up with a device plugged in or the device is plugged in after power-up. I use an additional power source to support the board and tried a BT adapter, a mouse and a keyboard.

    Any help is greatly appreciated.
    Thanks!
    Peter

      • Peter O

        Thanks for your reply, Oleg. I have an Arduino Mini 3,3V. My USB Mini Shield has the following pins soldered to the Arduino: 9,10,11,12,13, VCC, GND, RAW, RST. The label on BT Adapter says “GBU521″. The additional power source is a regulated lab power adapter with up to 1.5A which I’ve set to 5V and connected to the RAW pin. USB library is on commit b82835c877adecf507312b742dd687e2ea03628f, which should be the most recent.

      • Peter O

        I tried it with an Itead USB Host Shield and an Arduino Mega 2560. Most recent USB Library from git on master branch. The same effect – he stays in USB_DETACHED_SUBSTATE_WAIT_FOR_DEVICE.

  • Fabian Kluge

    Hello, im trying to get an USB HUB working with Arduino MEGA ADK board, but with the HUB_demo i only get back the HUB itself. Is there anythink special needed for ADK Board? Maybe some change in one of the library? The devices i want to connect via HUB work fine with the board itself(barcodescanner & multimeter). Thanks a lot!
    Fabian

  • Mr S

    Just wondering if anyone else had run into compilation issues with the FTDI example.

    Using a completely stock install of Arduino 1.5.7 on Win 8, building for an Atmega 2560 I get the following error on the unmodified example.

    USBFTDILoopback.ino:37:18: error: cannot declare variable ‘FtdiAsync’ to be of abstract type ‘FTDIAsync’
    USBFTDILoopback.ino:10:7: note: because the following virtual functions are pure within ‘FTDIAsync’:
    In file included from USBFTDILoopback.ino:1:0:
    C:\Program Files (x86)\Arduino\libraries\USB_Host_Shield_20/cdcftdi.h:82:25: note: virtual uint8_t FTDIAsyncOper::OnRelease(FTDI*)
    virtual uint8_t OnRelease(FTDI *pftdi) = 0;
    ^

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="">