Frage zum SD Datenlogger

Hallo,

ich habe an einem Uno einen BME280, einen TMP117 und ein RTC Modul mit Datenlogger (SD).

Die Sensoren, das RTC Modul und die Serielle Ausgabe funktioniert. Die Initialisierung der SD Karte auch.

Ich verstehe jetzt aber nicht, wie ich meinen Datensatz bestehend aus Timestamp + t + h+ p zusammensetze um ihn dann alle 30 Sekunden auf die SD Karte zu schreiben.

Hier mal mein Code:

#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include "BlueDot_BME280.h"
#include "TMP117.h"
#include "RTClib.h"
BlueDot_BME280 bme280 = BlueDot_BME280();
TMP117 tmp(0x49);
RTC_DS1307 rtc;

const int chipSelect = 10; //10 is default by shield, but normally on Pin 4
int interval = 5;  //Log to SD Card every 5 seconds

long timer;
String timestring;

void setup() {
  Wire.begin();
  Serial.begin(9600);
  delay(3000);
  rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
  Serial.println("Initializing SD card...");
  if (!SD.begin(chipSelect)) {
    Serial.println("SD Card error");
    return;
  }
  Serial.println("card initialized");
  if (! rtc.begin()) {
    Serial.println("No RTC found");
  } else {
    Serial.println("RTC clock found");
  }
  if (! rtc.isrunning()) {
    Serial.println("RTC is not configured");
  }

  bme280.parameter.I2CAddress = 0x76;
  bme280.parameter.IIRfilter = 0b100;                    //Setup for IIR Filter
  bme280.parameter.humidOversampling = 0b101;            //Setup Humidity Oversampling
  bme280.parameter.tempOversampling = 0b000;             //Setup Temperature Ovesampling
  bme280.parameter.pressOversampling = 0b101;            //Setup Pressure Oversampling

  if (bme280.init() != 0x60)
  {
    Serial.println(F("Ops! BME280 could not be found!"));
    while (1);
  }

  else
  {
    Serial.println(F("BME280 detected!"));
  }
  Serial.println();
  Serial.println();
}

void loop() {

  delay(2000);

  float h = bme280.readHumidity();
  float t = tmp.getTemperature();
  float p = bme280.readPressure() + 377.79;

  DateTime now = rtc.now();
  timestring = now.day();
  timestring += "-";
  timestring += now.month();
  timestring += "-";
  timestring += now.year();
  timestring += " ";
  timestring += now.hour();
  timestring += ":";
  timestring += now.minute();
  timestring += ":";
  timestring += now.second();

  Serial.print ("Timestamp   : ");
  Serial.print(timestring);
  Serial.println();

  Serial.print ("Temperature : ");
  Serial.print (t);
  Serial.println (" °C");

  Serial.print ("Humidity    : ");
  Serial.print (h);
  Serial.println ("  %");

  Serial.print ("Pressure    : ");
  Serial.print (p);
  Serial.println (" hPa");

  Serial.println();
  Serial.println();

}

Hallo
werf mal einen Blick in dieses Tutorial.

Hallo,
sehr viele interessante Informationen zum Loggen auf einer SD-Card findest du auch hier.

Danke für die beiden guten Infos.
Ich hab aber noch 2-3 Fragen:

"myFile = SD.open("test.txt", FILE_WRITE);" --> Wofür steht hier das FILE_WRITE?
Mit "myFile.println("(timestring)");" würde ich dann den Zeitstempel in die Datei schreiben.

Jetzt würde ich aber gerne noch die float Variablen t, h und p jeweils durch ein "," in die gleiche Zeile schreiben.

Am Ende soll die Zeile in der Datei folgendermaßen aussehen:

timestring, t , h , p

Würde das eventuell so funktionieren?
"myFile.println("(timestring) , (t) , (h) , (p)");"

Gruß,
Michael

Hast du dir die Beschreibung in meinem Link mal durchgelesen ?
Da steht alles drin:

In setup(), create a new file with SD.open() named "test.txt". FILE_WRITE enables read and write access to the file, starting at the end. If a file "test.txt" was already on the card, that file would be opened.

Hallo
probier mal das so aus:
myFile.print(timestring);
myFile.print(" , ");
myFile.print(t);
myFile.print(" , ");
myFile.print(h);
myFile.print(" , ");
myFile.println(p);

So kommt eine, für ein Tabellenberechungsprogramm, kompatible Datei bei raus.

Ich würde statt des Kommas immer ein Semikolon als Trennzeichen verwenden um auf der sicheren Seite zu sein.
Das Komma ist im Deutsch lokalisierten Windows/Excel das Dezimaltrennzeichen.

paulpaulson:
Hallo
probier mal das so aus:
myFile.print(timestring);
myFile.print(" , ");
myFile.print(t);
myFile.print(" , ");
myFile.print(h);
myFile.print(" , ");
myFile.println(p);

So kommt eine, für ein Tabellenberechungsprogramm, kompatible Datei bei raus.

Super, genau so hab ich es gemacht und es funktioniert.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.