Wrong values from BME280?

i have a BME280 and it reads values but… they are not updating and seem very wrong. The sensor reports about 40°C, but i am freezing.

#include <Particle.h>
#include <Arduino.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>


// Set up BME
#define BME_ADDRESS 0x76 // Use i2c_scanner to determine address
Adafruit_BME280 bme;

// define the pin for the led. (D7 is the PIN that is coupled with the on-board LED)
const int ledPin = D7;

// define the pin for the button
const int buttonPin = D5;

// the state of the push button.
int buttonState = HIGH; //not pressed

//this is only for us on the argon side. if its true, we let the onboard LED blinking to show the device is in initialization
int initializePhase = false;

//this is called from webclient->npm server->argon
int initialize(String values);

struct Config {
  uint8_t prefHumidity;
  uint8_t prefTemperature;
} config;

int button_pressed_time = 0;

void displayinitializePhase();

void setup()
{
  Serial.begin(9600);
  if (bme.begin(BME_ADDRESS))
  {
    Particle.publish("info", "BME Sensor found", PRIVATE);
  }
  else
  {
    Particle.publish("info", "Warning: No BME sensor found", PRIVATE);
  }

  Particle.function("initialize", initialize);

  EEPROM.get(0, config);
  //if any of these has such value, its either an config error or a new initialization
  if(config.prefHumidity == 0xFF || config.prefTemperature == 0xFF) { 
    initializePhase = true;
  }

  // Start I2C
  Wire.begin();

  // set the pin mode for the button
  pinMode(buttonPin, INPUT_PULLUP);

  // set the pin mode for the LED
  pinMode(ledPin, OUTPUT);

  Particle.variable("initializePhase", initializePhase);
}

void loop()
{

  if(initializePhase) 
  {
    displayinitializePhase();
  }

  if (!initializePhase)
  {
    buttonState = digitalRead(buttonPin);
  }

  double temperature = bme.readTemperature();
  double humidity = bme.readHumidity();

  String toSend = String(temperature) + ";" + String(humidity);

  Particle.publish("data", toSend, PRIVATE);

  delay(1000);
}

void displayinitializePhase()
{
  digitalWrite(D7, (millis() >> 3) & 0x88); // >> 3 for speed / & 0x88 for pattern
}

int initialize(String values) {
  //TODO INPUT VALIDATION!!!!!!
  config.prefTemperature = values.substring(0, values.indexOf(";")).toInt();
  config.prefHumidity = values.substring(values.indexOf(";")+1).toInt();
  EEPROM.put(0, config);
  initializePhase = false;
  digitalWrite(D7, LOW); //turn the LED off
  return 0;
}

can someone tell me whats wrong? do i have to somehow configure that sensor? or do i need some kind of calibration?

now its getting strange… i let the device run a couple of minutes and now it seems to send correct values.

edit:
i breathed at it and now its getting crazy again ;D
the temperature was rising, humidity too, now it dropped to -142°C and 0% humidity ?!

edit #2: after a restart, it reports now nearly correct values. its reporting 24°C which would be pretty warm. thats wrong, i guess in my room its about 19-20°C (a bit cold…). can someone tell me if i have to calibrate that somehow? just adjust the value -4°C? wondering if the humidity is still correct when the sensor measures the wrong temperature?

Sorry, I do not have the sensor you are testing but I remember a thread dealing with it. Perhaps you need to look at the pull-ups affecting your I2C sensor. In the link below, @RWB pointed out the following:

The Argon has 13K pull ups built in on the I2C pins.

You might check out this thread:

https://community.particle.io/t/bme280-temp-sensor-predictable-error-in-reading/57498/39

It may just be a faulty one. I bought two a few weeks ago. One worked perfectly, the other (when swapped into the same circuit) was very erratic. In the end I give up on it and ordered another.

I have used them in a few projects and they are usually pretty reliable.