Go Down

Topic: write to csv file? (Read 7120 times) previous topic - next topic

hambba


how to write the value of RTC and DHT into a CSV file.?
csv files I named "logger.csv"


Code: [Select]
//SD
#include <SD.h>
const int chipSelect = 10;
File file;

//RTC
#include <Wire.h>
#include <RTClib.h>
RTC_DS1307 rtc;

//LCD
#include <LiquidCrystal.h>
LiquidCrystal lcd(7,6,5,4,3,2); 

//DHT11
#include <dht.h>
#define sendht A1 
dht dht;

void setup()
{ lcd.begin(20,4);
  Serial.begin(9600);
  //SD
  Serial.print("Initializing SD card...");
  lcd.print("Initializing SD card...");
  delay(500);
  lcd.clear();
  pinMode(10, OUTPUT); // required for SD lib
  digitalWrite(10,HIGH);
  if (!SD.begin(chipSelect)) {
    Serial.println("Card failed, or not present");
    lcd.print("Card Failed or");
    lcd.setCursor(0,1);
    lcd.print("Not present");
    // don't do anything more:
    delay(500);
    return;
  }
  Serial.println("card initialized.");
  lcd.print("Card Initialized.");
  delay(500);
  lcd.clear();
  //RTC
 Wire.begin();
 rtc.begin();
 if (! rtc.isrunning()) {
    lcd.clear();
    lcd.print("RTC NOT Running");
    //Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
    // rtc.adjust(DateTime(__DATE__, __TIME__));  //useed when only to set date and time in firt setting of RTC
    }
  // rtc.adjust(DateTime(__DATE__, __TIME__)); use it when you need to correct the time   
}
void loop()
{
    //DHT
    dht.read11(sendht);
    Serial.print("Current humidity = ");
    Serial.print(dht.humidity);
    Serial.print("%  ");
    Serial.print("temperature = ");
    Serial.print(dht.temperature);
    Serial.println("C  ");
   
    //RTC
    DateTime now = rtc.now();
    Serial.print(now.year(), DEC);
    Serial.print('/');
    Serial.print(now.month(), DEC);
    Serial.print('/');
    Serial.print(now.day(), DEC);
    Serial.print(' ');
    Serial.print(now.hour(), DEC);
    Serial.print(':');
    Serial.print(now.minute(), DEC);
    Serial.print(':');
    Serial.print(now.second(), DEC);
    Serial.println();
}

PaulS

Code: [Select]
dht dht;
You should NEVER create an instance of a class with the same name as the class.

Quote
how to write the value of RTC and DHT into a CSV file.?
The RTC is hardware. The library that you use to read it can return several values. Which ones do you want to write to the file? In what order? With what between them?

The same applies to the DHT.

hambba

Code: [Select]
dht dht;
You should NEVER create an instance of a class with the same name as the class.
The RTC is hardware. The library that you use to read it can return several values. Which ones do you want to write to the file? In what order? With what between them?

The same applies to the DHT.
thank you for your attention,

I want to create a data logger that will be I made a means of learning.

if you can give me a few examples to write two values ​​into csv file and how to separate the different values ​​in the column


"dht dht; Is naming From My library"

PaulS

Quote
"dht dht; Is naming From My library"
It's still wrong.

Quote
if you can give me a few examples to write two values ​​into csv file and how to separate the different values ​​in the column
Code: [Select]
   File csvFile = SD.open("theData.csv");
   if(csvFile)
   {
      csvFile.print("thisIsInColumnOneRowOne");
      csvFIle.print(",");
      csvFile.println("thisIsInColumnTwoRowOne");

      csvFile.print("thisIsInColumnOneRowTwo");
      csvFIle.print(",");
      csvFile.println("thisIsInColumnTwoRowTwo");

      csvFile.close();
   }

SukkoPera

I attempted to write a library for CSV file creation for my MyTrack project.

The library works, but I'm not really satisfied with its interface, this is why it is embedded in the project and not packaged separately. The interface is so ugly that the more you're going to use it, the more you will be thinking that you don't really need a library for writing CSV files ;).

Anyway it might still be of some use to you, so maybe you can check it out. You only need to copy the CSVWriter.cpp and .h files into your project. Then have a look here for how to define the column names and here for how to actually write a line of data.
"Code is read much more often than it is written, so plan accordingly. Design for readability."

Guida rapida a ESP8266: https://goo.gl/kzh62E

Go Up