-
Notifications
You must be signed in to change notification settings - Fork 0
/
container_rh_sensor_firmware.ino
65 lines (52 loc) · 1.24 KB
/
container_rh_sensor_firmware.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
#include <Arduino.h>
#include <M5Stack.h>
#include <M5UnitENV.h>
SCD4X scd4x;
void setup()
{
M5.begin();
M5.Power.begin();
M5.Lcd.fillScreen(WHITE);
M5.Lcd.setTextWrap(true, true);
if (!scd4x.begin(&Wire, SCD4X_I2C_ADDR, 32, 33, 400000U))
{
M5.Lcd.print("Couldn't find sensor");
while (1)
delay(1);
}
uint16_t error;
// stop potentially previously started measurement
error = scd4x.stopPeriodicMeasurement();
if (error)
{
M5.Lcd.print("Error trying to execute stopPeriodicMeasurement(): ");
}
// Start Measurement
error = scd4x.startPeriodicMeasurement();
if (error)
{
M5.Lcd.print("Error trying to execute startPeriodicMeasurement(): ");
}
M5.Lcd.print("Waiting for first measurement... (5 sec)");
}
void loop()
{
if (scd4x.update()) // readMeasurement will return true when
// fresh data is available
{
M5.Lcd.clear(WHITE);
M5.Lcd.setCursor(0,0);
M5.Lcd.print("CO2(ppm):");
M5.Lcd.print(scd4x.getCO2());
M5.Lcd.print("\tTemperature(C):");
M5.Lcd.print(scd4x.getTemperature(), 1);
M5.Lcd.print("\tHumidity(%RH):");
M5.Lcd.print(scd4x.getHumidity(), 1);
M5.Lcd.println();
}
else
{
M5.Lcd.print(".");
}
delay(1000);
}