Jan 15, 2012

Arduino and Micro-SD logging

Getting started with Adafruit's Micro-SD Breakout Board in 2 minutes.

Wiring
Wiring the Breakout board is very simple.
  • Connect the 5v pin to the 5V pin on the Arduino
  • Connect the GND pin to one of the three GND pin on the Arduino
  • Connect CLK to pin 13
  • Connect DO to pin 12
  • Connect DI to pin 11
  • Connect CS to pin 10


Picture shamelessly taken from its home at adafruit.com

Programming
To use the Micro-SD you need to include the SD.h library at the top of your program.  Then add the following line of code to your setup() function:

SD.begin(10);

Now you can write something on the card:

File logFile = SD.open("log.txt",FILE_WRITE);

if(logFile){
   logFile.println(“Hello World!”);
   logFile.close();
}

Finally, while humming the MissionImpossible theme, you can power off the Arduino board, take the Micro-SD card out, put the micro-SD card in an SD card adaptor, put the SD card adaptor in your laptop and look at your new file.

Muha ha ha ha ha.

Note: I used this in my last arduino/bluetooth project.   

3 comments: