Hendrik Langer
7 years ago
5 changed files with 161 additions and 16 deletions
@ -0,0 +1,46 @@ |
|||
#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
|
|||
delay(50); |
|||
bme = new Adafruit_BME280(BME_CS, BME_MOSI, BME_MISO, BME_SCK); // software SPI
|
|||
while (!(status = bme->begin())) { |
|||
Serial.println("Could not find a valid BME280 sensor, check wiring!"); |
|||
delay(500); |
|||
} |
|||
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(); } |
@ -0,0 +1,30 @@ |
|||
#ifndef _BME280_H |
|||
#define _BME280_H |
|||
|
|||
#include <Arduino.h> |
|||
#include <Wire.h> |
|||
#include <SPI.h> |
|||
#include <Adafruit_Sensor.h> |
|||
#include <Adafruit_BME280.h> |
|||
|
|||
static constexpr uint8_t BME_SCK = 5; // SCL/SCK
|
|||
static constexpr int BME_MISO = 19; //SDO
|
|||
static constexpr int BME_MOSI = 27; //SDA/SDI
|
|||
static constexpr int BME_CS = 23; // CS
|
|||
|
|||
#define SEALEVELPRESSURE_HPA (1013.25) |
|||
|
|||
class BME280 { |
|||
public: |
|||
BME280(); |
|||
bool begin(void); |
|||
void printValues(void); |
|||
float readTemperature(void); |
|||
float readPressure(void); |
|||
float readHumidity(void); |
|||
private: |
|||
Adafruit_BME280 *bme; |
|||
bool status; |
|||
}; |
|||
|
|||
#endif /* _BME280_H */ |
Loading…
Reference in new issue