Shopping Cart


Mass Storage Support for USB Host Library 2.0 released!

Mass Storage

Mass Storage

The code supporting USB Mass Storage Class of devices has been added to USB Host Shield 2.0 library and is available to download on GitHub. Mass storage devices include USB Flash drives, memory card readers, external hard drives/CD-ROMs, smartphones/tablets, and some others – almost anything that shows as a drive while connected to a PC (exceptions are digital cameras as well as some phones pretending to be digital cameras). Andrew Kroll (who made this release possible) – thank you very much!

At present, the code example, also featuring Andrew’s FAT and extended memory implementation, can only be run on “big” Arduinos such as Mega and Mega 2560. Another FAT implementation, developed by Alex Glushchenko, is being tested – there is a slight possibility that at least some functionality can be demonstrated on a regular UNO board. On the other hand, the mass storage component can be used without a file system by simply reading/writing physical sectors; this approach can save a lot of memory. The documentation for the mass storage class code is available here.

Many hours has been spent testing the code; it should work with any device which claims to support “mass storage bulk only” transport. While newer (less than 5 years old) won’t cause any problems, older ones could be finicky. If your device shows odd behaviour with this code, please let me know – I will trade it for the good working one.



Related posts:

  1. HID support for USB Host Shield Library 2.0 released
  2. Bluetooth RFCOMM/SPP service support for USB Host 2.0 Library released!
  3. USB Host Shield library Version 2.0 released.
  4. Sony PS3 Controller support added to USB Host library
  5. Wireless Xbox360 controller support for USB Host 2.0 library
  6. Arduino 1.0-compatible USB Host Library released
  7. Google Open Accessory Interface for USB Host Shield Library 2.0 released
  8. Andriod ADK-compatible USB Host Library release.
  9. USGlobalsat ND-100S GPS receiver works with USB Host library
  10. A documentation project for USB Host Library 2.0 has begun!

