
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#include <SPI.h>
#define BLYNK_PRINT Serial // Comment this out to disable prints and save space
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define BME_SCK 14
#define BME_MISO 12
#define BME_MOSI 13
#define BME_CS 15
#define SEALEVELPRESSURE_HPA (1011)
//connect #0,#15 -> low 220 ohm R, take #2 high - cycle
//HSPI 12-MISO, 13-MOSI, 14-CLOCK, 15-CS (16)
char auth[] = "xxxxxxxxxxxxxxxxxxxxxx";
// Your WiFi credentials.
// Set password to "" for open networks.
char ssid[] = "xxxxxxx";
char pass[] = "xxxxxxxxx";
//Adafruit_BME280 bme(BME_CS);
Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
SimpleTimer timer;
void sendSensor()
{
Wire.begin(); //just added
float t = bme.readTemperature();
float p = (bme.readPressure() / 100.0F);
float h = bme.readHumidity();
float a = bme.readAltitude(SEALEVELPRESSURE_HPA);
if (isnan(t) || isnan(p) || isnan(h) || isnan(a)) {
Serial.println("Failed to read from BME sensor!");
return;
}
// You can send any value at any time.
// Please don't send more that 10 values per second.
Blynk.virtualWrite(V0, t);
Blynk.virtualWrite(V1, p);
Blynk.virtualWrite(V2, h);
Blynk.virtualWrite(V3, a);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false)
bme.begin();
timer.setInterval(1000L, sendSensor);
}
void loop() {
Blynk.run();
timer.run();
}
------------------------------------------------------------------------------
if (!bme.begin()) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
------------------------------------------------------------------------------
#include <SPI.h>
------------------------------------------------------------------------------
Комментариев нет:
Отправить комментарий