As part of a bigger project to measure temperature and humidity I’ve set up the NodeMcu ESP8266 (ESP12E) with a GY BME280 as below. I’m using ‘Software’ SPI which means I assign the pins used for the SPI bus in the code rather than use the standard SPI pins on the NodeMcu.
The code is below. You might need to install the two Adafruit libraries. The Sensor one can be difficult to find in the Arduino libraries – search unified abstraction and it should show at the top.
#include <Wire.h> #include <SPI.h> #include <Adafruit_Sensor.h> #include <Adafruit_BME280.h> // assign the ESP8266 pins to arduino pins #define D1 5 #define D2 4 #define D4 2 #define D3 0 // assign the SPI bus to pins #define BME_SCK D1 #define BME_MISO D4 #define BME_MOSI D2 #define BME_CS D3 #define SEALEVELPRESSURE_HPA (1013.25) Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI unsigned long delayTime; void setup() { Serial.begin(9600); Serial.println(F("BME280 test")); bool status; // default settings status = bme.begin(); if (!status) { Serial.println("Could not find a valid BME280 sensor, check wiring!"); while (1); } Serial.println("-- Default Test --"); delayTime = 1000; Serial.println(); } void loop() { printValues(); delay(delayTime); } void printValues() { Serial.print("Temperature = "); Serial.print(bme.readTemperature()); Serial.println(" *C"); Serial.print("Pressure = "); Serial.print(bme.readPressure() / 100.0F); Serial.println(" hPa"); Serial.print("Approx. Altitude = "); Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA)); Serial.println(" m"); Serial.print("Humidity = "); Serial.print(bme.readHumidity()); Serial.println(" %"); Serial.println(); }
These are the actual items I used but you can find the same on many other sites.
ESP8266 – http://www.ebay.es/itm/201838061951
BME280 – http://www.ebay.es/itm/112471267075
Buy Me A Coffee
If you found something useful above please say thanks by buying me a coffee here...
I get Could not find a valid BME280 sensor, check wiring!
I get the error too…
Is it possible that the code is pointing at the wrong wires?
// assign the ESP8266 pins to arduino pins
#define D1 5
#define D2 4
#define D4 2
#define D5 14
Thanks
The schematics show D1 to D4 connections but in the code the mapping is for D1, D2, D4, D5. Messy 🙁
Arg! I must have made a mistake when I copied this Sketch from my other computer or something as the pin definitions weren’t correct.
I’ve fixed the code. Sorry for the wasted time.
How do I add this code to existing code for ubidots?
Does this help? – https://help.ubidots.com/connect-your-devices/connect-a-nodemcu-esp8266-to-ubidots-over-http
If someone buys me lots of coffee I can write an article on how to combine the two.
No already got that far, brain function severely diminished ie. older than dirt
I am getting the same issue – “find a valid BME280 sensor, check wiring!”
Wiring is the same as per the image
Error Stack:
Hi, Which 8266 board are you using?