/************************************************************************
*
* Test of the Pmod
*
*************************************************************************
* Description: Pmod_SD
* The voltages applied to inputs A0 and A1 are stored in a file
* on the SD card.
*
* Material
* 1. Arduino Uno
* 2. Pmod SD
* 3. Adafruit module TXB0108
*
************************************************************************/
#define CS 10 // Assignment of the CS pin
#include <SPI.h> // Call of libraries
#include <SD.h>
int tension;
void setup()
{
Serial.begin(9600); // initialization of serial communication
Serial.println("Initialisation carte SD");
pinMode(CS, OUTPUT);
// Initialisation carte SD
if (!SD.begin(CS))
{
Serial.println(" * Carte absente");
Serial.println(" * Erreur de cablage");
return;
}
Serial.println("Carte initialisee.");
delay(2000);
}
void loop()
{
String donnee = ""; // String for storing values to be stored
for (int i = 0; i < 2; i++) // conversion of voltage and addition to string
{
tension = analogRead(i);
donnee+= String(tension);
if (i < 1)
{
donnee += ","; // add comma between 2 data
}
}
File fichier = SD.open("datalog.txt", FILE_WRITE); // open file datalog.txt
if (fichier) // if the file is available
{
fichier.println(donnee); // write data in file
fichier.close();
Serial.println(donnee); // send data in serial monitor
}
else // if the file does not exist, display an error
{
Serial.println("Erreur d'ouverture fichier");
}
delay(1000); // wait 1 sec between metering and recording
}
Comments