Hi, I am trying to convert a double value obtained from the library of Emon which i have running at home. https://github.com/openenergymonitor/MainsACv3/blob/master/EmonLib/Emon.cpp
the code i am using is this, using the tutorial of sciguy on youtube which works perfectly (when not using doubles)
As you can see below I need to save a line with unixtime stamp obtained from an RTC clock, then with comma separated also have apparentPower, realPower, powerfactor, Vrms, Irms... which are all doubles
So it will end up something like this...
//unixtime;apparentpower;realpower;Voltage;Current;powerfactor
1315255517;2371.16;2012.23;230;8.21;0.95
The code below WORKS, but as soon as I add any extra info on the String dataString, then the line gets corrupted and arduino restarts.
So I guess the conversion from double to string is not working correctly.
Please help me out, I really appreciate.
void saveSD(){
// Get time information in "now" to use later
DateTime now = RTC.now();
//************ convert double to String ***************
char charapparentPower[16];
dtostrf( emon.apparentPower, 4, 2, charapparentPower );
//***************************
// Create the String that will be output to Serial port and saved to SD card.
String dataString = String(now.unixtime()) + ";" + String(charapparentPower); //230;0.95;1;45";
//Open a file to write to
//Only one file can be open at a time
File dataFile = SD.open("loga.txt", FILE_WRITE);
if(dataFile)
{
dataFile.println(dataString);
dataFile.close();
Serial.println(dataString);
}
else
{
Serial.println("Couln't access file");
}
}
btw, I forgot to mention I am using the official ethernet shield for the SD. But as I said its working perfectly when only a string such as the one below is used
// String dataString = " Hello ethernet";
so basically, this is the aim of the question
//************ convert double to String ***************
char charapparentPower[16];
dtostrf( emon.apparentPower, 4, 2, charapparentPower );
//***************************
// Create the String that will be output to Serial port and saved to SD card.
String dataString = String(now.unixtime()) + ";" + String(charapparentPower); //230;0.95;1;45";