Dr4g0n3:
#include <SD.h>
int cs_pin = 10;
int pow_pin = 8;
float refresh_rate = 0.0;
int val = analogRead(A0);
long id = 1;
void setup() {
Serial.begin(9600);
Serial.println("Initializing Card");
pinMode(CS_pin, OUTPUT);
pinMode(pow_pin, OUTPUT);
digitalWrite(pow_pin, HIGH);
if(!SD.begin(CS_pin))
{
Serial.println("Card Failed!");
return;
}
Serial.println("Card Ready.")
File dataFile = SD.open("Voltage & Current", FILE_WRITE);
if(dataFile)
{
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couldn't create datalog");
}
File commandFile = SD.open("COMMANDS.txt");
if (commandFile)
{
Serial.println("Reading Command File")
float decade = pow(10, (cammandFile.available() - 1));
while(commandFile.available())
{
float temp = cammandFile.read() - '0');
refresh_rate = temp*decade+refresh_rate;
decade = decade/10;
}
Serial.print("Refresh Rate = ");
Serial.print(refresh_rate);
Serial.prinln("ms");
}
else
{
Serial.println("Couldn't read command file.");
return;
}
File logFile = SD.open("Voltage & Current.csv", FILE_WRITE);
if (logFile)
{
logFile.println)", ,");
String header = "Voltage, Current";
logFile.println(header);
logFile.close();
Serial.println(header);
}
else
{
Serial.println("Couldn't open log file");
}
}
void loop() {
int Voltage = (val*(5/1024));
int Current = ((val*(5/1024))/15);
String dataString = String(id) + ", " + String(Voltage) + ", " + String(Current);
File dataFile = SD.open("Voltage & Current.csv", FILE_WRITE);
if(dataFile)
{
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couldn't create datalog");
}
id++;
delay (refresh_rate);
}
According to the tutorial by Jeremy Blum it should work like that :confused:
Was that in reply to #11, or #13? Anyway, you should take tutorials with a large grain of salt. It's amazing how wrong most of them are.