Who are conflicting here? BMP280 not reading

Hi

The code is my weather station to which I added the BMP280 and code to read barometic pressure. The whole thing runs on a NodeMCU and wiring, pins and code work in another setup I used for testing the BMP. Fine readings. Added to the weather station code, the BMP reads 0.00 all the time. Frustrating as I know it's good. I figure it's conflicting with something else but i can't work out what. Constructive help will be much appreciated.

#include <DHT.h>
#include <ESP8266WiFi.h>
#include <Button.h> #include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

int ventetidSekunder = 120;
 
const char* ssid = 
const char* password = 
const char* server = 
String apiKey = 

/* pins til BMP280
 *  GND til GND
 *  VCC, CSB og SDO alle til 3.3v
 *  SCL til D1 
 *  SDA til D2
 */

#define DHTPIN 0        // D3 på NodeMCU
#define NULSTIL_PIN 2   // D4 på NodeMCU
#define MAALER_PIN 14   // D5 på NodeMCU   
#define PULLUP true        
#define INVERT true
#define DEBOUNCE_MS 0  
int lysPin = A0;        // A0 på NodeMCU

int lysStyrke = 0;
int tip = 0;   
int lufttryk = 0;
float dagMaksTemp = 0;
float dagMinTemp = 0;
float fugt = 0;
float millimeter = 0; 
unsigned long time_now = 0;

Button maaler(MAALER_PIN, PULLUP, INVERT, DEBOUNCE_MS); 
Button nulstil(NULSTIL_PIN, PULLUP, INVERT, DEBOUNCE_MS); 
 
DHT dht(DHTPIN, DHT22, 40);
Adafruit_BMP280 bme;

WiFiClient client;

void setup() {      
  Serial.begin(9600);          
  dht.begin();
  WiFi.begin(ssid, password);
  float f = dht.readTemperature(true);
  float t = (((f-32)*5)/9);
  dagMaksTemp = t;
  dagMinTemp = dagMaksTemp;
}
 
void loop() {
if(millis() > time_now + ventetidSekunder * 1000){
        time_now = millis();
  lysStyrke = analogRead(lysPin); 
//  lufttryk = (bme.readPressure() / 100);
  delay(15);  
  float fugt = dht.readHumidity();
  while (fugt > 111 ) {
    float fugt = dht.readHumidity();
    delay(15); 
    }
  delay(15);  
  float f = dht.readTemperature(true);
  float t = (((f-32)*5)/9);
  delay(15);  
  if (t > dagMaksTemp) dagMaksTemp = t;
  if (t < dagMinTemp) dagMinTemp = t;
    Serial.print("Temperatur = ");
    Serial.print(t);
    Serial.print("  Luftfugtighed = ");
    Serial.print(fugt);
    Serial.print("  Lysstyrke = ");
    Serial.print(lysStyrke);
    Serial.print("  Lufttryk = ");
    Serial.print(bme.readPressure() / 100);
  if (client.connect(server,80)) {  
    String postStr = apiKey;
           postStr +="&field1=";
           postStr += String((float)t);
           postStr +="&field2=";
           postStr += String((int)fugt);
           postStr +="&field3=";
           postStr += String((int)lysStyrke);
           postStr +="&field4=";
           postStr += String((float)millimeter,1);
           postStr +="&field5=";
           postStr += String((float)dagMaksTemp,1);
           postStr +="&field6=";
           postStr += String((float)dagMinTemp,1);
//           postStr +="&field7=";
//           postStr += String((int)lufttryk,1);
     client.print("POST /update HTTP/1.1\n"); 
     client.print("Host: api.thingspeak.com\n"); 
     client.print("Connection: close\n"); 
     client.print("X-THINGSPEAKAPIKEY: "+apiKey+"\n"); 
     client.print("Content-Type: application/x-www-form-urlencoded\n"); 
     client.print("Content-Length: "); 
     client.print(postStr.length()); 
     client.print("\n\n"); 
     client.print(postStr);
  }
  client.stop();
   }
   
maaler.read();                   
if (maaler.wasPressed()) {     
  tip++; 
  delay(20);
  }
millimeter = tip * 0.315;

nulstil.read();                   
if (nulstil.wasPressed()) {     
  tip = 0; 
  float f = dht.readTemperature(true);
  float t = (((f-32)*5)/9);
  dagMaksTemp = t;
  dagMinTemp = dagMaksTemp;
  }   
}

Your not doing a bme.begin() and you have commented out the code that reads the bme.pressure().

From the bmp280test example:

Adafruit_BMP280 bme; // I2C
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK);

Your constructor:

Adafruit_BMP280 bme;

You have the constructor for I2C. I think that you need to include the Wire library if you use I2C or use the right constructor for SPI. See the example.

Riva:
Your not doing a bme.begin() and you have commented out the code that reads the bme.pressure().

Thanks for you reply. I do an Adafruit_BMP280 bme; which to my understanding starts it.
I read twice. Once for ThingSpeak which is quoted out but the other one for serialprint(testing) remains.

groundFungus:
You have the constructor for I2C. I think that you need to include the Wire library if you use I2C or use the right constructor for SPI. See the example.

Thanks for your reply.
I have the wire.h but somehow I deleted a break which brought it up to line 3 instead of it's own line 4.
Bringing it back changes nothing sadly.

I read a bit about the BMP option and I would have to un-solder some wires. I hard wired the stuff as the code below worked for testing.... meaning the I2C

So would anything make I2C work?

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

// using I2C
Adafruit_BMP280 bme;

  
void setup()
{
  Serial.begin(9600);
  if (!bme.begin())
  {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}
  
void loop()
{
    Serial.print("---- GY BMP 280 ----------------\n");
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100); // 100 Pa = 1 millibar
    Serial.println(" mb");
    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25));
    Serial.println(" m");
    Serial.print("--------------------------------\n\n");
    delay(2000);
}

chrven:
Thanks for you reply. I do an Adafruit_BMP280 bme; which to my understanding starts it.
I read twice. Once for ThingSpeak which is quoted out but the other one for serialprint(testing) remains.

The examples supplied with the Adafruit library show otherwise. Both have the bme.begin() in setup.
My mistake on the reading of the bme.pressure(), I missed the second entry in the print statement.

Assuming your using I2C and not SPI to connect to the BMP280 then have you wired it correctly and is it on the default I2C address that the Adafruit library expects it? You can change the library default address if it is different.

  bool status = bme.begin(BME280_I2C_ADDR);
  if (!status) {
    Serial.println(F("Could not find BME280 sensor, check wiring!"));
    while (1);
  }

Riva:
The examples supplied with the Adafruit library show otherwise. Both have the bme.begin() in setup.

Tank you for another reply! :slight_smile:
I found it in a working setup. The one below IS working and outputs real values.

#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>

// using I2C
Adafruit_BMP280 bme;

  
void setup()
{
  Serial.begin(9600);
  if (!bme.begin())
  {  
    Serial.println("Could not find a valid BMP280 sensor, check wiring!");
    while (1);
  }
}
  
void loop()
{
    Serial.print("---- GY BMP 280 ----------------\n");
    Serial.print("Temperature = ");
    Serial.print(bme.readTemperature());
    Serial.println(" *C");
    Serial.print("Pressure = ");
    Serial.print(bme.readPressure() / 100); // 100 Pa = 1 millibar
    Serial.println(" mb");
    Serial.print("Approx altitude = ");
    Serial.print(bme.readAltitude(1013.25));
    Serial.println(" m");
    Serial.print("--------------------------------\n\n");
    delay(2000);
}