-->
Page 1 of 2

BME280 and ESP01

PostPosted: Sun Jan 24, 2021 11:19 am
by Juanan
Hello. I am developing a project in which I have encountered some problems. I am using an esp01 and a bme280 to measure the temperature of different rooms and send this information to a screen via udp.
My problem is in the module composed of the esp01 and the temperature sensor. After a time correctly measuring the temperature, the sensor begins to send erroneous data (indicating -147 in temperature and 100 in humidity). I have modified the code so that after taking the measurement the sensor turns off and does not turn on again until the next loop, but the result is the same. Currently I don't know how I can solve this error.
I attach my code and the image of the connections I am using.

Captura.JPG

Code: Select all#include <Wire.h>
#include <ESP8266WiFi.h>
#include <WiFiUDP.h>
#include <SPI.h>
#include <Adafruit_BME280.h>

#include "config.h"
#include "UDP.hpp"
#include "ESP8266_Utils.hpp"
#include "ESP8266_Utils_UDP.hpp"

#define pin_bme 3
Adafruit_BME280 bme;
int sensor[] = {0, 0};

void setup()
{
  ConnectWiFi_STA();
  ConnectUDP();
  pinMode(pin_bme, OUTPUT);
  digitalWrite(pin_bme, LOW);
}

void loop()
{
  digitalWrite(pin_bme, HIGH);
  delay(500);
  Wire.begin(0, 2);
  bme.begin(0x76);
  delay(4000);
  sensor[0] = bme.readTemperature();
  sensor[1] = bme.readHumidity();

  String packet = (String)sensor[0] + "." + (String)sensor[1];
  SendUDP_Packet(packet);

  digitalWrite(pin_bme, LOW);
  delay(1000);
}

Thx.

Re: BME280 and ESP01

PostPosted: Tue Jan 26, 2021 3:40 am
by QuickFix
From this website on noveldevices.co.uk:
2. INTERMITTENT CONNECTIONS
A sensor returns an unexpected value or NaN. This problem may present itself as either transient or permanent and can be caused by a poor connection to ground or 3V3. To find the problem, move one of the connections to another equivalent pin or just reconnect both wires to a different set of ground and 3V3 pins. If you're using breadboard patch leads and the fault persists then it could be the leads themselves. If you replace the patch leads throw the old ones away or they will come back to haunt you.

You might want to check that. :idea:

Re: BME280 and ESP01

PostPosted: Tue Jan 26, 2021 6:18 am
by Juanan
Hi QuickFix, thx for the reply.
I will try to change all my wires and post the result as soon as i can.

Re: BME280 and ESP01

PostPosted: Wed Jan 27, 2021 11:13 am
by eriksl
I once had a batch of bogus ones. They gave all sorts of erronous readings (continuously, not varying with temperature or humidity). I complained and got others and they worked like a charm, using the same code and the same hardware. So you might be victim of the same bogus ones.

Also be aware often BMP280's are sold are BME280's. They are completely identical, but only the BME280 has humidity support. The BMP280 will not give an error, but it will return bogus values. Only in the chip ID you can see which one it is.