SD/MMC From the ground up

Here you go:

http://micro-hacker.googlegroups.com/web/DevicePrintDemo.zip

It's not a great demo, but it shows everything you need.

I really should update it :smiley:

How does this solution compare to the FileLogger library?

http://code.google.com/p/arduino-filelogger/

One difference is that with FileLogger you have to create the file, but you don't have to pre-allocate the size.

I'm curious as to the difference in data bandwidth and code space.

NOTE: They both use 'mmc' sub-files which are not the same, so if you want to try both be aware of this.

I haven't used filelogger, I suspect it utilises FAT 'properly'. The trade-off is speed and sketch size. It requires far more grunt to navigate the file allocation tables and ensure a consistent file system.

Perhaps people could post of their experiences?

C

Since I have used both DevicePrint and FileLogger and you ask for experiences, I will share mine. While both libraries represent a lot of creative work, and both are a real asset to the community, there is still some value in comparing the two.

Functionally, they both do a great job in appending to what becomes a "proper" FAT file on the SD card. Resource wise, I think the FileLogger is somewhat smaller at the stated 3601 bytes. I found the 'self adjusting' file size in FileLogger to be more convenient over the fixed file size as I did not need to anticipate the maximum file size, and can therefore switch to a bigger card when I need to.

For my application, I was not comfortable with having to use PROGMEM. This might be a personal issue, but I find PROGMEM to be somewhat arcane, and since I store my strings in EEPROM, redundant. It was indicated that I was "allowed" to bypass it in DevicePrint, but the comments in the source said otherwise.

Both libs use the mmc lib to do the grunt work, however there are differences. RD123's warning is correct about trying to have both DevicePrint and FileLogger coexist in the same build environment. Part of this is due to the directory structure. DevicePrint sees mmc as a separate lib in the libraries folder while FileLogger finds it in it's own folder.

