Hi,
I am using this code to output data to an Excel (.CSV) file.
when I view it the concurrent output is not in each cell, instead it is in one cell, seperated with commas.
I also tried printing the data without the string, didn't turn out quite well for me.
Help please.
#include <SD.h>
#include <DHT.h>
#include <SPI.h>
#include <stdlib.h>
//sensor settings
#define DHTPIN 2
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
int id=1;
const int chipSelect = 4;
void setup() {
// Open serial communications and wait for port to open:
Serial.begin(9600);
//mitruma sensor
dht.begin();
//kustības sensors
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
//SD card;
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 logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(", ,");
String header="ID,T,H%";
logFile.println(header);
logFile.close();
Serial.println(header);
}
else
{
Serial.println("Couldn't read");
}
}
void loop() {
char tempT[10];
char rhPct[10];
dtostrf(dht.readTemperature(), 4, 1, tempT);
dtostrf(dht.readHumidity(), 4, 1, rhPct);
//saves data to SD card Log file
String dataString = String(id) + "," + String(tempT) + "," +String(rhPct);
File logFile = SD.open("LOG.csv", FILE_WRITE);
if (logFile)
{
logFile.println(dataString);
logFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couldn't open log file");
}
id++;
delay(3000);
}