-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathco2_logger_octi_scd30.ino
92 lines (78 loc) · 2.28 KB
/
co2_logger_octi_scd30.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include <SPI.h>
#include <SD.h>
#include <Wire.h>
#include <SparkFun_SCD30_Arduino_Library.h>
#include <ESP8266WiFi.h>
// Set the pins used
#define cardSelect 15
File logfile;
SCD30 airSensorSCD30; // Objekt SDC30 Umweltsensor
// blink out an error code
void error(uint8_t errno) {
while(1) {
uint8_t i;
for (i=0; i<errno; i++) {
delay(100);
}
for (i=errno; i<10; i++) {
delay(200);
}
}
}
// This line is not needed if you have Adafruit SAMD board package 1.6.2+
// #define Serial SerialUSB
void setup() {
// connect at 115200 so we can read the GPS fast enough and echo without dropping chars
// also spit it out
Serial.begin(115200);
Serial.println("\r\nCO2-Sensor logger test");
WiFi.forceSleepBegin(); // Wifi off
Wire.begin(); // ---- Initialisiere den I2C-Bus
if (Wire.status() != I2C_OK) Serial.println("Something wrong with I2C");
if (airSensorSCD30.begin() == false) {
Serial.println("The SCD30 did not respond. Please check wiring.");
while(1) {
yield();
delay(1);
}
}
airSensorSCD30.setAutoSelfCalibration(false); // Sensirion no auto calibration
airSensorSCD30.setMeasurementInterval(2); // CO2-Messung alle 2 s
Wire.setClock(100000L); // 100 kHz SCD30
Wire.setClockStretchLimit(200000L);// CO2-SCD30
// see if the card is present and can be initialized:
if (!SD.begin(cardSelect)) {
Serial.println("Card init. failed!");
error(2);
}
char filename[15];
strcpy(filename, "/SENSOR00.TXT");
for (uint8_t i = 0; i < 100; i++) {
filename[7] = '0' + i/10;
filename[8] = '0' + i%10;
// create if does not exist, do not open existing, write, sync after write
if (! SD.exists(filename)) {
break;
}
}
logfile = SD.open(filename, FILE_WRITE);
if( ! logfile ) {
Serial.print("Couldnt create ");
Serial.println(filename);
error(3);
}
Serial.print("Writing to ");
Serial.println(filename);
pinMode(0, OUTPUT);
Serial.println("Ready!");
}
uint8_t i=0;
void loop() {
digitalWrite(0, HIGH);
logfile.print("CO2 = "); logfile.println(airSensorSCD30.getCO2());
Serial.print("CO2 = "); Serial.println(airSensorSCD30.getCO2());
delay(500);
digitalWrite(0, LOW);
logfile.flush(); // 30mA instead of 10mA in avg ...
delay(5000);
}