How to transfer file from SD Card to USB Stick

  • Arduino Mega 2560
  • USB Host Shield
  • SD Card Module
  • CH375B USB Memory Module

These are what I have.

I have a project that can read data coming from a serial port, which is a CO2 detector, and save this data to an SD card. At the end of this phase of reading and saving data from the CO2 detector, I want to transfer these saved files from the SD card to the USB stick.

Is it possible to do this? I've researched, but I couldn't determine its feasibility.

Thank you...

Hello rakekaru

Welcome to the worldbest Arduino forum ever.

Take a search engine of your choice and ask the WWW for 'USB stick +arduino' to collect some data to be sorted out to get the needed information.

Have a nice day and enjoy coding in C++.

1 Like

Thank you for answering and friendly attitude.

I tried that kind of research. But it is not just a "USB stick + Arduino". It's a "USB stick + Arduino + SD Card". And I guess that formation of setup is kind of complicated.

Have a nice day

Make each work separately, then combine the codes.

1 Like

So break it down.

As @DrDiettrich said, you have:

  1. Arduino + SD Card
    As far as reading from the SD Card goes, the USB Stick part is irrelevant.

  2. Arduino + USB Stick
    As far as writing to the USB stick goes, the SD Card part is irrelevant.

In each case, you can further break down into

  1. The physical interface;
    eg, SPI for the SD Card, USB Host for the USB Stick

  2. A filesystem to access the files
    Hopefully, you can find one that can support two devices...

Yeah, it's possible, just might be a bit tricky. Here are my quick thoughts on how you could do it.

  • Have the SD card on the SPI bus, like normal.
  • Have the CH375 connected to one of the 3 spare hardware UART ports on the Mega. The CH375 could go on the same SPI bus as the SD card, but the benefit of having it connected to a UART is that you wouldn't have to continually open and close the files when you switch from one slave to another.
  • Open the text file on the SD card and transfer all the data into a temporary buffer on the Mega. Depending on how large the text files are, you might need to have it transferred in multiple packets.
  • Then write the temporary buffer to the CH375 module.

This library has worked well for me when I used the CH376, I haven't used the CH375 though: GitHub - djuseeq/Ch376msc: Arduino library for CH376 mass storage contoller

So I assume that setup can be possible. Thank you for answering that problem.

If that setup is possible I can transfer the file SD card to a USB stick with Arduino Mega.

Which USB library is proper for data transfer SD card to a USB stick? These libraries are what I found.

  • USB Host Shield Library
  • USB Mass Storage Library
  • SdFat Library -> That one is what I use for writing data coming from a CO2 detector to an SD Card.

Have a good day..

I will try that tricky solution. It sounds like it will work. My setup can create approximately 100 kb each run of my cycle duty. I can transfer that file to a USB stick from the temporary buffer as you said.

I will write my experience after trying that.

Thank you for your answer.

Your progam reads data from the SD card into a buffer, then writes the buffer to the stick. This part of the code is up to you.

3 Likes

So each file will be around 100 kilobytes max in size? You will have to split that into multiple transfers then, as the mega will not have enough enough SRAM to store the whole file in the buffer. Shouldn't be too hard though.

3 Likes

I must split because Mega's SRAM is 8 kb. Maybe i can send data to USB stick line by line.

SD card -> SRAM -> USB stick -> clear SRAM data -> SD Card(new data from serial)

By the way, the detector sends 8 data each second. Will it be okay for this scheme?

That assumes your data is line-based text, of course.

If you're worried about performance, it might be better to work on the filesystem's natural block size...

What does that mean? what is a "datum" here?

The detector sends Arduino this message > "N 0.0063 0.0000 0.0000 0.00 0.0000 26632 900.0 0".

I am splitting this message and I am getting this part "0.0063".

And saving this part of the message to the SD card line-by-line in txt file. This happens 8 times in a second.

Here is a source that claims to provide

Or just search the internet for

 Arduino USB host shield

Good luck!

So you're just saving one value, eg "0.0063", as a text string per line?

Shouldn't be any trouble to do that 8 times/second...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.