Skip to content

Instantly share code, notes, and snippets.

@Thiemann96
Last active February 2, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Thiemann96/6a6db6501993efd296848720e0c8e2de to your computer and use it in GitHub Desktop.
Save Thiemann96/6a6db6501993efd296848720e0c8e2de to your computer and use it in GitHub Desktop.
Saves on SD card every 60 seconds
#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