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();
}