Hi,
I am trying to create some code to have the BME680 go through the ESP8266 to Blynk. I wanted to see if anyone has already created some code to do this, I’ve been failing miserably.
I’ve had been able to connect a good ol’ DHT11. Now, I’m trying to get the BME680 to work and have come up with some errors (below) and I’ll post my code below that.
> C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp: In member function 'bool Adafruit_BME680::begin(uint8_t)':
C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp:89:5: error: 'Wire' was not declared in this scope
Wire.begin();
^
C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp: In function 'int8_t i2c_read(uint8_t, uint8_t, uint8_t*, uint16_t)':
C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp:457:3: error: 'Wire' was not declared in this scope
Wire.beginTransmission((uint8_t)dev_id);
^
C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp: In function 'int8_t i2c_write(uint8_t, uint8_t, uint8_t*, uint16_t)':
C:\libraries\Adafruit_BME680_Library\Adafruit_BME680.cpp:488:3: error: 'Wire' was not declared in this scope
Wire.beginTransmission((uint8_t)dev_id);
Here’s my code:
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BME680.h"
#include <SPI.h>
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
#define SEALEVELPRESSURE_HPA (1011)
char auth[] = "XXXX";
// WiFi credentials.
char ssid[] = "XXXX";
char pass[] = "XXXX";
Adafruit_BME680 bme; // I2C
SimpleTimer timer;
void sendSensor()
{
float t = bme.readTemperature();
float p = (bme.readPressure() / 100.0F);
float h = bme.readHumidity();
float g = (bme.gas_resistance / 1000.0);
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, h);
Blynk.virtualWrite(V4, a);
}
void setup()
{
Serial.begin(9600);
Blynk.begin(auth, ssid, pass);
while (Blynk.connect() == false)
bme.begin();
timer.setInterval(5000L, sendSensor); //1000L is one second
}
void loop() {
Blynk.run();
timer.run();
}