Last active
February 2, 2021 14:54
-
-
Save Thiemann96/6a6db6501993efd296848720e0c8e2de to your computer and use it in GitHub Desktop.
Saves on SD card every 60 seconds
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <SPI.h> | |
#include <SD.h> | |
#include "SenseBoxMCU.h" | |
#include <RV8523.h> | |
File myFile; | |
HDC1080 hdc; | |
RV8523 rtc; | |
// Sensor ID's mit eigenen austauschen | |
const char *TEMP_ID = "SENSORID"; | |
const char *HUMI_ID = "SENSORID"; | |
const long interval = 60000; // 60.000 Millisekunden = 60 Sekunden | |
long time_start = 0; | |
long time_actual = 0; | |
// Platzhalter für den Zeistempel | |
char timestamp[64]; | |
void setup() { | |
// put your setup code here, to run once: | |
SD.begin(28); | |
myFile = SD.open("data.txt", FILE_WRITE); | |
myFile.close(); | |
rtc.begin(); | |
rtc.start(); | |
rtc.batterySwitchOver(1); | |
} | |
void loop() { | |
time_start = millis(); | |
if (time_start > time_actual + interval) { | |
time_actual = millis(); | |
uint8_t sec, min, hour, day, month; | |
uint16_t year; | |
//get time from RTC | |
rtc.get(&sec, &min, &hour, &day, &month, &year); | |
sprintf(timestamp, "20%02d-%02d-%02dT%02d:%02d:%02dZ", | |
year, | |
month, | |
day, | |
hour, | |
min, | |
sec); | |
// Datei vorher öffnen | |
myFile = SD.open("data.txt", FILE_WRITE); | |
myFile.print(TEMP_ID); | |
myFile.print(","); | |
myFile.print(hdc.getTemperature()); | |
myFile.print(","); | |
myFile.println(timestamp); | |
// zweiter Messwert | |
myFile.print(HUMI_ID); | |
myFile.print(","); | |
myFile.print(hdc.getHumidity()); | |
myFile.print(","); | |
myFile.println(timestamp); | |
// Datei nachher schliessen | |
myFile.close(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment