• Skip to main content
  • Skip to primary sidebar

RNTLab.com

The Ultimate Shortcut to Learn Electronics and Programming with Open Source Hardware and Software

  • Courses
  • Forum
    • Forum
    • Ask Question
  • Shop
  • Account
  • Blog
  • Login

BME280 and BMP280

Q&A Forum › Category: Home Automation › BME280 and BMP280
1 Vote Up Vote Down
Andreas M asked 3 years ago

Hello Rui,

thanks for your great examples.  I would like to give something in return:

You might have bought a BMP280.  So, the code just works fine this way:  #include <Adafruit_BMP280.h>  and // BMP280 sensor
Adafruit_BMP280 bmp; // I2C

/*
Rui Santos
Complete project details at our blog: https://RandomNerdTutorials.com/esp32-data-logging-firebase-realtime-database/
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files.
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
*/

#include <Arduino.h>
#include <WiFi.h>
#include <Firebase_ESP_Client.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
#include “time.h”

// Provide the token generation process info.
#include “addons/TokenHelper.h”
// Provide the RTDB payload printing info and other helper functions.
#include “addons/RTDBHelper.h”

// Insert your network credentials

// Insert Firebase project API Key

// Insert Authorized Email and Corresponding Password

// Insert RTDB URLefine the RTDB URL

// Define Firebase objects
FirebaseData fbdo;
FirebaseAuth auth;
FirebaseConfig config;

// Variable to save USER UID
String uid;

// Database main path (to be updated in setup with the user UID)
String databasePath;
// Database child nodes
String tempPath = “/temperature”;
//String humPath = “/humidity”;
String presPath = “/pressure”;
String timePath = “/timestamp”;

// Parent Node (to be updated in every loop)
String parentPath;

int timestamp;
FirebaseJson json;

const char* ntpServer = “pool.ntp.org”;

// BMP280 sensor
Adafruit_BMP280 bmp; // I2C
float temperature;
//float humidity;
float pressure;

// Timer variables (send new readings every three minutes)
unsigned long sendDataPrevMillis = 0;
unsigned long timerDelay = 180000;

// Initialize BMP280
void initBMP(){
if (!bmp.begin(0x76)) {
Serial.println(“Could not find a valid BMp280 sensor, check wiring!”);
while (1);
}
}

// Initialize WiFi
void initWiFi() {
WiFi.begin(WIFI_SSID, WIFI_PASSWORD);
Serial.print(“Connecting to WiFi ..”);
while (WiFi.status() != WL_CONNECTED) {
Serial.print(‘.’);
delay(1000);
}
Serial.println(WiFi.localIP());
Serial.println();
}

// Function that gets current epoch time
unsigned long getTime() {
time_t now;
struct tm timeinfo;
if (!getLocalTime(&timeinfo)) {
//Serial.println(“Failed to obtain time”);
return(0);
}
time(&now);
return now;
}

void setup(){
Serial.begin(115200);

// Initialize p280 sensor
initBMP();
initWiFi();
configTime(0, 0, ntpServer);

// Assign the api key (required)
config.api_key = API_KEY;

// Assign the user sign in credentials
auth.user.email = USER_EMAIL;
auth.user.password = USER_PASSWORD;

// Assign the RTDB URL (required)
config.database_url = DATABASE_URL;

Firebase.reconnectWiFi(true);
fbdo.setResponseSize(4096);

// Assign the callback function for the long running token generation task */
config.token_status_callback = tokenStatusCallback; //see addons/TokenHelper.h

// Assign the maximum retry of token generation
config.max_token_generation_retry = 5;

// Initialize the library with the Firebase authen and config
Firebase.begin(&config, &auth);

// Getting the user UID might take a few seconds
Serial.println(“Getting User UID”);
while ((auth.token.uid) == “”) {
Serial.print(‘.’);
delay(1000);
}
// Print user UID
uid = auth.token.uid.c_str();
Serial.print(“User UID: “);
Serial.println(uid);

// Update database path
databasePath = “/UsersData/” + uid + “/readings”;
}

void loop(){

// Send new readings to database
if (Firebase.ready() && (millis() – sendDataPrevMillis > timerDelay || sendDataPrevMillis == 0)){
sendDataPrevMillis = millis();

//Get current timestamp
timestamp = getTime();
Serial.print (“time: “);
Serial.println (timestamp);

parentPath= databasePath + “/” + String(timestamp);

json.set(tempPath.c_str(), String(bmp.readTemperature()));
//json.set(humPath.c_str(), String(bme.readHumidity()));
json.set(presPath.c_str(), String(bmp.readPressure()/100.0F));
json.set(timePath, String(timestamp));
Serial.printf(“Set json… %s\n”, Firebase.RTDB.setJSON(&fbdo, parentPath.c_str(), &json) ? “ok” : fbdo.errorReason().c_str());
}
}

Question Tags: https://randomnerdtutorials.com/solved-could-not-find-a-valid-bme280-sensor/#more-108681
1 Answers
0 Vote Up Vote Down
Sara Santos Staff answered 3 years ago

Thank you for sharing.
Many people have BMP280 instead of BME280. This will be helpful. Thanks for sharing.
Regards,
Sara

Primary Sidebar

Login to Ask or Answer Questions

This Forum is private and it’s only available for members enrolled in our Courses.

Login »

Latest Course Updates

  • [eBook Updated] Learn Raspberry Pi Pico/Pico W with MicroPython eBook – Version 1.2 May 26, 2025
  • [New Edition] Build ESP32-CAM Projects eBook – 2nd Edition April 16, 2025

You must be logged in to view this content.

Contact Support - Refunds - Privacy - Terms - MakerAdvisor.com - Member Login

Copyright © 2013-2025 · RandomNerdTutorials.com · All Rights Reserved

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.