ESP8266 and BME280 Temp, Pressure and Humidity sensor usage

Corrected copy.

Wrote this sketch for those that want to use the BME280 sensor with the ESP8266.

Rick

#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <Wire.h>
#include <BME280.h>//sensor library Adafruit or other
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = “TOKEN HERE”;
// Your network name and password.
char ssid[] = “SSID HERE“;
char password[] = “PASSWORD HERE”;


// Virtual Pins of the BME280 widget.
#define TEMPERATURE_PIN V0
#define BAROMETER_PIN V1
#define HUMIDITY_PIN V2

BME280 bme; //Create an instance of the sensor


void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
  bme.begin();
}

void loop()
{
  Cayenne.run();
}

// These functions are called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)
{
  // Send the Temperature value to Cayenne
  Cayenne.virtualWrite(V0, bme.ReadTemperature());
}

CAYENNE_OUT(V1)
{
  // Send the Pressure value to Cayenne
  Cayenne.virtualWrite(V1, bme.ReadPressure());
}

CAYENNE_OUT(V2)
{
  // Send the Humidity value to Cayenne
  Cayenne.virtualWrite(V2, bme.ReadHumidity());
}
2 Likes

Take a closer look. Works for me using an analog, and selecting Humidity as type.

Craig

Thanks Craig. I missed it.

Rick

Hi

I get an error

cannot declare variable ‘bme’ to be of abstract type ‘BME280’

Please can anyone help

Matt

Did you install the Adafruit library for BME sensor ?

Hi

I have changed the BME280 library to the Adafruit one, then removed all other ones.

I get this error now = ‘BME280’ does not name a type, BME280 bme; //Create an instance of the sensor

exit status 1
‘BME280’ does not name a type

I think that this error means that there is no definition for that identifier visible for the compiler.
Did you put your library in the right place → sketchbook /libraries path?

C:/ Program Files(x86) / Arduino / Libraries / Adafruit_BME280_Library-master

I also tried my documents / Arduino / libraries

I still get the same error : ‘BME280’ does not name a type

Even to me, this Sketch does not work.
Is it possible to make it work?

Hi @trussino,

Most Adafruit libraries also require the common sensor library:

Make sure you install it and let us know.

Cheers,

Craig

I added this libraty but it does not work.
Maybe I’m wrong? I make a copy and paste the sketch

Seems some issues with unsupported characters and library calls in the above sketch. Try this one. I will try and compile it when I get home:

Also, make sure you are using the Adafruit libraries from here:

#define CAYENNE_DEBUG         // Uncomment to show debug messages
#define CAYENNE_PRINT Serial  // Comment this out to disable prints and save space
#include <Wire.h>
#include <BME280.h> //sensor library Adafruit or other
#include "CayenneDefines.h"
#include "BlynkSimpleEsp8266.h"
#include "CayenneWiFiClient.h"

// Cayenne authentication token. This should be obtained from the Cayenne Dashboard.
char token[] = "TOKEN HERE";
// Your network name and password.
char ssid[] = "SSID HERE";
char password[] = "PASSWORD HERE";


// Virtual Pins of the BME280 widget.
#define TEMPERATURE_PIN V0
#define BAROMETER_PIN V1
#define HUMIDITY_PIN V2

BME280 bme; //Create an instance of the sensor


void setup()
{
  Serial.begin(9600);
  Cayenne.begin(token, ssid, password);
  bme.begin();
}

void loop()
{
  Cayenne.run();
}

// These functions are called when the Cayenne widget requests data for the Virtual Pin.
CAYENNE_OUT(V0)
{
  // Send the Temperature value to Cayenne
  Cayenne.virtualWrite(V0, bme.readTemperature());
}

CAYENNE_OUT(V1)
{
  // Send the Pressure value to Cayenne
  Cayenne.virtualWrite(V1, bme.readPressure());
}

CAYENNE_OUT(V2)
{
  // Send the Humidity value to Cayenne
  Cayenne.virtualWrite(V2, bme.readHumidity());
}
2 Likes

OK. now works.
I modified the sketch with Adafruit “Adafruit_BME280.h” library.

Now you can tell me the connections I have to do.

Bme280 – Nodemcu
GND – GND
3Vo – 3V3
VIN – ???
SCK – ???
SD0 – ???
SD1 – ???
CS – ???

These links are not for Nodemcu + BME280 Adafruit.
I have these circuits

@trussino

NodeMCU / BMP

3.3V / VIN
GND / GND
SCK / SDCLK
SDO / SDDO
SDI / SDD1
CS / SDCMD

Cheers,

Craig

Sorrry! I was making some work the whole day with raspberry and I missed that your thread is for another device!

This is my first post.
I use ArduinoMega and Ethernet Shiels W5100.
After added 2 LEds in dashboard now I want to integrate my BME280 sensor in Cayenne dashboard.
Can you tell me wich are the steps?

Thank you for patience.

Later edit:
From Dashboard:
Add new - Device widget - Custom widget - Value - Pin virtual - Pin number - Data - Unit - Icon.

Copy Cayenne code, make new INO file and paste code, add data from BME280 sensor.
Must add 3 different widges for each BME280 parameters (temperature, pressure and humidity).
I’ll make 1 files with 3 parameters and flash to Arduino.
It’s OK?