Copyright ©

Mongoose OS Forum

ATTENTION! This forum has moved to:

Do not post any new messages.

BME280 fails(-128) after random amount of time ESP32

Hello! I am using the latest mos and ESP32.
I also use MJS for my project mainly. I am using I2C ports 21 scl /22 sda, 0x76 as address and things work just fine for 20-30 minutes sometimes it works for hours, after that it starts returning -128 both for temperature and humidity.
Right now my code that handles BME is like this:

let sensor = BME280.createI2C(0x76);
let TEMP = 0;
let HUM = 0;

function updateSensorReadings() {
  let t = bmeSensor.readTemp();
  let h = bmeSensor.readHumid();
  print("Got sensor data: ", t, h);
  if (!isNaN(h)) {
    HUM = floor(h);
  if (!isNaN(t)) {
    TEMP = floor(t);


  10000 /* milliseconds */,
  function() {

What I tried:

changing sensors
changing bme280 libs (tried the arduino one from adafruit),
tried to instantiate the sensor object right before querying the temperature and humidity and freeing the instance (.free()) after each read
tried to check the source code and from that I can only assume that during use the ESP32 will lose sight of the sensor which will trigger the null_ptr/bme_error return (-128).
I use the BME280 board, so I tried to run it in 3.3v and 5v, same results.
Tried another different sensor (DHT22) and it worked fine, no problems.
Tried Different ESP32 (mine local and from a client that is showing the same problem)

Can anyone point me in the right direction? have you have encountered this problem?
Thank you!


  • nliviunliviu Romania

    I don't know what the "BME280 board" is.
    Do you have pull-up resistors on the SCL/SDA lines?
    How long is the I2C cable?

  • Hi @nliviu thanks!!

    The cable cable is around 50cm (19 inches). I havent added resistors.

    its this little board

  • nliviunliviu Romania

    I have the same modules and they work very well with several Wemos modules (Lolin 32 and 32 pro, Lolin D32 and D32 pro).

Sign In or Register to comment.