Interfacing Arduino to micro SD Memory

I’m working on an Arduino project that requires oodles of storage. For no reason in particular, I had planned to use a micro SD memory card. I found out quickly that there were many hardware choices that seemed to suit my needs. I chose the Sparkfun Breakout Board for DOSonCHIP FAT16 FAT32 uSD Module because (1) it looked easy to implement and (2) it had a real time clock built in. Supposedly, this product “makes it easy to add up to 32GB of storage to your project without adding software complexity”. The example cited on the product web page describes the programming simplicity: “Datalogging is now as easy as sending ‘md CHAT’ to make a directory!”
After reading various blogs and Arduino forum posts, I understood that even a simplified FAT implementation for the micro SD card could consume most of the free memory on the Arduino. Since the DOSonChip promised to handle all of the FAT issues and more, it seemed like a good choice.
I wired the module to my Arduino and quickly established communication through the device’s UART interface. However I did not get the expected response from the DOSonCHIP module. The folks at WEARABLE INC., the makers of the DOSonCHIPTM CD17B10 were quick to respond to my email inquiries. Sadly, they’ve made big changes to the device’s command structure. They now utilize a packet-based protocol. Matt, the tech support guy who responded to my emails, did give me the instructions to revert back to the 1.02 version firmware (not to be confused with the version 1.02 API), but my RS232 to 5V converter only has TX and RX. I need CTS and RTS to upload the 1.02 firmware.

I was stuck for a week or so as I pondered my options. (a) buy or build a four wire RS232 level shifter; (b) convert the DOSonCHIPTM sample code to work with the Arduino – not very appealing as I haven’t programmed a big project in C for 10 years (d) use Ladyada’s FAT implementation (e) what is this uFAT thing being discussed over at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1206874649/84#84 ?

A discussion about the pros and cons of these choices could fill an entire blog post. However, with my particular combination of resources and limitations I chose to try out uFAT – uFAT2 actually.

