Trying to connect esp8266 to bme280 but cant pull out readings

Hi, Iā€™m trying to connect an Adafruit Huzzah ESP8266 to a BME280 sensor, but i cant seem to pull any values out, I think Iā€™m having trouble with the SPI connection?

This is my code, I used a similar setup with a 101 and it worked fine.

Any ideas?

#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();
}

To start with you have included the SPI library twice.

Have you also had any success with the example provides in the BME280 library?

Yes i got that example to work in the serial monitor and then amended another for the DHT22 for BLE

Add this code to your setup:

    Serial.println("Could not find a valid BME280 sensor, check wiring!");
    while (1);
  }```
1 Like

Thanks seems to be working great now :thumbsup:

,

1 Like

actually it only appears to be working with the FTDI friend connected

EDIT: just my spark fun power supply not giving its labeled power outage

1 Like