CSV Logging File Column Headers
hi there,
i using sketch record , log temperature of 1 sensor attached uno adafruit logger shield.
when open data in excel has 2 nice columns; first filled date , time, second filled temperature readings. add sketch column heading @ top of each column when open csv file in excel???
thanks
i using sketch record , log temperature of 1 sensor attached uno adafruit logger shield.
code: [select]
#include <sd.h>
#include <wire.h>
#include "rtclib.h"
#define echo_to_serial 1
rtc_ds1307 rtc;
void setup() {
serial.begin(57600);
wire.begin();
rtc.begin();
if (!rtc.isrunning()) {
serial.println("rtc not running!");
}
pinmode(10, output);
sd.begin(4);
}
file myfile;
float value;
float time;
void loop() {
myfile = sd.open("test.csv", file_write);
datetime = rtc.now();
if (myfile) {
value = analogread(0) * 5 / 1024.0;
value = value - 0.5;
value = value / 0.01;
myfile.print(now.day(), dec);
myfile.print('/');
myfile.print(now.month(), dec);
myfile.print('/');
myfile.print(now.year(), dec);
myfile.print(' ');
myfile.print(now.hour(), dec);
myfile.print(':');
myfile.print(now.minute(), dec);
myfile.print(':');
myfile.print(now.second(), dec);
myfile.print(",");
myfile.println(value);
serial.print(now.day(), dec);
serial.print('/');
serial.print(now.month(), dec);
serial.print('/');
serial.print(now.year(), dec);
serial.print(' ');
serial.print(now.hour(), dec);
serial.print(':');
serial.print(now.minute(), dec);
serial.print(':');
serial.print(now.second(), dec);
serial.print(" - ");
serial.println(value);
}
myfile.close();
delay(1000);
}
when open data in excel has 2 nice columns; first filled date , time, second filled temperature readings. add sketch column heading @ top of each column when open csv file in excel???
thanks
hi there,simple,
i using sketch record , log temperature of 1 sensor attached uno adafruit logger shield.code: [select]#include <sd.h>
#include <wire.h>
#include "rtclib.h"
#define echo_to_serial 1
rtc_ds1307 rtc;
void setup() {
serial.begin(57600);
wire.begin();
rtc.begin();
if (!rtc.isrunning()) {
serial.println("rtc not running!");
}
pinmode(10, output);
sd.begin(4);
}
file myfile;
float value;
float time;
void loop() {
myfile = sd.open("test.csv", file_write);
datetime = rtc.now();
if (myfile) {
value = analogread(0) * 5 / 1024.0;
value = value - 0.5;
value = value / 0.01;
myfile.print(now.day(), dec);
myfile.print('/');
myfile.print(now.month(), dec);
myfile.print('/');
myfile.print(now.year(), dec);
myfile.print(' ');
myfile.print(now.hour(), dec);
myfile.print(':');
myfile.print(now.minute(), dec);
myfile.print(':');
myfile.print(now.second(), dec);
myfile.print(",");
myfile.println(value);
serial.print(now.day(), dec);
serial.print('/');
serial.print(now.month(), dec);
serial.print('/');
serial.print(now.year(), dec);
serial.print(' ');
serial.print(now.hour(), dec);
serial.print(':');
serial.print(now.minute(), dec);
serial.print(':');
serial.print(now.second(), dec);
serial.print(" - ");
serial.println(value);
}
myfile.close();
delay(1000);
}
when open data in excel has 2 nice columns; first filled date , time, second filled temperature readings. add sketch column heading @ top of each column when open csv file in excel???
thanks
csv files assume data separated commas between columns, , records separated line feeds between records. from excel difference between header , data? (nothing) they both records of data.
just write headers first record.
myfile.println("column 1 header,column 2 header");
chuck.
p.s. remember, if want comma in header, kinda this:
sample date,time value
you need put quotes around comma'd heading. since quotes identify println() string, have escape them(i.e. \" ).
myfile.println("\"sample date, time\",value");
Arduino Forum > Using Arduino > Storage > CSV Logging File Column Headers
arduino
Comments
Post a Comment