-
Notifications
You must be signed in to change notification settings - Fork 16
/
BME280.ino
99 lines (78 loc) · 2.29 KB
/
BME280.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
93
94
95
96
97
98
99
// This example requires SparkFun's BME280 library.
// https://github.com/sparkfun/SparkFun_BME280_Arduino_Library
#include "SparkFunBME280.h"
#include "Wire.h"
#include <SakuraIO.h>
SakuraIO_I2C sakuraio;
BME280 bme280;
uint32_t cnt = 0;
void setup() {
Serial.begin(9600);
// Setup BME280
bme280.settings.commInterface = I2C_MODE; // Use I2C Interface
bme280.settings.I2CAddress = 0x76; // I2C Address
bme280.settings.runMode = 3; // Normal mode
bme280.settings.tempOverSample = 1;
bme280.settings.pressOverSample = 1;
bme280.settings.humidOverSample = 1;
delay(10);
if (bme280.begin() != 0x60)
{
Serial.println("BME280 communication error!");
while (1);
}
Serial.print("Waiting to come online");
for (;;) {
if ( (sakuraio.getConnectionStatus() & 0x80) == 0x80 ) break;
Serial.print(".");
delay(1000);
}
Serial.println("");
}
void loop() {
cnt++;
float temp = bme280.readTempC();
float humi = bme280.readFloatHumidity();
float pressure = bme280.readFloatPressure() / 100; // hPa
float altitude = bme280.readFloatAltitudeMeters();
Serial.println();
Serial.println(cnt);
Serial.print("Temperature: ");
Serial.print(temp, 2);
Serial.println(" deg C");
Serial.print("Humidity: ");
Serial.print(humi, 2);
Serial.println(" %");
Serial.print("Pressure: ");
Serial.print(pressure, 2);
Serial.println(" hPa");
Serial.print("Altitude: ");
Serial.print(altitude, 2);
Serial.println(" m");
if (sakuraio.enqueueTx(0, cnt) != CMD_ERROR_NONE) {
Serial.println("[ERR] enqueue error");
}
if (sakuraio.enqueueTx(1, temp) != CMD_ERROR_NONE) {
Serial.println("[ERR] enqueue error");
}
if (sakuraio.enqueueTx(2, humi) != CMD_ERROR_NONE) {
Serial.println("[ERR] enqueue error");
}
if (sakuraio.enqueueTx(3, pressure) != CMD_ERROR_NONE) {
Serial.println("[ERR] enqueue error");
}
if (sakuraio.enqueueTx(4, altitude) != CMD_ERROR_NONE) {
Serial.println("[ERR] enqueue error");
}
sakuraio.send();
delay(5000);
uint8_t available;
uint8_t queued;
if (sakuraio.getTxQueueLength(&available, &queued) != CMD_ERROR_NONE) {
Serial.println("[ERR] get tx queue length error");
}
Serial.print("Available :");
Serial.print(available);
Serial.print(" Queued :");
Serial.println(queued);
}