Test BME and TLC59711 BLE Nano 1.5
Fork of BME280_SPI by
BME280_SPI.h@9:01d4e22a7012, 2018-04-13 (annotated)
- Committer:
- elitesnipezz360
- Date:
- Fri Apr 13 13:39:13 2018 +0000
- Revision:
- 9:01d4e22a7012
- Parent:
- 7:dfd6107f1f92
initial
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
MACRUM | 1:763a4018aaec | 1 | /** |
MACRUM | 5:c1f1647004c4 | 2 | ****************************************************************************** |
MACRUM | 6:b91c721722d2 | 3 | * @file BME280_SPI.h |
MACRUM | 5:c1f1647004c4 | 4 | * @author Toyomasa Watarai |
MACRUM | 5:c1f1647004c4 | 5 | * @version V1.0.0 |
MACRUM | 5:c1f1647004c4 | 6 | * @date 11 March 2017 |
MACRUM | 6:b91c721722d2 | 7 | * @brief This file contains the class of a BME280 Combined humidity and pressure sensor library with SPI interface |
MACRUM | 5:c1f1647004c4 | 8 | ****************************************************************************** |
MACRUM | 5:c1f1647004c4 | 9 | * @attention |
MACRUM | 1:763a4018aaec | 10 | * |
MACRUM | 7:dfd6107f1f92 | 11 | * Licensed under the Apache License, Version 2.0 (the "License"); |
MACRUM | 7:dfd6107f1f92 | 12 | * you may not use this file except in compliance with the License. |
MACRUM | 7:dfd6107f1f92 | 13 | * You may obtain a copy of the License at |
MACRUM | 7:dfd6107f1f92 | 14 | * |
MACRUM | 7:dfd6107f1f92 | 15 | * http://www.apache.org/licenses/LICENSE-2.0 |
MACRUM | 5:c1f1647004c4 | 16 | * |
MACRUM | 7:dfd6107f1f92 | 17 | * Unless required by applicable law or agreed to in writing, software |
MACRUM | 7:dfd6107f1f92 | 18 | * distributed under the License is distributed on an "AS IS" BASIS, |
MACRUM | 7:dfd6107f1f92 | 19 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
MACRUM | 7:dfd6107f1f92 | 20 | * See the License for the specific language governing permissions and |
MACRUM | 7:dfd6107f1f92 | 21 | * limitations under the License. |
MACRUM | 5:c1f1647004c4 | 22 | */ |
MACRUM | 6:b91c721722d2 | 23 | |
MACRUM | 5:c1f1647004c4 | 24 | /** |
MACRUM | 1:763a4018aaec | 25 | * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science |
MACRUM | 1:763a4018aaec | 26 | * https://www.switch-science.com/catalog/2236/ |
MACRUM | 1:763a4018aaec | 27 | * |
MACRUM | 1:763a4018aaec | 28 | * For more information about the BME280: |
MACRUM | 6:b91c721722d2 | 29 | * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf |
MACRUM | 6:b91c721722d2 | 30 | */ |
MACRUM | 6:b91c721722d2 | 31 | |
MACRUM | 6:b91c721722d2 | 32 | #ifndef MBED_BME280_SPI_H |
MACRUM | 6:b91c721722d2 | 33 | #define MBED_BME280_SPI_H |
MACRUM | 0:ade9be832910 | 34 | |
MACRUM | 0:ade9be832910 | 35 | #include "mbed.h" |
MACRUM | 0:ade9be832910 | 36 | |
MACRUM | 0:ade9be832910 | 37 | #ifdef _DEBUG |
MACRUM | 0:ade9be832910 | 38 | extern Serial pc; |
MACRUM | 0:ade9be832910 | 39 | #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__) |
MACRUM | 0:ade9be832910 | 40 | #else |
MACRUM | 0:ade9be832910 | 41 | #define DEBUG_PRINT(...) |
MACRUM | 0:ade9be832910 | 42 | #endif |
MACRUM | 0:ade9be832910 | 43 | |
MACRUM | 5:c1f1647004c4 | 44 | /** Interface for controlling BME280 Combined humidity and pressure sensor |
MACRUM | 5:c1f1647004c4 | 45 | * |
MACRUM | 5:c1f1647004c4 | 46 | * @code |
MACRUM | 5:c1f1647004c4 | 47 | * #include "mbed.h" |
MACRUM | 6:b91c721722d2 | 48 | * #include "BME280_SPI.h" |
MACRUM | 6:b91c721722d2 | 49 | * |
MACRUM | 5:c1f1647004c4 | 50 | * Serial pc(USBTX, USBRX); |
MACRUM | 6:b91c721722d2 | 51 | * BME280_SPI sensor(D11, D12, D13, D9); // mosi, miso, sclk, cs |
MACRUM | 6:b91c721722d2 | 52 | * |
MACRUM | 5:c1f1647004c4 | 53 | * int main() { |
MACRUM | 6:b91c721722d2 | 54 | * |
MACRUM | 5:c1f1647004c4 | 55 | * while(1) { |
MACRUM | 5:c1f1647004c4 | 56 | * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity()); |
MACRUM | 5:c1f1647004c4 | 57 | * wait(1); |
MACRUM | 5:c1f1647004c4 | 58 | * } |
MACRUM | 5:c1f1647004c4 | 59 | * } |
MACRUM | 6:b91c721722d2 | 60 | * |
MACRUM | 5:c1f1647004c4 | 61 | * @endcode |
MACRUM | 5:c1f1647004c4 | 62 | */ |
MACRUM | 5:c1f1647004c4 | 63 | |
MACRUM | 6:b91c721722d2 | 64 | /** BME280_SPI class |
MACRUM | 0:ade9be832910 | 65 | * |
MACRUM | 6:b91c721722d2 | 66 | * BME280_SPI: A library to correct environmental data using Boshe BME280 environmental sensor device |
MACRUM | 0:ade9be832910 | 67 | * |
MACRUM | 6:b91c721722d2 | 68 | */ |
MACRUM | 6:b91c721722d2 | 69 | class BME280_SPI |
MACRUM | 0:ade9be832910 | 70 | { |
MACRUM | 0:ade9be832910 | 71 | public: |
MACRUM | 0:ade9be832910 | 72 | |
MACRUM | 7:dfd6107f1f92 | 73 | enum spi_mask { |
MACRUM | 7:dfd6107f1f92 | 74 | BME280_SPI_MASK = 0x7F |
MACRUM | 7:dfd6107f1f92 | 75 | }; |
MACRUM | 7:dfd6107f1f92 | 76 | |
MACRUM | 0:ade9be832910 | 77 | /** Create a BME280 instance |
MACRUM | 6:b91c721722d2 | 78 | * which is connected to specified SPI pins |
MACRUM | 0:ade9be832910 | 79 | * |
MACRUM | 6:b91c721722d2 | 80 | * @param mosi SPI MOSI pin |
MACRUM | 6:b91c721722d2 | 81 | * @param miso SPI MISO pin |
MACRUM | 6:b91c721722d2 | 82 | * @param sclk SPI SCLK pin |
MACRUM | 6:b91c721722d2 | 83 | * @param cs device CS pin |
MACRUM | 0:ade9be832910 | 84 | */ |
MACRUM | 6:b91c721722d2 | 85 | BME280_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs); |
MACRUM | 0:ade9be832910 | 86 | |
MACRUM | 6:b91c721722d2 | 87 | /** Destructor of BME280_SPI |
MACRUM | 0:ade9be832910 | 88 | */ |
MACRUM | 6:b91c721722d2 | 89 | virtual ~BME280_SPI(); |
MACRUM | 0:ade9be832910 | 90 | |
MACRUM | 0:ade9be832910 | 91 | /** Initializa BME280 sensor |
MACRUM | 0:ade9be832910 | 92 | * |
MACRUM | 0:ade9be832910 | 93 | * Configure sensor setting and read parameters for calibration |
MACRUM | 0:ade9be832910 | 94 | * |
MACRUM | 0:ade9be832910 | 95 | */ |
MACRUM | 0:ade9be832910 | 96 | void initialize(void); |
MACRUM | 0:ade9be832910 | 97 | |
MACRUM | 0:ade9be832910 | 98 | /** Read the current temperature value (degree Celsius) from BME280 sensor |
MACRUM | 0:ade9be832910 | 99 | * |
MACRUM | 7:dfd6107f1f92 | 100 | * @return Temperature value (degree Celsius) |
MACRUM | 0:ade9be832910 | 101 | */ |
MACRUM | 0:ade9be832910 | 102 | float getTemperature(void); |
MACRUM | 0:ade9be832910 | 103 | |
MACRUM | 6:b91c721722d2 | 104 | /** Read the current pressure value (hectopascal) from BME280 sensor |
MACRUM | 0:ade9be832910 | 105 | * |
MACRUM | 7:dfd6107f1f92 | 106 | * @return Pressure value (hectopascal) |
MACRUM | 0:ade9be832910 | 107 | */ |
MACRUM | 0:ade9be832910 | 108 | float getPressure(void); |
MACRUM | 0:ade9be832910 | 109 | |
MACRUM | 0:ade9be832910 | 110 | /** Read the current humidity value (humidity %) from BME280 sensor |
MACRUM | 0:ade9be832910 | 111 | * |
MACRUM | 7:dfd6107f1f92 | 112 | * @return Humidity value (humidity %) |
MACRUM | 0:ade9be832910 | 113 | */ |
MACRUM | 0:ade9be832910 | 114 | float getHumidity(void); |
MACRUM | 0:ade9be832910 | 115 | |
MACRUM | 0:ade9be832910 | 116 | private: |
MACRUM | 0:ade9be832910 | 117 | |
MACRUM | 6:b91c721722d2 | 118 | SPI _spi; |
MACRUM | 6:b91c721722d2 | 119 | DigitalOut _cs; |
MACRUM | 0:ade9be832910 | 120 | uint16_t dig_T1; |
MACRUM | 0:ade9be832910 | 121 | int16_t dig_T2, dig_T3; |
MACRUM | 0:ade9be832910 | 122 | uint16_t dig_P1; |
MACRUM | 0:ade9be832910 | 123 | int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9; |
MACRUM | 0:ade9be832910 | 124 | uint16_t dig_H1, dig_H3; |
MACRUM | 0:ade9be832910 | 125 | int16_t dig_H2, dig_H4, dig_H5, dig_H6; |
MACRUM | 0:ade9be832910 | 126 | int32_t t_fine; |
MACRUM | 0:ade9be832910 | 127 | |
MACRUM | 0:ade9be832910 | 128 | }; |
MACRUM | 0:ade9be832910 | 129 | |
MACRUM | 6:b91c721722d2 | 130 | #endif // MBED_BME280_SPI_H |