You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

54 lines
1.4 KiB

7 years ago
#include "BME280.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
BME280::BME280() {}
bool BME280::begin(void) {
// SPI.begin(BME_SCK, BME_MISO, BME_MOSI, BME_CS);
pinMode(18, OUTPUT);
digitalWrite(18, HIGH); // disable LoRa_CS
7 years ago
pinMode(23, OUTPUT);
digitalWrite(23, HIGH); // enable bme280 CS
7 years ago
delay(50);
bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
7 years ago
int retries = 0;
7 years ago
while (!(status = bme->begin())) {
7 years ago
if (retries > 5) break;
retries++;
7 years ago
Serial.println("Could not find a valid BME280 sensor, check wiring!");
7 years ago
// bme->reset();
7 years ago
delay(500);
}
7 years ago
if (!status) return false;
7 years ago
return true;
}
void BME280::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();
}
float BME280::readTemperature(void) { return bme->readTemperature(); }
float BME280::readPressure(void) { return bme->readPressure() / 100.0F; }
float BME280::readHumidity(void) { return bme->readHumidity(); }