esp32_Adafruit_BME280_Library/examples/bme280test/bme280test.ino

83 lines
2.1 KiB
Arduino
Raw Normal View History

2015-07-24 21:44:43 +01:00
/***************************************************************************
This is a library for the BME280 humidity, temperature & pressure sensor
2015-09-01 06:23:33 +01:00
Designed specifically to work with the Adafruit BME280 Breakout
2015-07-24 21:44:43 +01:00
----> http://www.adafruit.com/products/2650
2015-09-01 06:23:33 +01:00
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.
2015-07-24 21:44:43 +01:00
Adafruit invests time and resources providing this open source code,
please support Adafruit andopen-source hardware by purchasing products
from Adafruit!
2015-09-01 06:23:33 +01:00
Written by Limor Fried & Kevin Townsend for Adafruit Industries.
2015-07-24 21:44:43 +01:00
BSD license, all text above must be included in any redistribution
***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define BME_SCK 13
#define BME_MISO 12
2015-09-01 06:23:33 +01:00
#define BME_MOSI 11
2015-07-24 21:44:43 +01:00
#define BME_CS 10
2015-09-01 06:23:33 +01:00
#define SEALEVELPRESSURE_HPA (1013.25)
2015-07-24 21:44:43 +01:00
Adafruit_BME280 bme; // I2C
//Adafruit_BME280 bme(BME_CS); // hardware SPI
//Adafruit_BME280 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
2015-09-01 06:23:33 +01:00
unsigned long delayTime;
2015-09-01 06:23:33 +01:00
void setup() {
Serial.begin(9600);
Serial.println(F("BME280 test"));
bool status;
// default settings
2017-09-12 11:29:13 +01:00
status = bme.begin(&Wire1);
if (!status) {
Serial.println("Could not find a valid BME280 sensor, check wiring!");
while (1);
}
2017-02-06 23:52:37 +00:00
Serial.println("-- Default Test --");
delayTime = 1000;
Serial.println();
delay(100); // let sensor boot up
2015-07-24 21:44:43 +01:00
}
2015-09-01 06:23:33 +01:00
2017-02-06 23:52:37 +00:00
void loop() {
printValues();
delay(delayTime);
}
void printValues() {
2015-07-24 21:44:43 +01:00
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
2015-09-01 06:23:33 +01:00
2015-07-24 21:44:43 +01:00
Serial.print("Pressure = ");
2015-09-14 06:10:52 +01:00
2015-08-31 22:48:55 +01:00
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
2015-09-01 06:23:33 +01:00
Serial.print("Approx. Altitude = ");
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(" m");
2015-07-24 21:44:43 +01:00
Serial.print("Humidity = ");
Serial.print(bme.readHumidity());
Serial.println(" %");
2015-09-01 06:23:33 +01:00
2015-07-24 21:44:43 +01:00
Serial.println();
2017-02-06 23:52:37 +00:00
}