NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » Data logging using SD card

April 06, 2010
by Ralphxyz
Ralphxyz's Avatar

Is there any code enabling a SD card for data logging?

I really do not want to dedicate a computer for data logging.



April 12, 2010
by Ralphxyz
Ralphxyz's Avatar

Does anyone use a SD card with the ATmega168?

How else is data logging being done besides dumping to a PC?


April 13, 2010
by hevans
(NerdKits Staff)

hevans's Avatar

Hi Ralph,

Writing to an SD Card can be a tricky thing. User pbfy0 did a project where he read from an SD Card. You could use that as a starting point to write data back out to the SD Card. Note that this approach involves writing and reading bytes directly to the SD Card. Which means you wont be able to just put the SD card into your computer and read a file on it, since there is no file system. You will have to write a computer side program to read and interpret the data, or write an MCU program to read the data back out and dump it over the serial port. Any way you wish to proceed it will be quite an undertaking, so take it slow and steady. But it should be fun!


April 14, 2010
by Ralphxyz
Ralphxyz's Avatar

With 2282 views this seems to be a popular thread doesn't anybody else hav antthing to say?

I see using a SD card with Arduino and PIC is a popular subject.

Writing a translation program for the PC, "should" not be that big of a deal.

Probably make the raw data into a .csv file would be the simplest thing to do.

Since I am wanting to record temperature readings using Excel or another spreadsheet

to show the readings (bar charts etc.).

Have there really been 2 thousand hits on this thread?


April 14, 2010
by Rick_S
Rick_S's Avatar

From what I understand, there are FAT libraries available for avr. One of the problems is the amount of memory required for the read/write buffers. One of the websites I had browsed through mentioned the libraries alone ate up 8k of code. Add the 2k for the bootloader in your nerdkit 168 and you only have about 6k of remaining program space to do everything else.

If I recall correctly the write packets are 512 bytes in size. This alone would fill 1/2 the available ram on a 168.

This would be a challenge with an ATMEGA168. Now the 328 might be a bit more do-able. I know I've seen projects such as THIS where an ATMEGA32 was used writing to a 1Gb SD card in FAT format.

It can be done, but like Humberto said, it will be quite an undertaking.


April 22, 2010
by brockmjp
brockmjp's Avatar

I'm not surprised there are so many hits on this thread. I'll bet anyone who ever made the temp sensor project had the same thought "Now how do I make this into a data logger? No problem, I'll just write to an SD card. Surely someone has figured out how to do that...". I'm not quite ready to tackle this myself, but HERE is a project using an ATmega8 writing data in raw format and FAT32. Lots of photos, schematics and code provided and hundreds of comment posts where people are modifying the code for other platforms.

You don't necessarily have to loose 2k to the bootloader. You can program the chip directly with an in-system programmer (ISP) instead.

Good luck and if you have any success, please share! ;-)


May 03, 2010
by JohnBonnechappe
JohnBonnechappe's Avatar

Hi Ralph,

Just to let you know, this is a project that I will be seriously tackling "before too long". I will be just logging data straight to the card on an hourly basis, then transferring to a PC via a serial transfer. A program on the PC will write the data to a csv file for loading into excel.

I'll post here when I make some progress.

Cheers! JohnB

May 03, 2010
by Ralphxyz
Ralphxyz's Avatar

Hi John, thanks. This really seems so logical, to have have data logging. Your outline is approximately what I was thinking of.

I would not think that having the data in FAT format would be critical as the data would be viewable on a PC and with a custom program to build a .csv from the RAW data the .csv would be viewable in Excel.

Using RAW data one could probable still use the ATmega168 for this.

I also have a ATmega328p so memory space should certainly not be a problem.

I am learning C programming so I probable would not be much help but I could certainly test, if you or anyone else would need independent testing.

In my limited knowledge I really can not see that this would be that big of a project, considering the Arduino projects that are published on the web that could be used for reference. It seems it "should" be a pretty straight forward project, but then again what do I know.

Please keep me posted.


August 09, 2010
by Ralphxyz
Ralphxyz's Avatar

Is anybody familiar with this data logger or with OpenLog?



It uses a ATmega328 MCU so I wonder if some Nerdkit projects might be added.


Post a Reply

Please log in to post a reply.

Did you know that a thermometer can be made "faster" by using a bit of math? Learn more...