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?