Logger Shield

From GOF_Wiki
Jump to: navigation, search

Contents

Introduction

Logger Shield will be very heplful when running out of memory space in your Arduino project. The Logger Shield adds mass-storage to your Arduino. The shield supports standard SD card and TF card, but you can only use one card at a time, there is a on-board switch for you to select the socket you want to use. The communication between the Arduino and memory card is achieved over SPI interface(digital 10-13), while the CS pin is Digital Pin 10. If you use SD library of Arduino IDE, make sure to change the code to reflect the location of the CS pin.

DO NOT install memory card into the socket while wired, the Logger Shield does not support hot plug.

Module: M2012042201


SD TF.jpg

Features

Specifications

Item Min Typical Max Unit
Voltage 2.7 3.3 3.6 V
Current 0.159 40 200 mA
Supported Card Type SD card(<=2G); Micro SD card(<=2G); SDHC card(<=16G) /
Dimension 53.50x47.30x19.00 mm
Net Weight 12 g

Hardware Diagram

SD HWD.jpg

Getting Started

Preparation

You have to have an SD card or micro SD card, and then format the SD card as FAT16 or FAT32 if it is necessary. Format the SD card as the screenshots below(win7):

FormatSD.jpg

Reading from and writing to SD cards on the Arduino

SD.jpg

It is easy to read from and write to SD cards on the Arduino,Firstly,you should select the on-board switch to the socket you want to use.Secondly,when you use the arduino's own SD library ,you should change the CS pin to 10.The changed writing to SD cards example as below:

/*
  SD card datalogger
 
 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
 
 created  24 Nov 2010
 updated 2 Dec 2010
 by Tom Igoe
 
 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.
const int chipSelect = 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:
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    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 dataString = "";
 
  // read three sensors and append to the string:
  for (int analogPin = 0; analogPin < 3; analogPin++) {
    int sensor = analogRead(analogPin);
    dataString += String(sensor);
    if (analogPin < 2) {
      dataString += ","; 
    }
  }
 
  // 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 dataFile = SD.open("bobo.txt", FILE_WRITE);
 
  // if the file is available, write to it:
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    Serial.println(dataString);
  }  
  // 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 datalogger
 
 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
 
 created  24 Nov 2010
 updated 2 Dec 2010
 by Tom Igoe
 
 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.
const int chipSelect = 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:
  pinMode(10, OUTPUT);
 
  // see if the card is present and can be initialized:
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    // don't do anything more:
    return;
  }
  Serial.println("card initialized.");
 File dataFile = SD.open("bobo.txt");  //open the file. note that only one file can be open at a time,
  if (dataFile) {
    while (dataFile.available()) {  //if the file is available, read it:
 
       Serial.write(dataFile.read());  //If the data is available, sent it to the serial interface
    }
    dataFile.close();  //close dataFile
  }  
  else {
    Serial.println("error opening datalog.txt");  
  } 
 
}
 
void loop()
{
 
}

Writing to SD cards on the Arduino Ethernet Shield

Schematics

Schematic of Logger Shield

Resources

How to buy

Logger Shield can be ordered through the GOF store. Its product page is located here

See Also

Licensing

This documentation is licensed under the Creative Commons Attribution-ShareAlike License 3.0 Source code and libraries are licensed under GPL/LGPL, see source code files for details.

Personal tools
Variants
Actions
Navigation
Support
Toolbox