Esp-01: BME280 not found

I have tested my BMP280 on an Arduino Uno and it can be found but when I connect it as below, the code gets stuck in the BMP280 test loop. Not sure what I might be missing.

/*  HTTPS on ESP8266 with follow redirects, chunked encoding support
    Version 3.0
    Author: Sujay Phadke
    Github: @electronicsguy
    Copyright (C) 2018 Sujay Phadke <electronicsguy123@gmail.com>
    All rights reserved.

    Example Arduino program
*/

#include <ESP8266WiFi.h>
#include "HTTPSRedirect.h"
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>

// Fill ssid and password with your network credentials
const char* ssid = "SSID";
const char* password = "Pwd@";

float temperature;
float humidity;
float pressure;

#define ALTITUDE 19.812 // Altitude in Hamilton, NZ
#define SLEEP_LENGTH 60*15

Adafruit_BME280 bme; // I2C

const char* host = "script.google.com";
// Replace with your own script id to make server side changes
const char *GScriptId = "GScriptId";

const int httpsPort = 443;

// Write to Google Spreadsheet
String url = String("/macros/s/") + GScriptId + "/exec?";


HTTPSRedirect* client = nullptr;

void setup() {
  Serial.begin(115200);
  Serial.flush();

  //BME280 Test
  Serial.println(F("BME280 test connection"));

  bool status = bme.begin(0x76);  
 if (!status) {
    while (1);
  } 
  Serial.println("Success!");
  Serial.println("");

  Serial.print("Connecting to wifi: ");
  Serial.println(ssid);
  // flush() is needed to print the above (connecting...) message reliably,
  // in case the wireless connection doesn't go through
  Serial.flush();

  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
    delay(500);
    Serial.print(".");
  }
  Serial.println("");
  Serial.println("WiFi connected");
  Serial.println("IP address: ");
  Serial.println(WiFi.localIP());

  // Use HTTPSRedirect class to create a new TLS connection
  client = new HTTPSRedirect(httpsPort);
  client->setInsecure();
  client->setPrintResponseBody(true);
  client->setContentTypeHeader("application/json");

  Serial.print("Connecting to ");
  Serial.println(host);

  // Try to connect for a maximum of 5 times
  bool flag = false;
  for (int i = 0; i < 5; i++) {
    int retval = client->connect(host, httpsPort);
    if (retval == 1) {
      flag = true;
      break;
    }
    else
      Serial.println("Connection failed. Retrying...");
  }

  if (!flag) {
    Serial.print("Could not connect to server: ");
    Serial.println(host);
    Serial.println("Exiting...");
    return;
  }

  temperature = bme.readTemperature();
  Serial.print("Temperature: "); Serial.println(temperature);

  humidity = bme.readHumidity();
  Serial.print("Humidity: "); Serial.println(humidity);

  pressure = bme.readPressure(); // pressure in Pa
  pressure = bme.seaLevelForAltitude(ALTITUDE, pressure);
  pressure = pressure / 100.0F; // pressure in hPa
  Serial.print("Pressure: "); Serial.println(pressure);

  // Send memory data to Google Sheets

  String urlFinal = url + "Temperature=" + temperature + "&Humidity=" + humidity + "&Pressure=" + pressure;

  Serial.print("urlFinal "); Serial.println(urlFinal);

  client->GET(urlFinal, host, false);

  // delete HTTPSRedirect object
  delete client;
  client = nullptr;

  delay(3000);
  ESP.deepSleep(SLEEP_LENGTH * 1000000,WAKE_RF_DEFAULT); // // deepSleep time is defined in microseconds. Multiply seconds by 1e6
  delay(100);


}

void loop() {

}```

Try adding pull up resistors, something in the 4K to 5K range should work just fine. Good schematic, easy to follow.

Hi Gilshultz, thanks for that that. Just need to confirm; pull-up means put the resistor from the pin to the 5V line? Do I do one for both the SCL and SDA pins?

Which BMP280 (board), and why BME code.

Pull up (if needed) for a 3.3volt processor (ESP) must go to 3.3volt (not 5volt).
Leo..

Sorry, my mistake; I meant 3.3V (the sketch takes 5v and steps it down to 3.3v) and then the board is BME280

Hi tried the following pull-up but no joy: https://www.esp8266.com/download/file.php?id=5097&mode=view i.e. pull-up across the SDA pin in VCC.

Please answer the questions.
Which BME board (link).
Most BME boards already have pull up.
Leo..

The initialisation of the bme-object is done without any parameters. This means the library is expecting that the I2C-device is connected to that IO-pins that are dedicated to act as the I2C-interface.

On ESP8266-nodeMCU-bboards this is GPIO4 and GPIO5 which aren't available on a ESP-01

So in the codeline that creates the BME-object you have to specify which IO-pins shall act as the I2C-bus

Here I found an article about a guy that makes use of all four IO-pins of the ESP-01. tricky but programming needs to disconnect from your sensors everytime.

If you can afford to buy a ESP8266 nodeMCU-board I would do that.

best regards Stefan

If I understand the above referenced "Instructable" correctly, all I should need to do is to change the first part of setup() to

void setup() {
  Serial.begin(115200);
  Serial.flush();
  Wire.pins(0, 2);
  Wire.begin(0, 2);
  //BME280 Test
  Serial.println(F("BME280 test connection"));

  bool status = bme.begin();  //The I2C address of the sensor I use is 0x76
 if (!status) {
    while (1);
  } 

i.e. add the Wire commands and remove 0x76 from the bme.begin

As I am only using the BME280, I only need the two pins.

But this does not seem to work either. Maybe it's because I am tired; will look again tomorrow.

I use this
Wire.begin(0, 2);
and added also a DS18B20 on 3
But first I flash it then put on my board.

Use an I2C scanner sometimes the I2C address is different.

Hi Zoomx

Tried Wire.begin(0,2); not using a DS18B20. Also checked the I2C address and it was the standard address.

I always flash the board before connecting anything.

I have also checked the wiring to make sure that the leads from the BME280 are connected to the correct pins (using a continuity meter).

If you can afford to spend $10 you could buy such a logic analyser
it looks like this

if you do a search on your own you will find them in different online-shops for $10

These logic analysers are able to record digital signals at high-speed with the software PulseView. PulseView can decode I2C, Serial, Onwire CAN-Bus etc.
So you can take a close look if the I2C-bus is working as expected.

I had some trouble with a BME20 too.
Not all libraries seemed to work
The online-shop where I bought them recommended this library
https://bitbucket.org/christandlg/bmx280mi/src/master/

best regards Stefan

Connect the RST pin of the ESP-01 to 3.3v or it won't do anything !

I have used the ESP-01 successfully in the past without shorting the RST pin across 3.3V. As per my schematic I have only needed to bridge CH_PD and VCC.

Thanks will try different library

This looks to have what I need: https://www.instructables.com/How-to-use-the-ESP8266-01-pins/. @Deva_Rishi they also show the reset connected to VCC. I will try again tonight.

Final update: got it to work (without adding any extra pull-up resistors or connecting the Rst pin) by using the library mentioned above.

Old ESP01 need shorting the RST pin across 3.3V, new ones not.
Old one should be blue, new ones shold be much darker near black.
I forgot this and wandered for an hour why it didn't start. Anyway use serial out, in my setup TX is still free for debug.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.