Could someone help us with weather station

Our student project needs some help. We have a code for our weather station with DHT22, MPL3115A2, SD data logger and DS18B20.

Monitor shows that “SD-card reader is ready for use” and “file is opened and header is created” but thats all. And when we check the SD-card, that shows only these things with two errors:

/Volumes/VMSPOT_ESXI/MEETFILE: line 1: syntax error near unexpected token ArduinoS,humidity' /Volumes/VMSPOT_ESXI/MEETFILE: line 1: time (ms) ArduinoS,humidity (%),temperat’reDHT(°C)
logout
Saving session…
…copying shared history…
…saving history…truncating history files…
…completed.

If someone can help us, we appreciate that very very much!

Code below:

//Load lib for DHT
#include “DHT.h”
#define DHTPIN 5 //connect DHT dat-pin to pin 5, Vcc to 5V,GND to GND
#define DHTTYPE DHT22 // DHT 22
DHT dht(DHTPIN, DHTTYPE); //creat the object named “dht” from the class DHT

//Load lib for MPL3115A2
#include <Wire.h>
#include <Adafruit_MPL3115A2.h>
// Power by connecting Vin to 5V, GND to GND
// Uses I2C - connect SCL to pin A5, SDA to SDA pin A4
Adafruit_MPL3115A2 baro; //create Object with Adafruit_MPL3115A2 lib. The name of the object is baro

//load lib vor SD cardreader
#include <SD.h>
#include <SPI.h> //MOSI on pin 11; MISO on pin 12; clock on pin 13
int pinCS = 4 ; // CS for SD-cardreader (SPI)
File myFile; //create File-object with SD library. The name of the object is myfile

//Load lib for DS18B20
#include <OneWire.h>
#include <DallasTemperature.h>
#define ONE_WIRE_BUS 2 // connect DS18B20 on pin 2
OneWire oneWire(ONE_WIRE_BUS); //create oneWire object for DS18B20
DallasTemperature sensors(&oneWire); //Create object with DallasTemperature library. The name of the object is sensors

void setup()
{
Serial.begin(9600);

// Setup SD-cardreader
if (SD.begin(4)) // Set CS into pin 10 LOW (=active). Begin method returns 1 is everything is Ok.
{
Serial.println(F(“SD-card reader is ready for use.”));
} else
{
Serial.println(F(“SD-card reader is NOT ready for use!!!”));
return;
}
//measureFile will be opened and the header will be created
myFile = SD.open(F(“meetFile”), FILE_WRITE);
if (myFile)
{
Serial.println(F(“file is opened and header is created”));
myFile.print(F(“time (ms) Arduino”));
myFile.print(F(","));
myFile.print(F(“humidity (%)”));
myFile.print(F(","));
myFile.println(F(“temperatureDHT(°C)”));
myFile.print(F(","));
myFile.println(F(“temperatureDS18(°C)”));
myFile.print(F(","));
myFile.println(F(“Pressure¶”));
myFile.print(F(","));
myFile.println(F(“time”));

//Here you can add other measurements
myFile.close();
}
else {
Serial.println(“No measurements”);
}

//Setup DHT
dht.begin();

//Setup baro
baro.begin();

}

void loop()
{
voerMetingUit();

}

int timeBetweenMeasurements = 10;
int measureTime = 5; //mesureTime in minutes
float humidity;
float temperatureDHT;
float temperatureDS18;
float pressure;
int Hour = 0;
int Minute = 0;
int Second = 0;

double startMeting = millis();
double startMeetinterval = millis();

void voerMetingUit()
{
startMeting = millis();
startMeetinterval = millis();
while ((millis() - startMeting) < measureTime * 6000)
{
if ((millis() - startMeetinterval) > timeBetweenMeasurements * 1000)
{

humidity = dht.readHumidity();
temperatureDHT = dht.readTemperature();
pressure = baro.getPressure();
temperatureDS18 = sensors.getTempCByIndex(0);
startMeetinterval = millis();
//Enter other measurements if necessary
//Datafile openen het buffer overzetten op de SD-kaart.
myFile = SD.open(F(“meetFile”), FILE_WRITE);
if (myFile)
{
Serial.println(F(“file is opened and measurements are added”));
myFile.print(millis() - startMeting);
myFile.print(",");
myFile.print(humidity);
myFile.print(",");
myFile.print(temperatureDHT);
myFile.print(",");
myFile.print(temperatureDS18);
myFile.print(",");
myFile.print(pressure);
myFile.print(",");
myFile.println(Hour);
myFile.print(":");
myFile.print(Minute);
myFile.print(":");
myFile.println(Second);
//add more measurements
myFile.close(); // close the file

}

//Also send results to the serial monitor for verification:
Serial.print(millis()- startMeting);
Serial.print(F(","));
Serial.print(humidity);
Serial.print(F(","));
Serial.print(temperatureDHT);
Serial.print(F(","));
Serial.print(temperatureDS18);
Serial.print(F(","));
Serial.print(pressure);
Serial.print(F(","));
Serial.print(F(","));
Serial.print(Hour);
Serial.print(F(":"));
Serial.print(Minute);
Serial.print(F(":"));
Serial.println(Second);
}
}
Serial.println(“een meetreeks werd afgewerkt”);
}

It looks like whatever is trying to parse your .csv file is complaining about the file header. Try putting quotes around each string:

//measureFile will be opened and the header will be created
  myFile = SD.open(F("meetFile"), FILE_WRITE);
  if (myFile)
  {
    Serial.println(F("file is opened and header is created"));
    myFile.print(F("\"time (ms) Arduino\""));
    myFile.print(F(","));
    myFile.print(F("\"humidity (%)\""));
    myFile.print(F(","));
    myFile.println(F("\"temperatureDHT(°C)\""));
    myFile.print(F(","));
    myFile.println(F("\"temperatureDS18(°C)\""));
    myFile.print(F(","));
    myFile.println(F("\"Pressure(PA)\""));
    myFile.print(F(","));
    myFile.println(F("\"time\""));

    //Here you can add other measurements
    myFile.close();
  }
  else
  {
    Serial.println("No measurements");
  }

Thank you very much!:slight_smile: