blob: 46ff6b00c19244f69636856d6f2b93fb631255a7 (
plain)
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
|
/*
* Copyright 2020 Daniel Friesel
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include "arch.h"
#include "driver/gpio.h"
#include "driver/stdout.h"
#if defined(DRIVER_I2C)
#include "driver/i2c.h"
#elif defined(DRIVER_SOFTI2C)
#include "driver/soft_i2c.h"
#endif
#ifdef DRIVER_LM75
#include "driver/lm75.h"
#endif
#ifdef DRIVER_S5851A
#include "driver/s5851a.h"
#endif
#ifdef DRIVER_AM2320
#include "driver/am2320.h"
#endif
#ifdef DRIVER_BME280
#include "driver/bme280.h"
#include "driver/bme680_util.h"
#endif
#ifdef DRIVER_BME680
#include "driver/bme680.h"
#include "driver/bme680_util.h"
#endif
#ifdef DRIVER_CCS811
#include "driver/ccs811.h"
#endif
#ifdef DRIVER_MAX44009
#include "driver/max44009.h"
#endif
#ifdef DRIVER_HDC1080
#include "driver/hdc1080.h"
#endif
#ifdef DRIVER_MPU9250
#include "driver/mpu9250.h"
#endif
#ifdef DRIVER_TSL2591
#include "driver/tsl2591.h"
#endif
#ifdef DRIVER_SCD4X
#include "driver/scd4x.h"
#endif
void loop(void)
{
#ifdef DRIVER_LM75
kout << "temperature_celsius: ";
kout.printf_float(lm75.getTemp());
kout << endl;
#endif
#ifdef DRIVER_S5851A
kout << "temperature_celsius: ";
kout.printf_float(s5851a.getTemp());
kout << endl;
#endif
#ifdef DRIVER_AM2320
am2320.read();
if (am2320.getStatus() == 0) {
kout.printf_float(am2320.getTemp());
kout << " degC @ ";
kout.printf_float(am2320.getHumidity());
kout << " rel%" << endl;
} else {
kout << "AM2320 error " << dec << am2320.getStatus() << endl;
}
#endif
#ifdef DRIVER_BME280
struct bme280_data comp_data;
int8_t rslt = bme280.getSensorData(BME280_ALL, &comp_data);
kout << "BME280 read " << rslt << endl;
kout << "BME280 temperature " << (float)comp_data.temperature / 100 << " degC" << endl;
kout << "BME280 humidity " << (float)comp_data.humidity / 1024 << " %" << endl;
kout << "BME280 pressure " << (float)comp_data.pressure / 100 << " Pa" << endl;
#endif
#ifdef DRIVER_BME680
struct bme680_field_data data;
bme680.setSensorMode();
arch.delay_ms(250);
bme680.getSensorData(&data);
kout << "BME680 temperature " << (float)data.temperature / 100 << " degC" << endl;
kout << "BME680 humidity " << (float)data.humidity / 1000 << " %" << endl;
kout << "BME680 pressure " << (float)data.pressure / 100 << " hPa" << endl;
kout << "BME680 gas resistance " << data.gas_resistance << endl;
#endif
#ifdef DRIVER_CCS811
ccs811.read();
kout << bin;
kout << "CCS811 status / error: " << ccs811.status << " / " << ccs811.error_id << endl;
kout << dec;
kout << "CCS811 tVOC / eCO₂ : " << ccs811.tvoc << " ppb / " << ccs811.eco2 << " ppm" << endl;
#endif
#ifdef DRIVER_HDC1080
/*
hdc1080.heater(1);
for (unsigned char i = 0; i < 50; i++) {
hdc1080.getTemp();
}
*/
kout << "HDC1080 temperature " << hdc1080.getTemp() << " degC" << endl;
kout << "HDC1080 humidity " << hdc1080.getRH() << " %H" << endl;
#endif
#ifdef DRIVER_MPU9250
int mx, my, mz;
kout << "Temperature: " << mpu9250.getTemperature() << endl;
kout << "Accel X " << mpu9250.getAccelX() << endl;
kout << "Accel Y " << mpu9250.getAccelY() << endl;
kout << "Accel Z " << mpu9250.getAccelZ() << endl;
kout << "Gyro X " << mpu9250.getGyroX() << endl;
kout << "Gyro Y " << mpu9250.getGyroY() << endl;
kout << "Gyro Z " << mpu9250.getGyroZ() << endl;
mpu9250.getRawMagnet(&mx, &my, &mz);
kout << "Magnet X " << mx << endl;
kout << "Magnet Y " << my << endl;
kout << "Magnet Z " << mz << endl;
#endif
#ifdef DRIVER_MAX44009
kout.printf_float(max44009.getLux());
kout << endl;
#endif
#ifdef DRIVER_TSL2591
tsl2591.read();
kout << dec << "TSL2591 CH0: " << tsl2591.ch0 << " / CH1: " << tsl2591.ch1;
kout << hex << " (status: 0x" << tsl2591.getStatus() << ")" << endl;
#endif
#ifdef DRIVER_SCD4X
scd4x.read();
kout << dec << "CO₂: " << scd4x.co2 << " ppm" << endl;
kout << "Temperature: ";
kout.printf_float(((175.0 * scd4x.rawTemperature) / 65536) - 45);
kout << " °c" << endl;
kout << "Humidity: ";
kout.printf_float((100.0 * scd4x.rawHumidity) / 65536);
kout << " %" << endl;
#endif
}
int main(void)
{
arch.setup();
gpio.setup();
kout.setup();
#if defined(DRIVER_I2C) || defined(DRIVER_SOFTI2C)
if (i2c.setup() != 0) {
kout << "I2C setup FAILED" << endl;
return 1;
}
kout << "I2C setup OK" << endl;
#endif
#ifdef DRIVER_BME280
bme280.intf = BME280_I2C_INTF;
bme280.read = bme680_i2c_read;
bme280.write = bme680_i2c_write;
bme280.delay_ms = bme680_delay_ms;
int8_t rslt = BME280_OK;
rslt = bme280.init();
kout << "BME280 init " << rslt << endl;
bme280.settings.osr_p = BME280_OVERSAMPLING_16X;
bme280.settings.osr_t = BME280_OVERSAMPLING_16X;
bme280.settings.osr_h = BME280_OVERSAMPLING_16X;
bme280.settings.filter = BME280_FILTER_COEFF_OFF;
bme280.settings.standby_time = BME280_STANDBY_TIME_500_MS;
bme280.setSensorSettings(BME280_OSR_PRESS_SEL | BME280_OSR_TEMP_SEL | BME280_OSR_HUM_SEL | BME280_FILTER_SEL | BME280_STANDBY_SEL);
bme280.enterNormalMode();
#endif
#ifdef DRIVER_BME680
bme680.intf = BME680_I2C_INTF;
bme680.read = bme680_i2c_read;
bme680.write = bme680_i2c_write;
bme680.delay_ms = bme680_delay_ms;
bme680.amb_temp = 25;
int8_t rslt = BME680_OK;
rslt = bme680.init();
kout << "BME680 init " << rslt << endl;
bme680.power_mode = BME680_FORCED_MODE;
bme680.tph_sett.os_hum = BME680_OS_1X;
bme680.tph_sett.os_pres = BME680_OS_16X;
bme680.tph_sett.os_temp = BME680_OS_2X;
bme680.gas_sett.run_gas = BME680_ENABLE_GAS_MEAS;
bme680.gas_sett.heatr_dur = 100;
bme680.gas_sett.heatr_temp = 300;
bme680.setSensorSettings(BME680_OST_SEL | BME680_OSP_SEL | BME680_OSH_SEL | BME680_GAS_SENSOR_SEL);
#endif
#ifdef DRIVER_CCS811
kout << hex;
kout << "CCS811 HWID: " << ccs811.getManufacturerID() << endl;
arch.delay_ms(65);
kout << "CCS811 status: " << ccs811.getStatus() << endl;
arch.delay_ms(65);
ccs811.init();
arch.delay_ms(65);
kout << "CCS811 status: " << ccs811.getStatus() << endl;
kout << dec;
ccs811.setMode(1);
arch.delay_ms(50);
#endif
#ifdef DRIVER_HDC1080
hdc1080.init();
if (hdc1080.getManufacturerID() != 0x5449) {
kout << "[!] invalid HDC1080 manufacturer ID: " << hex << hdc1080.getManufacturerID() << endl;
}
#endif
#ifdef DRIVER_MPU9250
mpu9250.init();
#endif
#ifdef DRIVER_TSL2591
tsl2591.init();
#endif
#ifdef DRIVER_SCD4X
scd4x.start();
#endif
arch.idle_loop();
return 0;
}
|