1

Is it possible to read a microSD card (on a breakout) through the USB port on the arduino? or perhaps another USB port I could attach to the breakout? Basically, I would like to read data off the card with my laptop without having to go and remove it each time!

  • yes, that is possible – jsotola Dec 2 '19 at 15:23
  • @jsotola Really? I wonder how (I thought the Arduino did not support USB to be used within a sketch, at least by default). – Michel Keijzers Dec 2 '19 at 15:25
  • 2
    @MichelKeijzers, use the serial connection for the data transfer ... the OP inquired about the possibility of data transfer ... i do not see a requirement to emulate a flash drive – jsotola Dec 2 '19 at 15:38
  • @jsotola ok than I think we have about the same idea (I deleted my answer based on your comment, now undeleted, shoot at it if it is incorrect though). – Michel Keijzers Dec 2 '19 at 15:43
  • 1
    @201, Just in case it is not clear from the comments or answers: USB contains many different protocols. The Arduino uses the USB serial protocol. An SDCard uses the USB mass storage protocol. Not many, if any, USB peripherals can switch between protocols. I see you have not picked a correct answer yet. If you want me to elaborate in yet another answer - add a comment stating so. – st2000 Dec 2 '19 at 17:31
1

It would be very useful, but afaik this is not possible, since the Arduino sketch you write communicates to the PC via the serial interface only.

The IDE/Arduino driver can use the USB to write your sketch and use the USB for communicating, but for sketches the USB (as direct medium) is not possible.

The SD card will not show up as a specific drive/map/folder on your PC.

Since you want to read the SD card, write in your sketch code to transmit the file(s) you want to send to the PC, to transfer them by UART, and on the PC write a program that reads the serial port and processes it.

| improve this answer | |
1

In general that's possible. But you can't read the sd card through the arduino's usb port. Instead you have to read the sd card via another protocol, e.g. SPI (look for the apropriate library) and send it to the pc via serial. You'll need software on the pc side to write the content that was read from the arduino to a file.

Take a look at the SD card tutorial to see how to read it.

| improve this answer | |
  • so, if i want to lets say read the last year history of my data from data logger, can i use SPI to make this connection between SD card and arduino? do you have an example code that may be useful? – 201 Dec 2 '19 at 16:00
  • 1
    There are examples and tutorials out in the internet (I found one for you). But may I ask why you want to use an arduino? Don't you have an sd card reader to use with usb on your laptop? – Sim Son Dec 2 '19 at 16:10
  • @201, and how is it wired for data logging? not over SPI? – Juraj Dec 2 '19 at 17:13
  • you're right, but that's actually the project i'm working on right now.. – 201 Dec 3 '19 at 11:43
0

It can't be done with an Arduino, but it can be done with other microcontrollers. You need a microcontroller with a direct USB ("native") connection plus a USB stack that is capable of acting as a USB Mass Storage Device. Something like the Teensy or chipKIT series of boards can do that.

Then you can write software that will, on command, detach the SD card from your normal sketch operation and re-attach it to the MSD device in the USB stack. You can then read and write to the SD card (though your sketch otherwise cannot access it) as much as you like - then "unmount" the MSD device and detach the SD card from it, at which point your sketch is then free to re-attach itself to the card and start using it again.

Note that the important thing here is that only one functionality can work at a time - either you can read and write the files on the card with your sketch, or you can export the device through MSD. Never both. That way leads to filesystem corruption and loss of data.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.