Download - ARDUINO SD-MMC SHIELD
w w w . e k t 2 . c o mw w w . e k t 2 . c o m
ARDUINO SD-MMC SHIELD
Arduino Sample Code:It is easy to read from and write to SD cards on the Arduino, Firstly, you should select the on- board want to use. Secondly, when you use the arduino's own SD library, you should SD cards example as below: /*
SD card data logger
This example shows how to log data from three analog sensors
To an SD card using the SD library.
The circuit:
* Analog sensors on analog ins 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
This example code is in the public domain.
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
Cost int chip Select = 10; //you should change to pin 10
Void setup ()
{
Serial. Begin (9600);
Serial. Print ("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
Pin Mode (10, OUTPUT);
switch to the socket youchange the CS pin to 10.The changed writing to
// see if the card is present and can be initialized:
If (! SD.begin (chip Select)) {
Serial.println ("Card failed, or not present");
// don't do anything more:
Return;
}
Serial.println ("card initialized.");
}
Void loop ()
{
// make a string for assembling the data to log:
String data String = "";
// read three sensors and append to the string:
For (int analog Pin = 0; analog Pin < 3; analog Pin++) {
w w w . e k t 2 . c o mw w w . e k t 2 . c o m
Int sensor = analog Read (analog Pin);
Data String += String (sensor);
If (analog Pin < 2) {
Data String += ",";
// open the file. Note that only one file can be open at a time,
// so you have to close this one before opening another.
File data File = SD.open ("bobo.txt", FILE_WRITE);
// if the file is available, write to it:
If (data File) {
dataFile.println (data String);
dataFile.close ();
// print to the serial port too:
Serial.println (data String);
}
// if the file isn't open, pop up an error:
Else {
Serial.println ("error opening datalog.txt");
The changed reading from SD cards example as below:
SD card data logger
This example shows how to log data from three analog sensors
To an SD card using the SD library.
The circuit:
* Analog sensors on analog INS 0, 1, and 2
* SD card attached to SPI bus as follows:
** MOSI - pin 11
** MISO - pin 12
** CLK - pin 13
** CS - pin 10
This example code is in the public domain.
#include <SD.h>
// On the Ethernet Shield, CS is pin 4. Note that even if it's not
// used as the CS pin, the hardware CS pin (10 on most Arduino boards,
// 53 on the Mega) must be left as an output or the SD library
// functions will not work.
Cost int chip Select = 10;//you should change to pin 10
Void setup ()
{
Serial. Begin (9600);
Serial. Print ("Initializing SD card...");
// make sure that the default chip select pin is set to
// output, even if you don't use it:
Pin Mode (10, OUTPUT);
// see if the card is present and can be initialized:
If (! SD. Begin (chip Select)) {
Serial. Printing ("Card failed, or not present");
// don't do anything more:
Return;
}
Serial.println ("card initialized.");
File data File = SD.open ("bobo.txt"); //open the file. Note that only one
file can be open at a time,
If (data File) {
While (data File. available ()) {//if the file is available, read it:
Serial. Write (data File. read()); //If the data is available, sent
it to the serial interface
}
Data File. Close (); //close data File }
Else {
Serial .printing ("error opening datalog.txt");
Void loop ()