init ci
This commit is contained in:
commit
599137c7b4
1 file changed
+84
+84
@@ -0,0 +1,84 @@
|
|||||||
|
#include <OneWire.h>
|
||||||
|
#include <DallasTemperature.h>
|
||||||
|
#include <U8g2lib.h>
|
||||||
|
#include <SD.h>
|
||||||
|
|
||||||
|
#define ONE_WIRE_BUS D4
|
||||||
|
#define PIN_CS D8
|
||||||
|
|
||||||
|
#define STATUS_OK 0
|
||||||
|
#define STATUS_SD_INIT_FAILED 1
|
||||||
|
#define STATUS_SD_WRITE_FAILED 2
|
||||||
|
|
||||||
|
#define ODD 1
|
||||||
|
#define EVEN 2
|
||||||
|
|
||||||
|
OneWire oneWire( ONE_WIRE_BUS );
|
||||||
|
DallasTemperature DS18B20( &oneWire );
|
||||||
|
U8G2_SSD1306_128X64_NONAME_F_HW_I2C display(U8G2_R0);
|
||||||
|
|
||||||
|
|
||||||
|
int status = STATUS_OK;
|
||||||
|
int oddEvenLoop = ODD;
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
Serial.begin(115200);
|
||||||
|
DS18B20.begin();
|
||||||
|
display.begin();
|
||||||
|
|
||||||
|
if (!SD.begin(PIN_CS)) {
|
||||||
|
status = STATUS_SD_INIT_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
char tempStr[6];
|
||||||
|
long uptimeSec = millis() / 1000;
|
||||||
|
|
||||||
|
DS18B20.requestTemperatures();
|
||||||
|
float tempFl = DS18B20.getTempCByIndex(0);
|
||||||
|
|
||||||
|
dtostrf(tempFl, 4, 1, tempStr);
|
||||||
|
|
||||||
|
Serial.print(uptimeSec);
|
||||||
|
Serial.print(": ");
|
||||||
|
Serial.println(tempStr);
|
||||||
|
|
||||||
|
display.clearBuffer();
|
||||||
|
display.setFont(u8g2_font_fub11_tf);
|
||||||
|
switch(status) {
|
||||||
|
case STATUS_SD_INIT_FAILED:
|
||||||
|
display.drawStr(0, 11, "SD init failed");
|
||||||
|
break;
|
||||||
|
case STATUS_SD_WRITE_FAILED:
|
||||||
|
display.drawStr(0, 11, "SD write failed");
|
||||||
|
break;
|
||||||
|
case STATUS_OK:
|
||||||
|
default:
|
||||||
|
if (oddEvenLoop == ODD) {
|
||||||
|
display.drawStr(0, 11, "Temperatur *");
|
||||||
|
oddEvenLoop = EVEN;
|
||||||
|
} else {
|
||||||
|
display.drawStr(0, 11, "Temperatur #");
|
||||||
|
oddEvenLoop = ODD;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
display.setFont(u8g2_font_fub42_tn);
|
||||||
|
display.drawStr(8, 63, tempStr);
|
||||||
|
display.sendBuffer();
|
||||||
|
|
||||||
|
if (status != STATUS_SD_INIT_FAILED) {
|
||||||
|
File fd = SD.open("temp.csv", FILE_WRITE);
|
||||||
|
if (fd) {
|
||||||
|
fd.print(uptimeSec);
|
||||||
|
fd.print(";");
|
||||||
|
fd.println(tempStr);
|
||||||
|
fd.close();
|
||||||
|
status = STATUS_OK;
|
||||||
|
} else {
|
||||||
|
status = STATUS_SD_WRITE_FAILED;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
delay(5000);
|
||||||
|
}
|
||||||
Reference in new issue
Block a user