93 comments to Mass Storage Support for USB Host Library 2.0 released!

  • Is Arduino Due compatibility a possibility?

  • Mr. Oleg and everyone in this website,
    i really appropriate all of the wonderful libraries you provide and can’t tell you how much they are useful for people in their projects and i hope a time comes that you can control every single device involving USB connections using Arduino.
    best of luck.

  • Al

    Could you please post the code for the implementation that could run on an UNO?

  • Kabir

    Hmm, cannot compile on Arduino 1.0.5 :

    testusbhostFAT:49: error: variable or field ‘die’ declared void
    testusbhostFAT:49: error: ‘FRESULT’ was not declared in this scope
    testusbhostFAT:62: error: expected constructor, destructor, or type conversion before ‘*’ token
    testusbhostFAT:69: error: expected initializer before ‘*’ token
    testusbhostFAT:70: error: ‘part_t’ does not name a type
    testusbhostFAT:71: error: ‘storage_t’ does not name a type
    testusbhostFAT.ino: In function ‘void setup()’:
    testusbhostFAT:105: error: ‘_VOLUMES’ was not declared in this scope
    testusbhostFAT:106: error: ‘Fats’ was not declared in this scope
    testusbhostFAT:172: error: ‘Usb’ was not declared in this scope
    testusbhostFAT:176: error: ‘Usb’ was not declared in this scope
    testusbhostFAT:181: error: ‘Usb’ was not declared in this scope
    testusbhostFAT.ino: At global scope:
    testusbhostFAT:289: error: variable or field ‘die’ declared void
    testusbhostFAT:289: error: ‘FRESULT’ was not declared in this scope

    Please advise; Want to run it on Mega ADK.


    • You can’t compile the test in the Arduino IDE. Please use the bundled makefile:
      Also please update to the newest version of the submodules by executing the following command:

      git submodule foreach --recursive git pull origin master

      See the readme for more information:

      • xxxajk

        As of a couple days ago, you may use the Arduino IDE to compile and play with the example.
        You will find that using make will result in a smaller binary since I set better compile options.

        • nelson

          sorry i know the post was a bit dated. Im also trying out the ‘testusbhostfat’ demo on my arduino mega2560. Im having the same problems as Kabir. Ive already installed git, cloned and updated. I’m stumped. Thanks.

          testusbhostFAT:76: error: variable or field ‘die’ declared void
          testusbhostFAT:76: error: ‘FRESULT’ was not declared in this scope
          testusbhostFAT:88: error: expected constructor, destructor, or type conversion before ‘*’ token
          testusbhostFAT:95: error: expected initializer before ‘*’ token
          testusbhostFAT:96: error: ‘part_t’ does not name a type
          testusbhostFAT:97: error: ‘storage_t’ does not name a type
          testusbhostFAT.ino: In function ‘void setup()’:
          testusbhostFAT:178: error: ‘_VOLUMES’ was not declared in this scope
          testusbhostFAT:179: error: ‘Fats’ was not declared in this scope
          testusbhostFAT:180: error: ‘sto’ was not declared in this scope
          testusbhostFAT:180: error: expected type-specifier before ‘pvt_t’
          testusbhostFAT:180: error: expected `;’ before ‘pvt_t’
          testusbhostFAT:181: error: ‘pvt_t’ was not declared in this scope
          testusbhostFAT:181: error: expected primary-expression before ‘)’ token
          testusbhostFAT:181: error: expected `)’ before ‘sto’
          testusbhostFAT:285: error: ‘InitStorage’ was not declared in this scope
          testusbhostFAT.ino: At global scope:
          testusbhostFAT:399: error: variable or field ‘die’ declared void
          testusbhostFAT:399: error: ‘FRESULT’ was not declared in this scope

      • kevin

        How to compile the testusbhostFAT.ino without the Arduino IDE? Thanks.

  • jony

    hey thats great !

    i want to connect arduino uno bia usb to usb host shield on another arduino is it possible?
    can i add usb HUB and communicate with both USB PEN DRIVE and the uno?

  • Don Vukovic

    Has any more effort been made to connect a USB WiFi dongle ?

    Does anyone need help in getting this working with WiFi ?

    I am available.


  • Carlos

    when I try to compile the file with the Arduino IDE I get the following error:
    testusbhostFAT.ino: In function ‘void loop ()’:
    testusbhostFAT.ino: 341:46: error: ‘on’ was not declared In this scope
    testusbhostFAT.ino: 344:46: error: ‘off’ was not declared In this scope

    to give values ​​to ‘on = 1′ and ‘off = 0′ for example shows:

    In file included from ~ / sketchbook / libraries / generic_storage / FAT.c: 4:0:
    / home / xscharlie / sketchbook / libraries / generic_storage / FAT / FATFS / src / ff.c: In function ‘f_write’:
    / home / xscharlie / sketchbook / libraries / generic_storage / FAT / FATFS / src / ff.c: 2868:1: error: unable to find a register to spill in class ‘POINTER_REGS’
    ~ / sketchbook / libraries / generic_storage / FAT / FATFS / src / ff.c: 2868:1: error: this is the insn:
    (insn 197 196 198 33 (set (reg: HI 26 r26)
             (reg / f: HI 231))
    ~ / sketchbook / libraries / generic_storage / FAT / FATFS / src / ff.c: 2825} 32 {* movhi
    ~ / sketchbook / libraries / generic_storage / FAT / FATFS / src / ff.c: 2868: confused by View earlier errors, bailing out

    any ideas?

  • avtop

    I am asking about modem dongle i didn’t find where to ask, quarry so posting here
    I am trying to use USB2.0 lib for usb modem dongle but it is reset after reach USB_ATTACHED_SUBSTATE_WAIT_SOF 0×50
    this trace data
    Task State = 11
    Task State = 12
    Task State = 20
    Task State = 30
    Task State = 40
    Task State = 50
    Task State = 51
    Task State = 11 again repeat loop
    I am not able to find problem , what I need to check

  • avtop

    Thx Oleg for replay
    My device is Huawei E372
    idVendor : 0x12d1 (4817)
    idProduct : 0×1505 (5381)
    and same for 2nd device is EC168C same for both devices
    its Swtichable from zero cd to modem

  • avtop

    Hi Oleg
    device is connecting/disconnecting
    Task HSRL READ = 3
    Task State = 11
    Task HSRL READ = 3
    Task State = 12
    Task HSRL READ = 3
    Task State = 20
    Task HSRL READ = 83
    Task State = 30
    Task HSRL READ = 83
    Task State = 40
    Task HSRL READ = 83
    Task State = 50
    Task HSRL READ = 83
    Task HIRQ READ = 69
    Task HSRL READ = 3

    Conf.LS: 0
    Task State = 51
    Task HSRL READ = 3

    i checked 2 usb modem

  • avtop

    I am running USB_desc sketch, first I want see device desc than start, this output is add debug print in usb.cpp to find problem

  • avtop

    hi oleg
    is this due to power? is that any way check this, I am using external 12v dc supply.
    is that all device connect the same way to get device desc.


  • avtop

    Hi Oleg

    Yes, USBdesc Sketch can read all my USBHDD,USB Bluetooth,USB wifi and pen drive I checked but its resetting USB Data Modem
    and that USB Data Modem getting all data in computer
    I have checked with this code also;u=29238;sa=showPosts
    with same code and old v1.0 lib of yours its also get all thing as above but not that modem
    pls help why its reset and bus state goes to open state as shown above as soon as device connect its shows bus open state HSRL is 3 and aging when issue SOF bus set open state


  • avtop

    Hi Oleg
    Is that any cap. on power pin to power or discharge problem
    when connect modem with extension cable its start resetting even on computer for a minute but same I connect this through hub even very low power usb cable its working on computers
    Is that cap. or res. require on my Arduino Mega ADK v2 board

  • avtop

    Hi Oleg
    Through Hub Sketch and through Hub USB Modem also giving device desc. no resetting

  • Dimitri

    Hello, unfortunately I can’t register on this website (it keeps saying: please fill the form, even if I do) so I write here.
    sorry if it is off-topic, but I have some questions about the V.2.0 library:

    in the old library, I had to make an EP_RECORD struct and fill it with the informations about the endpoints. Then I could plug this struct to the device using the SetDevTableEntry method. Last, I could use SetConf method to have the device ready.
    Now in the v.2.0 something changed, EP_RECORD is now EpInfo if I’m not wrong..and the method to attach this struct to the device is setEpInfoEntry. Am I right?
    the only difference is that this new method now requires the number of EPs?
    Then I was wondering what are used for those 3 members inside the struct:
    bmSndToggle, bmRcvToggle, bmNakPower,
    and how should I fill them (if I can get those values from my device).
    Last question is, how can I obtain the address assigned to my device, in order to call those methods correctly (now I’m assuming the address is always 1).
    After I set all those things, I can try to use InTransfer to my device and see what I get. :)
    many thanks

    • Hello Dimitri,

      You don’t need to use seEpInfoEntry(). You allocate epInfo and fill it directly, like here 0>

      Toggles are set in transfer functions, you only need to reset them once during driver initialization. NAK power is number of automatic retries expressed as a number of 2, the number of NAKs counted is 2^bmNakPower – 1 . Certain useful values for Nak power are defined here ->

      • Dimitri

        hi, thanks for the reply :)
        I can’t find the allocation on that code..perhaps I need to do something like this:
        EpInfo epInfo[NUM_EP_OF_MY_DEVICE];
        globally, and then fill it inside my “configuration” method?
        so the library already knows that a declared and defined EpInfo struct is the right one to use for the device?
        then I have some other doubts..
        1) how can I get the address assigned to my device? now I’m assuming it’s 1, but who knows..
        2) about the 2 toggles, so I only need to write 0 to them during the EpInfo filling..and then forget about them?
        3) since I don’t know at all what NAK value should be suited for my application, what could you recommend me to use, as a start?
        4) Interval/poll value for EPs is not needed anymore (I can’t find it) or maybe should be set elsewhere?
        5) this line:
        ep_record[ CONTROL_EP ] = *( Usb.getDevTableEntry( 0,0 ));
        (taken from an example sketch of legacy library)
        to me is not clear.. what’s for?
        6) I can’t find infos about the Control EP of my device, descriptors only shows input and output endpoints..not the control endpoint.

        sorry for all those questions, I hope you can help me

  • Dimitri

    thank you, could you please help me understand the other questions as well?

  • avtop

    Hi Oleg
    I am trying to understand USBHub code, but I am not able get it,
    I am trying to send cntrol msg to modem to switch Mode what I do to get device address,info
    like USB.? to get address,epinfo

    thx for your all help

  • avtop

    Hi Oleg
    I have gone through all the help documents but I am not able get pointer to start further
    after I send Control Desc to device but I am not able to find which variable/function to go further even I start new like
    USB Usb;
    if( Usb.getUsbTaskState() == USB_STATE_RUNNING )
    But still not able go

  • avtop

    hi Oleg
    I run USBHub Sketch and list is
    I put Manual Address , How I can get pdev



    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0110
    Device class: 09
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 08
    Vendor ID: 03EB
    Product ID: 0902
    Revision ID: 0100
    Mfg.string index: 00
    Prod.string index: 00
    Serial number index: 00
    Number of conf.: 01

    Configuration descriptor:
    Length: 09
    Descriptor type: 02
    Total length: 0022
    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

    Hub Descriptor:
    bDescLength: 9
    bDescriptorType: 29
    bNbrPorts: 4
    LogPwrSwitchMode: 1
    CompoundDevice: 0
    OverCurrentProtectMode: 1
    TTThinkTime: 0
    Reserved: 0
    bPwrOn2PwrGood: 32
    bHubContrCurrent: 64


    Device descriptor:
    Descriptor Length: 12
    Descriptor type: 01
    USB version: 0110
    Device class: 00
    Device Subclass: 00
    Device Protocol: 00
    Max.packet size: 40
    Vendor ID: 12D1
    Product ID: 1505
    Revision ID: 0000
    Mfg.string index: 01
    Prod.string index: 02
    Serial number index: 04
    Number of conf.: 01

    Configuration descriptor:
    Length: 09
    Descriptor type: 02
    Total length: 0020
    Num.intf: 01
    Conf.value: 01
    Conf.string: 00
    Attr.: A0
    Max.pwr: FA

    Interface descriptor:
    Intf.number: 00
    Alt.: 00
    Endpoints: 02
    Intf. Class: 08
    Intf. Subclass: 06
    Intf. Protocol: 50
    Intf.string: 00

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

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



    This code is write after
    if (millis() >= next_time)

    byte rcode;
    byte addr;
    byte num_conf = 0;
    addr = 09;
    Serial.println(“\r\nSetting Feture …….”);
    rcode = Hub1.SetHubFeature(1);
    Serial.println(“\r\nSetting Reset……”);

    I got error 0D
    this is capature list Snoopy Pro

    1 in down n/a 0.001 GET_DESCRIPTOR_FROM_DEVICE
    1 in up n/a 0.001 CONTROL_TRANSFER 12 01 10 01 00 00 00 40 0×00000000
    Header (length: 80)

    SequenceNumber: 1

    Function: 0008 (CONTROL_TRANSFER)

    PipeHandle: f3229564

    0000: 80 06 00 01 00 00 12 00

    bmRequestType: 80

    DIR: Device-To-Host

    TYPE: Standard
    bRequest: 06

    Descriptor Type: 0×0001


    TransferBuffer: 0×00000012 (18)
    0000: 12 01 10 01 00 00 00 40 d1 12 05 15 00 00 01 02
    0010: 04 01

    bLength : 0×12 (18)

    bDescriptorType : 0×01 (1)

    bcdUSB : 0×0110 (272)

    bDeviceClass : 0×00 (0)

    bDeviceSubClass : 0×00 (0)

    bDeviceProtocol : 0×00 (0)

    bMaxPacketSize0 : 0×40 (64)

    idVendor : 0x12d1 (4817)

    idProduct : 0×1505 (5381)

    bcdDevice : 0×0000 (0)

    iManufacturer : 0×01 (1)

    iProduct : 0×02 (2)

    iSerialNumber : 0×04 (4)

    bNumConfigurations : 0×01 (1)

    2 in down n/a 0.001 GET_DESCRIPTOR_FROM_DEVICE
    2 in up n/a 0.002 CONTROL_TRANSFER 09 02 20 00 01 01 00 a0 0×00000000

    3 in down n/a 0.002 GET_DESCRIPTOR_FROM_DEVICE
    3 in up n/a 0.002 CONTROL_TRANSFER 09 02 20 00 01 01 00 a0 0×00000000

    4 ??? down n/a 0.002 SELECT_CONFIGURATION

    4 ??? up n/a 0.002 SELECT_CONFIGURATION 0×00000000

    5 out down n/a 0.002 SET_FEATURE_TO_DEVICE
    5 out up n/a 0.003 CONTROL_TRANSFER - 0×00000000

    URB Header (length: 80)

    SequenceNumber: 5

    Function: 0008 (CONTROL_TRANSFER)

    PipeHandle: f3229564

    0000: 00 03 01 00 00 00 00 00

    bmRequestType: 00

    DIR: Host-To-Device

    TYPE: Standard

    RECIPIENT: Device

    bRequest: 03


    No TransferBuffer

    6 ??? down n/a 0.003 RESET_PIPE

    6 ??? up n/a 0.003 RESET_PIPE 0×00000000

    7 ??? down n/a 0.003 RESET_PIPE

    7 ??? up n/a 0.003 RESET_PIPE 0×00000000

  • Andrey

    Hello Oleg,
    Could you answer a question. If i want to write and read information without a file system from hard disk, is it enough to use masstorage.h and masstorage.cpp?

  • Benjamin Richards

    I don’t know if I am in the right location. However I’m looking for instructions and sample code for getting the the sd shield installed on an arduino uno to act as a usb storage device but not to the arduino itself but to the computer where it is attached to. The sd shield will have a 16 gb sdhc card installed.
    Here is the in depth description of what I’d like to see as the outcome of this project:
    A USB mass storage device with bootable partion(s) the plural is optional the bootable aspect is mandatory.
    B software package for installing arduino ide to the host computer loaded onto the sd card
    C backup of the entire sketch that runs the arduino loaded onto the sd card
    D drivers or code, loaded on the sd card in an auto-run executable for windows or a disk image for mac os x on powerPC or a tar.gz package for linux, such that any machine can recognise the gprs/ gsm shield as a network interface by both the arduino and host computer analogous to cellphone via usb host shield post that I saw,

    • This is not the right place – we are doing USB host code. You first need to figure out how to run mass storage device code on 8u2 – the device used on UNO to provide USB to serial conversion. I’m not sure this is even possible, look at the Atmel site to see if they have any ms examples for this micro.

  • Shivarama

    Could you please release a video showing how to interface the mass storage device using the USB Host Shield 2.0. Also can you inform if any vendors are available for USB Host Shield 2.0 in India.

  • nelson


    Im kind of a newb when it comes to this USB host shield I purchased. What im trying to do is attach a hub onto the usb host shield and extend the number of ports to 4, plug 4 usb flash drives on each port, i would then transfer files between the usb flash drives. is this even possible, could you point me to the right direction please. Thanks and great work!

  • nelson

    Hi Oleg,

    Thanks for the reply. This is exciting news for me at least now I know its possible.I forgot to mention im using a mega2560 with 2.4tft touchscreen lcd (for GUI) and the usb host shield + hub. no PC connected so all file transfers will happen between the mega, host shield and hub only like a standalone usb file organizer. If you have like suggestions for reading and libraries you think i might need, it would help a lot. Thanks again great news!

  • etherViz

    I’m having some problems getting the USBHostFAT examples to compile on the Due. I understand the problem is all the AVR files that it wants to link in, instead of their SAM equivalents. Before I start tearing apart the FAT libraries to make them compatible I thought I would ask if there is an easy solution, existing fix, or perhaps a fork in beta.

  • wernert

    I’m experiencing problems to compile the example called testusbhostFAT for my AtMega1280.

    The error message I get says: “InitStorage() was not declared in this scope”.

    Please note that I downloaded and installed xmem2, generic storage and rtclib.

    Any advice?

  • wernert

    Thank you very much xxxajk. It does not look like my version of GIT understands the -recursive command. When I execute the command just like you gave it, it generates a new directory called -recursive and then puts some files in there but not all the files from the sub-directories. I use git version 1.9.2.mysysgit.0

  • wernert

    Since my GIT can not handle recursive, I was able to download all the individual libraries using this:
    git clone
    git clone
    git clone
    git clone
    git clone
    git clone
    git clone
    git clone

    It now compiles for a while and then output the following error message:

    C:\Users\werner\Documents\Arduino\libraries\RTClib\set_system_time.c: In function ‘set_system_time’:
    C:\Users\werner\Documents\Arduino\libraries\RTClib\set_system_time.c:45: error: ‘for’ loop initial declaration used outside C99 mode

    I use: Arduino: 1.5.6-r2 (Windows 8), Board: “Arduino ATmega1280″

    This looks more like an RTClib issue that and issue with the example itself.

  • wernert

    I got it working! :)
    Here is what I had to do: First I deleteted all the libraries from my Arduino section and then re-added them. There was still a compile error for FAT.cpp -> RTClock() -> return;
    So I just made it return zero so it compiled and the example worked. Thank you very much. This is excellent!

  • wiesiek

    Arduino: 1.5.6-r2 (Windows Vista), Board: ‘Arduino Tmega2560′ improved library
    and everything is OK. Operates without external memory and RTC. Reads and Pen Drives.
    If anyone needs these files, please contact us by e-mail: wiesiek1p
    Ps: Poor writing in English. Files Generic Mass Storage.

  • wiesiek

    After processing my memory is 6.5 k

    • xxxajk

      Try the update for RTClib.
      I did a hack that bypasses C99 requirement by using C++ and declaring it as C.
      This should allow the ATOMIC_BLOCK for updating the system_time variable to work.

      Please go to, register and file any remaining problems you have there, because I don’t visit this area much.

  • wernert

    Thanks. I tried it and still had a C99 compile error. I reported it at

    • Felipe


      I’m having the exact same problem. I’m trying to compile from IDE version 1.5.6-r2 with all library files updated.

      Wernerterreb, may I ask you what is the workaround to compile? I’ve already tried to change to zero.

      Thank you.

    • Hi I succeed compiled everything and made it work.
      The problem is there is a bug in the set_system_time.c of RTCLib. It duplicated define the function. You just need to remove one definition.

      extern “C” {
      extern volatile time_t __system_time;

      set_system_time(time_t timestamp) {

      __system_time = timestamp;

  • Hi xxajk,
    I have made the USB shield working with mega2560 when I plug and unplug my USB stick. It works great independently. Its behavior meet my expectation.
    But when there is an ethernet shield. there are lots of confliction.
    1. there are a lot of MICRO duplicated with Sdlib.
    2. USB stick can not be detected after I change the Sdlib to remove the duplicated MICRO definition.

    I know the ethernet shield using ICSP and PIN 10,11,12,13, and PIN 4 for SD card.
    My question is How can I make the USB shield work ethernet work together?.

    Thanks a head, xxajk

    • xxxajk

      Which Ethernet shield are you using?

      You will need to determine if both SPI devices speak the same SPI protocols, and share SPI somehow.


      Perhaps wait for my IP stack to support ethernet on USB.
      Perhaps wait for my IP stack to support your shield, if that is even possible.
      Right now the IP stack only supports serial devices, see my github repository if interested.

      • I already made the the USB shield working with Ethernet shield and CAN bus shield.
        I modified your library.

        What time you will release the IP stack support for ethernet shield?
        Thanks xxxajk.

  • I am using official ethernet shields. It looks like USB shield and ethernet shield can not live together.
    I did some research, it looks like if I change the USB Shield Selection PIN from 10 to other unused PIN, they should be able to work together.
    But I do not find the file that has the selection pin definition as #define MAX_SS 10.
    But some version has file Max3421e_constants.h, it has the MAX_SS definition.
    for example,
    If my test is successful, I may purchase a bunch of USB shields. I am doing comparative testing and prototype now.

  • 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

  • nupur

    i am trying to read and write in pen drive using testusbhost.ino file from examples of usbhostshield 2.0 library on arduino mega adk. Create new file and read command are working great but theres some problem in the write command. if i unplug the pendrive from arduino after writing something to a file and plug it into my laptop, i do not see anything written in the file. But reading from the file during the execution of the code itself after writing something prints the right result. dont know why this is happening .
    it would be great if someone can help.

  • Hi Oleg Mazurov,
    I found there is another shield at:
    I am not sure this shield is as same as your USB shield.
    Please tell me are there any difference?


  • Hi xxxajk,
    I replace my modbus server with new release.
    It has nothing to do with USB shield mass storage code and its function.
    But there are error when to create direction at USB stick memory. the error code =12 or 17

    FRESULT f_mkdir(const TCHAR* path)

    it mean:
    FR_NOT_ENABLED, /* (12) The volume has no work area */
    FR_NOT_ENOUGH_CORE, /* (17) LFN working buffer could not be allocated */

    Please help me what is wrong with USB code?


  • I have 4 sheilds. I did some tests.
    My application needs the shield to transfer/save a lot of files from SD card to the USB memory stick.
    generally, its function is ok but the performance is not that good. I mean it is too slow.
    Are there any plan to improve the performance of the shield for mass storage function? it looks like the initialization is very slow too.


  • OmkarDokur

    Dear Oleg,

    I have Arduino Mega 2560, USB Host Shield, 250 GB Sandisk Hard drive and Cammera Shield. Can i use these libraries to store images from camera into the Harddrive?

    Please advise !

    Thanks and regards,

  • OmkarDokur

    In your testhostfat example why there is a delay of 27 seconds before writing to the file?? Is this necessary?? Can i remove this delay ???

  • OmkarDokur

    This part of the code is taking more time.. Do we really need to make parts ready?? If yes, do we need make parts ready every time we write to the file ??
    This part is taking time of 27 seconds. Please guide me !
    if(usbon) {
    if(partsready && !fatready) {
    if(cpart > 0) fatready = true;
    // This is horrible, and needs to be moved elsewhere!
    for(int B = 0; B GetAddress() != NULL)) {

    // Build a list.
    int ML = UHS_USB_BulkOnly[B]->GetbMaxLUN();
    //printf(“MAXLUN = %i\r\n”, ML);
    for(int i = 0; i LUNIsGood(i)) {
    partsready = true;
    ((pvt_t *)(sto[i].private_data))->lun = i;
    ((pvt_t *)(sto[i].private_data))->B = B;
    sto[i].Reads = *UHS_USB_BulkOnly_Read;
    sto[i].Writes = *UHS_USB_BulkOnly_Write;
    sto[i].Status = *UHS_USB_BulkOnly_Status;
    sto[i].Initialize = *UHS_USB_BulkOnly_Initialize;
    sto[i].Commit = *UHS_USB_BulkOnly_Commit;
    sto[i].TotalSectors = UHS_USB_BulkOnly[B]->GetCapacity(i);
    sto[i].SectorSize = UHS_USB_BulkOnly[B]->GetSectorSize(i);
    printf_P(PSTR(“LUN:\t\t%u\r\n”), i);
    printf_P(PSTR(“Total Sectors:\t%08lx\t%lu\r\n”), sto[i].TotalSectors, sto[i].TotalSectors);
    printf_P(PSTR(“Sector Size:\t%04x\t\t%u\r\n”), sto[i].SectorSize, sto[i].SectorSize);
    // get the partition data…
    PT = new PCPartition;

    if(!PT->Init(&sto[i])) {
    part_t *apart;
    for(int j = 0; j GetPart(j);
    if(apart != NULL && apart->type != 0×00) {
    memcpy(&(parts[cpart]), apart, sizeof (part_t));
    printf_P(PSTR(“Partition %u type %#02x\r\n”), j, parts[cpart].type);
    // for now
    if(isfat(parts[cpart].type)) {
    Fats[cpart] = new PFAT(&sto[i], cpart, parts[cpart].firstSector);
    //int r = Fats[cpart]->Good();
    if(Fats[cpart]->MountStatus()) {
    delete Fats[cpart];
    Fats[cpart] = NULL;
    else cpart++;
    delete PT;

    if(fatready) {
    FRESULT rc; /* Result code */
    UINT bw, br, i;
    if(!notified) {
    notified = true;
    FATFS *fs = NULL;
    for(int zz = 0; zz volmap == 0) fs = Fats[zz]->ffs;
    printf_P(PSTR(“\r\nOpen an existing file (message.txt).\r\n”));
    rc = f_open(&My_File_Object_x, “0:/MESSAGE.TXT”, FA_READ);
    if(rc) printf_P(PSTR(“Error %i, message.txt not found.\r\n”), rc);
    else {
    printf_P(PSTR(“\r\nType the file content.\r\n”));
    for(;;) {
    rc = f_read(&My_File_Object_x, My_Buff_x, mbxs, &br); /* Read a chunk of file */
    if(rc || !br) break; /* Error or end of file */
    for(i = 0; i drv, CTRL_COMMIT, 0);
    printf_P(PSTR(“\r\nTest completed.\r\n”));



  • Daniel


    Is there already some library running on the Arduino Uno board?

  • Jacks

    I just got an Intel Galileo and noticed it is compatible with the “regular” usb host library, which leads me to the question: is the Galileo supported / has anyone got it working with the usb host library 2.0? If not, could anyone give me some pointers where to look at for a custom implementation?

  • Daniel

    Hello, I am testing the example “testusbhostFAT” and did not work well. When I run the program with a USB host to MEGA board and 4GB USB in FAT or FAT32 shows me the following:

    Current UsbDEBUGlvl 51
    '+' and '-' increase/decrease by 0x01
    '.' and ',' increase/decrease by 0x10
    't' will run a 10MB write/read test and print out the time it took.
    'e' will toggle vbus off for a few moments.

    Long filename support: Enabled
    Total EXT RAM banks 0
    Available heap: 6358 Bytes
    SP 21f0
    VBUS on
    USB state = 20
    USB state = 40
    USB state = 50
    USB state = 51
    USB state = a0
    Available heap: 5900 Bytes
    Available heap: 5900 Bytes

    when I send ‘t’ (without the quotes) using the serial monitor does nothing, still shows “Available heap: 5900 Bytes”

    That is what is happening? How can I solve it?

    Thanks you.

  • USB state = a0
    This means that the device was no enumerated. Re-plug in the device.
    Installing the vbus switch solves this problem automatically, see here:

    Once the device is properly enumerated, you will see:
    USB state = 90

    followed by information about the device, partition information (if partitions exist), and finally a short test.
    The 10MB test I left as a manual option in order to let you do speed tests. Not everyone may want to run such a test.

  • lee

    I’m not sure if this is the correct forum for this enquiry, so please go easy on me, if my question(s) are too low-brow!

    PREAMBLE: I’m working on a solar-science project for poorly-resourced high-schools in Ireland, using an Adafruit sensor (INA219) to measure the voltage and current from a solar-panel, using an I2C connection to a Leonardo board. I’ve written a little script that “prints” the measured Voltage, Current, and Power to my laptop via the serial-port connection – all works fine. Now the teachers are complaining that they can’t justify setting-aside a computer for long-term (a few weeks) of data-logging form the panel, and are not comfortable/interested in working with a RPi.

    PROBLEM: I bought a USB host-shield from Maplin (seems to be fabricated by Linksprite?) with the hope/idea of saving the solar-panel data directly to a USB thumb-drive. However, I now find myself completely outclassed by the complexity of the USB_Host_library_2 files! I can’t even understand IF it is possible to save three or four float variables to a USB stick every 10 minutes or so, let alone the commands to actually do it!

    Do you know of any existing (simple!?) example code that might help me figure this out? I understand that even the simple-sounding action of appending lines to a CSV or TXT file might require fiendishly complicated library files, but surely some kind soul has already tried it, and would be willing to share?

    Many thanks for any help/advice you can give!

    Problem: To get around this I bought a USB host

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