A more important difference, however, is that FileLogger now uses a modified version of the mmc lib. I understand that this modification is optional, but basically it uses the SPI lib to handle the I/O rather than the direct port addressing that the mmc lib was using. This is an advantage for me in that it gives me the option of more easily changing the pins for the SPI that the SD write uses. (via #defines SPI.h)

The reason I cared about reallocating the pins is that with both DevicePrint and FileLogger I initially had a problem accessing a second SPI device after writing to the card. My second device (LedControl.lib) allows me to change the SPI pins and that is how I solved the problem. This may have worked for either lib. but now I have the option of changing the pins for both SPI devices, and thus the possibility of regaining some of the pins I had to give up. (I have not tried this yet.)

My, I must have too much time on my hands, but perhaps this may prove useful. I hope this is taken in the sprit in which it's written and I again thank both authors for their contributions and commitment. :slight_smile:

I tried the filelogger library before. While it is nice to append data to the file and grow it, the library always failed to initialize the card on the first write attempt, and inserting an SD card would do weird things with the serial port...

Ok I finally made it to the end of this thread trying every possible solution posted of my problem but I am still getting the following error when running serial monitor on DevicePrintDemo.pde =

uFat / DevicePrint Demo
2009 arduinonut.blogspot.com

Error  Couldn't initialise card

Even though I don't think the program went as far as searching for data.txt I put it in there in FAT16, FAT32, different file sizes, reformats, etc. I tried using a 2GB and a 8GB microSD card with the Libelium adapter (http://www.libelium.com/tienda/catalog/product_info.php?cPath=21&products_id=66). When I take out the SD and run serial monitor it shows the same error but it takes about 15 seconds to show "Couldn't initialise card" instead of about 2 seconds with the card in.

I am able to write to the card using the SDuFat library but I am trying this one since I can't seem to figure out how to print variables, can only print txt with the SDuFAT for some reason as explained in my help post here = (http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1246090486

Could it be that the Libelium adapter doesn't work with this library? I hope someone can help, I have been reading and working on this for hours now :frowning:

I've been using the SD/MMC Mini Board from FUTURLEC
SD/MMC Mini Board
And, mainly, the code from sirmorris' devicePrintdemo.

The problem with FUTURLEC, is that it takes almost a month, after you have placed the order, to receive the parts. But thje price of the SD/MMC Mini Board is only $6.90. (I live in the USA). It is preassembled and easy to use.

I use a Kingston 1GB SD card to store data, which can be bought at any computer store. probably even at Wal-Mart.

I use an arduino compatable RBBB (really bare bones board), with an arduinoized atmega168, and a USB conversion board. (for programming via USB)

I'm sorry, I can't help more with your problem; I don't know what board or microcontroller you are using. (Under TOOLS > BOARD, have you checked the proper board?) Proper serial port? (getting on the proper port can be a little confusing)

After the SD card is formatted, you need to load the card up with a bunch of 'stuff', data of any kind, for instance just a bunch of (cccccccccc)'s, then put that 'stuff' in a file, on the card, and name the file, BUT when you name the file, just name it 'data', leave off the '.txt', as that will be put on automatically. Otherwise, if you add the'.txt', you will end up with a file named 'data.txt.txt', which won't work.

You're probably aware of all this stuff.
Pakrat

I am using the atmega 168 on windows xp. I know it is connected fine, did the standard tests. I did the txt file. I don't think the program even got far enough to checking the txt file since the error I got is checked for before checking for any txt file errors. Maybe I will try another board, has anyone got this working with the libelium board?

These are at SPARKFUN
SparkFun microSD Transflash Breakout - BOB-00544 - SparkFun Electronics
SparkFun SD/MMC Card Breakout - BOB-12941 - SparkFun Electronics

They are a bit more costly than FUTURLEC, though, but will be received in much less time.

As far as the operation of the code, you will probably need to contact sirmorris, or wait for him to reply. Or one of the other more knowledgeable members. ::slight_smile:

We don't know which board you are using, there are several choices under: ARDUINO-0014 > TOOLS > BOARD > Diecimila/Duemilanove w/atmega168, Arduino NG or older w/atmega168, etc, etc.

Pakrat

does anyone know how can i connect an sd with an arduino mega?
with the 2009 i can but with the mega dont compile

thanks to all

and excuse my english

I saw the sparkfun ones, they are just breakout boards, is that all I need? No resisters, capacitors, etc between the SD and the pins on my Arduino? If so can't I just solder some wires directly to the correct SD pins and wire to the correct Arduino pins or do I need some components in between?

I am using the Duemilanove w/atmega328

Posted by: jackie Posted on: Today at 06:30:17
I saw the sparkfun ones, they are just breakout boards, is that all I need? No resisters, capacitors, etc between the SD and the pins on my Arduino? If so can't I just solder some wires directly to the correct SD pins and wire to the correct Arduino pins or do I need some components in between?

I am using the Duemilanove w/atmega328

As far as I know, if your Duemilanove w/atmega328 operates at 5 volts you still need to connect the breakout boards according to the diagram on the first page of this thread:
http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1235125412/0

Breakout board is a name Sparkfun gives a lot of their accessory boards. These particular boards contain the microSD Socket for Transflash:
http://www.sparkfun.com/commerce/product_info.php?products_id=127

or the SD/MMC Socket for Secure Digital Disk or Multi Media Cards

Those sockets are sold seperately, BUT would require some very delicate soldering to connect them to a pre made board. The "breakiout boards" already have them soldered to a board, but cost much more.

pakrat

If I buy the one you mentioned earlier, SD/MMC Mini Board , do I still have to follow the structure on page 1 of this thread or are all the resisters and such on the circuit already doing the job?

Posted by: jackie Posted on: Yesterday at 20:53:02
If I buy the one you mentioned earlier, SD/MMC Mini Board , do I still have to follow the structure on page 1 of this thread or are all the resisters and such on the circuit already doing the job?

Well, I did because my RBBB operates at 5 volts. Three easy to make voltage dividers to drop the arduino (RBBB) signal outputs from 5v to 3.3v, as on the first page of this thread. The MMC/SD socket operates at 3.3 volts, and doesn't have those volt dividers included. If your Duemilanove w/atmega328 operates at 3.3v, I guess you won't need the volt dividers. But the socket will need a 3.3 voltage source to feed its power line, as well as the ground source.

There will be four signal lines between arduino and SD/MMC socket__(SS, MOSI, SCK, MISO, which are Arduino pins 10, 11,13, and 12).__ If your arduino operates at 5v, outputs from 10, 11, 13 need to be dropped to 3.3 v using those voltage dividers. Pin 12 runs directly from arduino to socket.
There will be a required 3.3v power feed to the socket, whether it comes from the arduino or a seperate 3.3 v regulator, and a ground feed. Six lines in all.

I mentioned that it takes about a month to receive shipments from FUTURLEC

packrat

There seems to be a conflict between the microfat module and Arduino 0016. I had no difficulty running the dptest demo earlier, but now (yes, I've done a complete rebuild), it dies with

uFat / DevicePrint Demo
2009 arduinonut.blogspot.com

Couldn't initialise microfat: error code 1Error

This is a fairly graceful crash, it turns out. In my own code, most calls to the DevicePrint package now result in a reset of the Arduino board.

I am using a 5V 16MHz Arduino Pro, telling Arduino 0016 that it is a Duemilanove w/ AT mega328. Have others had similar experience?

Robert R. Fenichel

guys i'm using the libelium SD module with arduinoBT. Will this thread help me write/read data on my SD card? just asking in order to save time from reading the long 9 pages thread :slight_smile:

i run the deviceprint demo but all i get is

Error Couldn't initialize card

My controller is an ArduinoBT and im using the libelium microSD module.
I've managed to write data on my microSD card, with another library (FileLogger) but I also need to read data from my SD directly in a variable on Arduino for further process, which isnt possible with the FileLogger lib. i think.
Does anyone know if i can read with filelogger btw? Or should i use DevicePrint and uFat2 ? And how can I solve this error?

I dont think it is the fact that i didnt follow the structure on page 1 with the resistors, cause like i said i have already managed to write on my card with the Filelogger lib.

Is FAT32 supported? I think it is not, but the summary post at the beginning of this thread seems to suggest it might be.

I finally got it working :slight_smile: Anyone know of some exhibits or codes that I can find to grab codes? The one for deviceprintdemo seems to repeat until there is no more space. I want to basically have a datalogger that prints to the sd card when necessary (configured by ifs and etc) Did a forum search didn't pull up anything :frowning:

Sorry, I am a bloddy beginner trying to compile the libraries.
I end up with the following error:
In file included from /partition.h:15,
from fat.c:12:
/sd_raw_config.h:107:6: error: #error "no sd/mmc pin mapping available!"
fat.c: In function 'fat_append_clusters':
fat.c:509: error: 'for' loop initial declaration used outside C99 mode
fat.c: In function 'fat_interpret_dir_entry':
fat.c:1553: error: 'for' loop initial declaration used outside C99 mode
fat.c: In function 'fat_write_dir_entry':
fat.c:1850: error: 'for' loop initial declaration used outside C99 mode
fat.c:1854: error: 'for' loop initial declaration used outside C99 mode
fat.c: In function 'fat_get_fs_free_16_callback':
fat.c:2297: error: 'for' loop initial declaration used outside C99 mode
hardware\libraries\SDcard\sd_raw.o: In function `sd_raw_available':

I am using a Duemilanove with ATMega 328. And IDE V 0016.