質問編集履歴
1
ご指摘ありがとうございます。コードを貼り付けなおしました。(なお間違っていたら申し訳ありません)
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,4 +1,104 @@
|
|
1
|
+
```ここに言語を入力
|
2
|
+
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
|
3
|
+
#include <ESP8266WiFi.h>
|
4
|
+
#include <BlynkSimpleEsp8266.h>
|
5
|
+
#include <BME280_MOD-1022.h>
|
6
|
+
#include <Wire.h>
|
7
|
+
|
8
|
+
// You should get Auth Token in the Blynk App.
|
9
|
+
// Go to the Project Settings (nut icon).
|
10
|
+
char auth[] = "xxxxxxxxxxx"; //Blynkで生成されるAuth Token
|
11
|
+
|
12
|
+
unsigned long lastCheck = 0;
|
13
|
+
double tempMostAccurate, humidityMostAccurate, pressureMostAccurate;
|
14
|
+
char buff[50];
|
15
|
+
|
16
|
+
// Arduino needs this to pring pretty numbers
|
17
|
+
|
18
|
+
void printFormattedFloat(float x, uint8_t precision) {
|
19
|
+
char buffer[10];
|
20
|
+
|
21
|
+
dtostrf(x, 7, precision, buffer);
|
22
|
+
Serial.print(buffer);
|
23
|
+
}
|
24
|
+
|
25
|
+
void setup()
|
26
|
+
{
|
27
|
+
Serial.begin(115200);
|
28
|
+
Blynk.begin(auth, "xxxxxxxxx", "xxxxxxxxx"); //無線ルーターのSSIDとパスワード
|
29
|
+
Wire.begin();
|
30
|
+
pinMode(12, OUTPUT);
|
31
|
+
|
32
|
+
// need to read the NVM compensation parameters
|
33
|
+
BME280.readCompensationParams();
|
34
|
+
|
35
|
+
BME280.writeStandbyTime(tsb_0p5ms); // tsb = 0.5ms
|
36
|
+
BME280.writeFilterCoefficient(fc_16); // IIR Filter coefficient 16
|
37
|
+
BME280.writeOversamplingPressure(os16x); // pressure x16
|
38
|
+
BME280.writeOversamplingTemperature(os2x); // temperature x2
|
39
|
+
BME280.writeOversamplingHumidity(os1x); // humidity x1
|
40
|
+
|
41
|
+
BME280.writeMode(smNormal);
|
42
|
+
}
|
43
|
+
|
44
|
+
void formattedFloat(float x, uint8_t precision, char *buff) {
|
45
|
+
dtostrf(x, 7, precision, buff);
|
46
|
+
}
|
47
|
+
|
48
|
+
BLYNK_READ(V0)
|
49
|
+
{
|
50
|
+
tempMostAccurate = BME280.getTemperatureMostAccurate();
|
51
|
+
|
52
|
+
Serial.print("Temp ");
|
53
|
+
printFormattedFloat(tempMostAccurate, 2);
|
54
|
+
Serial.println();
|
55
|
+
|
56
|
+
formattedFloat(tempMostAccurate, 2, buff);
|
57
|
+
Blynk.virtualWrite(V0, buff);
|
58
|
+
}
|
59
|
+
|
60
|
+
BLYNK_READ(V1)
|
61
|
+
{
|
62
|
+
humidityMostAccurate = BME280.getHumidityMostAccurate();
|
63
|
+
|
64
|
+
Serial.print("humid ");
|
65
|
+
printFormattedFloat(humidityMostAccurate, 2);
|
66
|
+
Serial.println();
|
67
|
+
|
68
|
+
|
69
|
+
formattedFloat(humidityMostAccurate, 2, buff);
|
70
|
+
Blynk.virtualWrite(V1, buff);
|
71
|
+
}
|
72
|
+
|
73
|
+
BLYNK_READ(V2)
|
74
|
+
{
|
75
|
+
pressureMostAccurate = BME280.getPressureMostAccurate();
|
76
|
+
|
77
|
+
Serial.print("pressure ");
|
78
|
+
printFormattedFloat(pressureMostAccurate, 2);
|
79
|
+
Serial.println();
|
80
|
+
|
81
|
+
formattedFloat(pressureMostAccurate, 2, buff);
|
82
|
+
Blynk.virtualWrite(V2, buff);
|
83
|
+
}
|
84
|
+
|
85
|
+
void loop()
|
86
|
+
{
|
87
|
+
Blynk.run();
|
88
|
+
int diff = millis() - lastCheck;
|
89
|
+
if (diff > 1000) {
|
90
|
+
while (BME280.isMeasuring() ) {
|
91
|
+
|
92
|
+
}
|
93
|
+
// read out the data - must do this before calling the getxxxxx routines
|
94
|
+
BME280.readMeasurements();
|
95
|
+
lastCheck = millis();
|
96
|
+
} else if (diff < 0) {
|
97
|
+
lastCheck = 0;
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
1
|
-
### 前提・実現したいこと
|
101
|
+
```### 前提・実現したいこと
|
2
102
|
初心者です。
|
3
103
|
ESP-WROOM-02(開発モジュール)とBME280(温湿度気圧センサー)を使用して、計測したデータをWifi経由でblynkに表示させようとしています。
|
4
104
|
参考サイト 島貫農園様 http://shimanuki-farm.net/archives/955/
|