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:
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.
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:
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:
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:
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:
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!
thanks, this was helpful!
johanzebin said this on March 9, 2009 at 8:00 pm |
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!
omikun said this on March 14, 2009 at 5:56 am |
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
ratdad said this on March 14, 2009 at 1:17 pm |
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
nitlogic said this on March 30, 2009 at 7:03 am |
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
ratdad said this on April 1, 2009 at 10:08 am |
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.
Starbug said this on June 27, 2009 at 9:06 am |
Starbug,
Thanks for the comment. sir Morris is the source of uFat2. Try this link:
http://arduinonut.blogspot.com/2009/01/there-has-been-flurry-of-activity.html
ratdad said this on July 2, 2009 at 3:58 pm |
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!
Serg said this on October 8, 2009 at 8:28 pm |
good post dude, full of good info.
kdd said this on February 24, 2010 at 3:37 am |
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)
bandsxbands said this on March 3, 2010 at 8:37 am |
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.)
bandsxbands said this on March 3, 2010 at 10:32 am |
[…] out Mal has accomplished exactly what I set out to do with my SD […]
2 more links | DannyBlog said this on April 6, 2010 at 5:51 am |
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
John Hobson said this on October 9, 2010 at 3:48 am |
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.
ratdad said this on November 15, 2010 at 8:05 pm |
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
Steve said this on December 12, 2010 at 7:02 am |
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.
ratdad said this on December 13, 2010 at 1:11 am |
[…] 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 […]
SD Memory Reprise « MAL’s Adventures in Electronics Blog said this on February 16, 2011 at 3:15 am |
[…] those who still want the circuit, it’s in this post, also explaining it more in […]
SD communication problems | Andreas's development log said this on May 4, 2011 at 10:40 am |
эффективная диета 10 кг за 6 днейдиетолог маргарита трофимовамедовый самомассаж для похудениясалаты с яблочным уксусом для похудениямедицинские вузы санкт петербурга диетологдиета при сахорномбезуглеводная диета врача из израилякак сделать чтобы лицо похуделопохудение с доктором сайковымпоиск кремлевская диетана второй неделе диетысайт бейсплатных способов похуденя без физических нагрузокдиета для восстановления желудкабыстро действенная диетадиеты от знаменитых спортсменовоздоровительная зарядка от спортсменовдиета при повышенном содержанием сахара в кровиправильно питание .диеты раздельного питаниянано пластыри для похудения в таразедиета стол №1 5антицеллюлитный пластырь
lypeCelve said this on July 31, 2011 at 12:03 pm |
backlinks…
[…]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…
backlinks said this on November 9, 2011 at 7:42 am |
Gorgeous tea lights…
[…]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…
Gorgeous tea lights said this on April 19, 2012 at 4:45 pm |
Simple Electronic and Microcontroller Projects with tutorials…
[…]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…
Simple Electronic and Microcontroller Projects with tutorials said this on April 28, 2012 at 7:36 am |
D3v IT bendruominė…
[…]Interfacing Arduino to micro SD Memory « MAL's Adventures in Electronics Blog[…]…
D3v IT bendruominė said this on May 4, 2012 at 6:56 pm |
Привет
Наверника у многих дома есть свои любимые четвероногие друзья, и некоторые из вас не будут против показать их фотки.
А вот мои два песика, хоть и дворняшки только они мне вовсю дороги.
[IMG – http://agranomic.ru/images/users/photos/medium/c72d758cf6c89d899c23e676cc84845b.jpg%5B/IMG –
С нетерпением жду фотки с вашими любыми животными.
vAspolk said this on June 16, 2013 at 3:47 am |