質問編集履歴
1
ご指摘ありがとうございます。コードを貼り付けなおしました。(なお間違っていたら申し訳ありません)
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,4 +1,204 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
|
3
|
+
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
|
4
|
+
|
5
|
+
#include <ESP8266WiFi.h>
|
6
|
+
|
7
|
+
#include <BlynkSimpleEsp8266.h>
|
8
|
+
|
9
|
+
#include <BME280_MOD-1022.h>
|
10
|
+
|
11
|
+
#include <Wire.h>
|
12
|
+
|
13
|
+
|
14
|
+
|
15
|
+
// You should get Auth Token in the Blynk App.
|
16
|
+
|
17
|
+
// Go to the Project Settings (nut icon).
|
18
|
+
|
19
|
+
char auth[] = "xxxxxxxxxxx"; //Blynkで生成されるAuth Token
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
unsigned long lastCheck = 0;
|
24
|
+
|
25
|
+
double tempMostAccurate, humidityMostAccurate, pressureMostAccurate;
|
26
|
+
|
27
|
+
char buff[50];
|
28
|
+
|
29
|
+
|
30
|
+
|
31
|
+
// Arduino needs this to pring pretty numbers
|
32
|
+
|
33
|
+
|
34
|
+
|
35
|
+
void printFormattedFloat(float x, uint8_t precision) {
|
36
|
+
|
37
|
+
char buffer[10];
|
38
|
+
|
39
|
+
|
40
|
+
|
41
|
+
dtostrf(x, 7, precision, buffer);
|
42
|
+
|
43
|
+
Serial.print(buffer);
|
44
|
+
|
45
|
+
}
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
void setup()
|
50
|
+
|
51
|
+
{
|
52
|
+
|
53
|
+
Serial.begin(115200);
|
54
|
+
|
55
|
+
Blynk.begin(auth, "xxxxxxxxx", "xxxxxxxxx"); //無線ルーターのSSIDとパスワード
|
56
|
+
|
57
|
+
Wire.begin();
|
58
|
+
|
59
|
+
pinMode(12, OUTPUT);
|
60
|
+
|
61
|
+
|
62
|
+
|
63
|
+
// need to read the NVM compensation parameters
|
64
|
+
|
65
|
+
BME280.readCompensationParams();
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
BME280.writeStandbyTime(tsb_0p5ms); // tsb = 0.5ms
|
70
|
+
|
71
|
+
BME280.writeFilterCoefficient(fc_16); // IIR Filter coefficient 16
|
72
|
+
|
73
|
+
BME280.writeOversamplingPressure(os16x); // pressure x16
|
74
|
+
|
75
|
+
BME280.writeOversamplingTemperature(os2x); // temperature x2
|
76
|
+
|
77
|
+
BME280.writeOversamplingHumidity(os1x); // humidity x1
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
BME280.writeMode(smNormal);
|
82
|
+
|
83
|
+
}
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
void formattedFloat(float x, uint8_t precision, char *buff) {
|
88
|
+
|
89
|
+
dtostrf(x, 7, precision, buff);
|
90
|
+
|
91
|
+
}
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
BLYNK_READ(V0)
|
96
|
+
|
97
|
+
{
|
98
|
+
|
99
|
+
tempMostAccurate = BME280.getTemperatureMostAccurate();
|
100
|
+
|
101
|
+
|
102
|
+
|
103
|
+
Serial.print("Temp ");
|
104
|
+
|
105
|
+
printFormattedFloat(tempMostAccurate, 2);
|
106
|
+
|
107
|
+
Serial.println();
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
formattedFloat(tempMostAccurate, 2, buff);
|
112
|
+
|
113
|
+
Blynk.virtualWrite(V0, buff);
|
114
|
+
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
|
119
|
+
BLYNK_READ(V1)
|
120
|
+
|
121
|
+
{
|
122
|
+
|
123
|
+
humidityMostAccurate = BME280.getHumidityMostAccurate();
|
124
|
+
|
125
|
+
|
126
|
+
|
127
|
+
Serial.print("humid ");
|
128
|
+
|
129
|
+
printFormattedFloat(humidityMostAccurate, 2);
|
130
|
+
|
131
|
+
Serial.println();
|
132
|
+
|
133
|
+
|
134
|
+
|
135
|
+
|
136
|
+
|
137
|
+
formattedFloat(humidityMostAccurate, 2, buff);
|
138
|
+
|
139
|
+
Blynk.virtualWrite(V1, buff);
|
140
|
+
|
141
|
+
}
|
142
|
+
|
143
|
+
|
144
|
+
|
145
|
+
BLYNK_READ(V2)
|
146
|
+
|
147
|
+
{
|
148
|
+
|
149
|
+
pressureMostAccurate = BME280.getPressureMostAccurate();
|
150
|
+
|
151
|
+
|
152
|
+
|
153
|
+
Serial.print("pressure ");
|
154
|
+
|
155
|
+
printFormattedFloat(pressureMostAccurate, 2);
|
156
|
+
|
157
|
+
Serial.println();
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
formattedFloat(pressureMostAccurate, 2, buff);
|
162
|
+
|
163
|
+
Blynk.virtualWrite(V2, buff);
|
164
|
+
|
165
|
+
}
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
void loop()
|
170
|
+
|
171
|
+
{
|
172
|
+
|
173
|
+
Blynk.run();
|
174
|
+
|
175
|
+
int diff = millis() - lastCheck;
|
176
|
+
|
177
|
+
if (diff > 1000) {
|
178
|
+
|
179
|
+
while (BME280.isMeasuring() ) {
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
}
|
184
|
+
|
185
|
+
// read out the data - must do this before calling the getxxxxx routines
|
186
|
+
|
187
|
+
BME280.readMeasurements();
|
188
|
+
|
189
|
+
lastCheck = millis();
|
190
|
+
|
191
|
+
} else if (diff < 0) {
|
192
|
+
|
193
|
+
lastCheck = 0;
|
194
|
+
|
195
|
+
}
|
196
|
+
|
197
|
+
}
|
198
|
+
|
199
|
+
|
200
|
+
|
1
|
-
### 前提・実現したいこと
|
201
|
+
```### 前提・実現したいこと
|
2
202
|
|
3
203
|
初心者です。
|
4
204
|
|