I have the Sparkfun breakout board for the micro SD flash card. uFAt2 and many of the other flash card libraries were written for SD or MMC memory. They all communicate to the microcontroller via the SPI bus. Not all micro SD memory cards support SPI mode communications (see http://en.wikipedia.org/wiki/MicroSD ). The Transcend micro SD card that I purchased supports SPI communication, so it seemed that I had a good chance of getting it all working.

I wired the two devices together like this:

spi-to-usd
When using SPi communications on the Arduino, SPI bus pins are predefined. MOSI, MISO, and SCK can only be Port B pins 3, 4 and 5, as described above, the Chip Select line, however, has no such restrictions. Each device on the SPI bus requires its own chip select. Here’s more info about SPI and Atmel.

I used a voltage divider network and resistor values similar to Ladyada’s circuit in her GPS Shield. It wasn’t clear to me as to why she chose to use the Zener diode on the CS line. I did not include it and my circuit works. Assuming a 5V output from the Arduino, we can use the voltage divider rule to calculate that the micro SD will see 3.4v as a logic high input.

voltage-divider-rule
Next I downloaded and installed the uFAT2 library provided by Arduino Nut. I inserted the micro SD card and powered up the circuit. uFAT2 comes with a demo sketch that helps to explain the operation of the uFAT library. I compiled the demo, which is called uFAT_example.pde, by the way.

I uploaded the sketch to the Arduino and selected the Serial Monitor. I got this message:

ufat-ser-mon
Success? Maybe. I needed to copy a file named data.bin to the micro SD so that I could see uFAT do its thing. I selected a jpeg image of the state of RI. It’s a 4MB file, so I guess it renders the state at nearly full size. I put my memory card into my AtivaTM Memory Card USB Drive, microSDTM (Office Depot, 10 bucks) and inserted it into one of my computer’s USB ports. I copied the file and renamed it to data.bin, this time the results were:

ufat-ser-mon-2
It is working! Eventually I’ll need to log csv files, so the DevicePrint library, also from ArduinoNut, is also of interest to me. I downloaded and installed the DevicePrint library. It comes with an example program. In order to see it run, I renamed the file on my memory card to data.txt. I ran the sketch got this message:

ufat-ser-mon-3
About 2.5 hours later, the sketch completed writing to my file. Memo to self: this is a good time to use debug code. When the program finishes it displays the message below:

ufat-ser-mon-4a
So in my opinion uFAT2 is a great library. It will work with micro SD memory IF the memory uses the optional SPI communication mode. uFAT2 is a great optimization for the competing interests of simplicity, ease of use and memory footprint. Furthermore the DevicePrint library increases the utility of the uFAT2 library.

If you are new to Arduino or flash memory operation, as I am, you may find this daunting. My advice: dig in, follow along, ask for help and you’ll soon be logging data!

Advertisements

~ by ratdad on February 24, 2009.

24 Responses to “Interfacing Arduino to micro SD Memory”

  1. thanks, this was helpful!

  2. Check out the new development at http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235125412

    SirMorris has made a new wrapper library called DevicePrint that works really well. Just load it up with the configuration you have already and it’ll work great. (change data.bin to data.txt on the drive is all you need to do) You can write to it with dp.print(“text”); just like regular print and println.

    Happy data logging!

  3. SirMorris deserves a lot of credit. I’ve learned so much about uSD memory interfacing from the his postings on the Arduino.cc forum and from his blog as well. Thanks for your comment.

    If you’d like to discuss the difficulties that you’ve faced as an Arduino newbie, I’ve made and inquiry in the forum at:
    http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1236908648
    I’m planning to hold an Arduino workshop for artists, so I’m looking for firsthand insight into the difficulties and revelation found along the way toward mastering the Arduino hardware and software.

    Thanks again,

    MAL

  4. I started to make my graduate project which a robot based on microcontroller, the question is what is better to use pic16f84 microcontroller or Atmel 8051 ? please help me

  5. nitlogic,

    I’ll give you an answer that is based more on project management than technology. When choosing between the two microcontrollers, I suggest that you consider the resources available to you. For example: have any of your classmates used either device? Heve you checked the web for user groups or manufacturer’s info.

    You project will go alot faster and you’ll probably learn more from using the device that has a bigger body of knowledge available to you.

    MAL

  6. Mal
    thanks a lot for your great presentation. I would very much like to reproduce what you have done but i am not able to find the software you are talking about. At least not the uFAT_example.pde.
    Have the libs changed completely or are there any archives?
    Keep on with your work.

  7. Please include links on libraries and sketch code used in topic. It is very hard to trace and reproduce for NewBe project if only names are mentioned. Great material anyway! Thx!

  8. good post dude, full of good info.

  9. Technology really has become one with our daily lives, and I am 99% certain that we have passed the point of no return in our relationship with technology.I don’t mean this in a bad way, of course! Societal concerns aside… I just hope that as memory becomes cheaper, the possibility of transferring our memories onto a digital medium becomes a true reality. It’s a fantasy that I daydream about all the time.(Posted using Nintendo DS running R4i SeKu)

  10. I have a love/hate relationship with virtual memory because of the way prices are always,and I domean always dropping. I hate buying SDs for my R4 / R4i at (seemingly) a cheap price only to see it become a whole lot cheaper a couple of weeks later.(Submitted from S3 for R4i Nintendo DS.)

  11. […] out Mal has accomplished exactly what I set out to do with my SD […]

  12. Post dig!

    Im really looking to get uFAT2 working on Arduino, But the google groups page that had the file hosted is no longer available. Do you have an elternate download or could you possibly upload/email me a copy?

    John

    • I’ve done some digging. Unfortunately, since I published this work, I’ve done two windows reinstalls. So I no longer can find the uFAT2 source. I looked for alternate sources on the web but have not had any luck.

  13. If you are interested using a SD Card with and Arduino you may want to check out the Storage Shield. It uses the FatFS library on an Atmega328 processor separate from the Arduino.

    The link to the project is http://www.chipstobits.com/blog/storage-shield/.

    Steve

  14. The Storage Shield looks great. The upside is that it’s a full featured mass storage device for the Arduino. It looks incredibly easy to use. The down side is that it’s more expensive that the Arduino itself. But that is OK. Variety is good for us. We now have several choices when we need to data log or otherwise have access to big memory. Depending on our project budget and time line, we can choose the storage solution that best fits our needs.

  15. […] Not much has changed since I posted my few blog entries almost two years ago. My original post SD Memory remains popular.  If you find my post interesting you’ll surely find these links worth your […]

  16. […] those who still want the circuit, it’s in this post, also explaining it more in […]

  17. эффективная диета 10 кг за 6 днейдиетолог маргарита трофимовамедовый самомассаж для похудениясалаты с яблочным уксусом для похудениямедицинские вузы санкт петербурга диетологдиета при сахорномбезуглеводная диета врача из израилякак сделать чтобы лицо похуделопохудение с доктором сайковымпоиск кремлевская диетана второй неделе диетысайт бейсплатных способов похуденя без физических нагрузокдиета для восстановления желудкабыстро действенная диетадиеты от знаменитых спортсменовоздоровительная зарядка от спортсменовдиета при повышенном содержанием сахара в кровиправильно питание .диеты раздельного питаниянано пластыри для похудения в таразедиета стол №1 5антицеллюлитный пластырь

  18. backlinks…

    […]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…

  19. Gorgeous tea lights…

    […]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…

  20. Simple Electronic and Microcontroller Projects with tutorials…

    […]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…

  21. D3v IT bendruominė…

    […]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…

  22. Привет

    Наверника у многих дома есть свои любимые четвероногие друзья, и некоторые из вас не будут против показать их фотки.

    А вот мои два песика, хоть и дворняшки только они мне вовсю дороги.

    [IMG – http://agranomic.ru/images/users/photos/medium/c72d758cf6c89d899c23e676cc84845b.jpg%5B/IMG

    С нетерпением жду фотки с вашими любыми животными.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: