Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /***************************************************************************
- This is a library for the BME280 humidity, temperature & pressure sensor
- Designed specifically to work with the Adafruit BME280 Breakout
- ----> http://www.adafruit.com/products/2650
- These sensors use I2C or SPI to communicate, 2 or 4 pins are required
- to interface. The device's I2C address is either 0x76 or 0x77.
- Adafruit invests time and resources providing this open source code,
- please support Adafruit andopen-source hardware by purchasing products
- from Adafruit!
- Written by Limor Fried & Kevin Townsend for Adafruit Industries.
- BSD license, all text above must be included in any redistribution
- ***************************************************************************/
- #include <Wire.h>
- #include <ESP8266WiFi.h>
- #include <SPI.h>
- #include <Adafruit_Sensor.h>
- #include <Adafruit_BME280.h>
- #define SEALEVELPRESSURE_HPA (1013.25)
- Adafruit_BME280 bme; // I2C
- unsigned long delayTime;
- void setup() {
- Serial.begin(9600);
- Serial.println(F("BME280 test"));
- WiFi.mode(WIFI_STA);
- Wire.begin(0, 2);
- 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");
- if(isnan(bme.readTemperature())){
- Serial.println("Failed to read data from BME280 sensor!");
- }
- 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();
- }
Advertisement
Add Comment
Please, Sign In to add comment