BME280 Combined humidity and pressure sensor library with SPI interface
Dependents: BME280_SPI_Hello TYBLE16_simple_data_logger mpl115a2_display_local GS_final
Fork of BME280 by
BME280_SPI.h
00001 /** 00002 ****************************************************************************** 00003 * @file BME280_SPI.h 00004 * @author Toyomasa Watarai 00005 * @version V1.0.0 00006 * @date 11 March 2017 00007 * @brief This file contains the class of a BME280 Combined humidity and pressure sensor library with SPI interface 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * Licensed under the Apache License, Version 2.0 (the "License"); 00012 * you may not use this file except in compliance with the License. 00013 * You may obtain a copy of the License at 00014 * 00015 * http://www.apache.org/licenses/LICENSE-2.0 00016 * 00017 * Unless required by applicable law or agreed to in writing, software 00018 * distributed under the License is distributed on an "AS IS" BASIS, 00019 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00020 * See the License for the specific language governing permissions and 00021 * limitations under the License. 00022 */ 00023 00024 /** 00025 * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science 00026 * https://www.switch-science.com/catalog/2236/ 00027 * 00028 * For more information about the BME280: 00029 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf 00030 */ 00031 00032 #ifndef MBED_BME280_SPI_H 00033 #define MBED_BME280_SPI_H 00034 00035 #include "mbed.h" 00036 00037 #ifdef _DEBUG 00038 extern Serial pc; 00039 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) 00040 #else 00041 #define DEBUG_PRINT(...) 00042 #endif 00043 00044 /** Interface for controlling BME280 Combined humidity and pressure sensor 00045 * 00046 * @code 00047 * #include "mbed.h" 00048 * #include "BME280_SPI.h" 00049 * 00050 * Serial pc(USBTX, USBRX); 00051 * BME280_SPI sensor(D11, D12, D13, D9); // mosi, miso, sclk, cs 00052 * 00053 * int main() { 00054 * 00055 * while(1) { 00056 * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity()); 00057 * wait(1); 00058 * } 00059 * } 00060 * 00061 * @endcode 00062 */ 00063 00064 /** BME280_SPI class 00065 * 00066 * BME280_SPI: A library to correct environmental data using Boshe BME280 environmental sensor device 00067 * 00068 */ 00069 class BME280_SPI 00070 { 00071 public: 00072 00073 enum spi_mask { 00074 BME280_SPI_MASK = 0x7F 00075 }; 00076 00077 /** Create a BME280 instance 00078 * which is connected to specified SPI pins 00079 * 00080 * @param mosi SPI MOSI pin 00081 * @param miso SPI MISO pin 00082 * @param sclk SPI SCLK pin 00083 * @param cs device CS pin 00084 */ 00085 BME280_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs); 00086 00087 /** Destructor of BME280_SPI 00088 */ 00089 virtual ~BME280_SPI(); 00090 00091 /** Initializa BME280 sensor 00092 * 00093 * Configure sensor setting and read parameters for calibration 00094 * 00095 */ 00096 void initialize(void); 00097 00098 /** Read the current temperature value (degree Celsius) from BME280 sensor 00099 * 00100 * @return Temperature value (degree Celsius) 00101 */ 00102 float getTemperature(void); 00103 00104 /** Read the current pressure value (hectopascal) from BME280 sensor 00105 * 00106 * @return Pressure value (hectopascal) 00107 */ 00108 float getPressure(void); 00109 00110 /** Read the current humidity value (humidity %) from BME280 sensor 00111 * 00112 * @return Humidity value (humidity %) 00113 */ 00114 float getHumidity(void); 00115 00116 private: 00117 00118 SPI _spi; 00119 DigitalOut _cs; 00120 uint16_t dig_T1; 00121 int16_t dig_T2, dig_T3; 00122 uint16_t dig_P1; 00123 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9; 00124 uint16_t dig_H1, dig_H3; 00125 int16_t dig_H2, dig_H4, dig_H5, dig_H6; 00126 int32_t t_fine; 00127 00128 }; 00129 00130 #endif // MBED_BME280_SPI_H
Generated on Tue Jul 12 2022 22:08:35 by 1.7.2