javiergonzalezb
Published © CC BY

Example How to Get Data from ADC and Save in SD Card

I used this example for save ECG signals in SD card. It was the adaptation of the SD card example from Arduino IDE.

BeginnerProtip91
Example How to Get Data from ADC and Save in SD Card

Things used in this project

Hardware components

Arduino Due
Arduino Due
×1

Software apps and online services

Processing
The Processing Foundation Processing

Hand tools and fabrication machines

Amazon Web Services SDCard shield

Story

Read more

Custom parts and enclosures

Arduino due and SDcard

This image is from: https://hackaday.io/project/19560-arduino-due-cpm-personal-computer

ECG SHIEDL olimex

This is the ECG shield From Olimex used as analog amplifier.

Schematics

SD card connection

Experiment Setup

This image shows the ecg simulator and Arduino connected to ECG shield. This experiment setup was used for to simulate the ECG signal acquisition and signal storage in SD card.

Code

Code for save data in SDcard

C/C++
This code is for to save data from ADC in SDcard
/*
  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 4

 created  24 Nov 2010
 modified 9 Apr 2012
 by Tom Igoe

 This example code is in the public domain.

 */

#include <SPI.h>
#include <SD.h>

const int chipSelect = 4;

void setup() {
  // Open serial communications and wait for port to open:
  Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  // 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("electro2.txt", FILE_WRITE);


for (int i = 0; i < 2000; i++)

  {

String dataString = "";
  
//dataString += String(i);
//dataString += ",";
  int sensor = analogRead(0);
  dataString += String(sensor);

 dataFile.println(dataString);

 /*
  if (dataFile) {
    dataFile.println(dataString);
    dataFile.close();
    // print to the serial port too:
    //Serial.println(dataString);
  }*/
  

delay(1);
}
 dataFile.close();


Serial.println("Archivo cerrado");

}



void loop() {
 
}

Credits

javiergonzalezb

javiergonzalezb

3 projects • 0 followers

Comments

Add projectSign up / Login