Test BME and TLC59711 BLE Nano 1.5

Fork of BME280_SPI by Toyomasa Watarai

Committer:
MACRUM
Date:
Sun Mar 12 03:02:05 2017 +0000
Revision:
6:b91c721722d2
Parent:
BME280.h@5:c1f1647004c4
Child:
7:dfd6107f1f92
SPI version prototyping

Who changed what in which revision?

UserRevisionLine numberNew 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 5:c1f1647004c4 11 * Permission is hereby granted, free of charge, to any person obtaining a copy
MACRUM 5:c1f1647004c4 12 * of this software and associated documentation files (the "Software"), to deal
MACRUM 5:c1f1647004c4 13 * in the Software without restriction, including without limitation the rights
MACRUM 5:c1f1647004c4 14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
MACRUM 5:c1f1647004c4 15 * copies of the Software, and to permit persons to whom the Software is
MACRUM 5:c1f1647004c4 16 * furnished to do so, subject to the following conditions:
MACRUM 5:c1f1647004c4 17 *
MACRUM 5:c1f1647004c4 18 * The above copyright notice and this permission notice shall be included in
MACRUM 5:c1f1647004c4 19 * all copies or substantial portions of the Software.
MACRUM 1:763a4018aaec 20 *
MACRUM 5:c1f1647004c4 21 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
MACRUM 5:c1f1647004c4 22 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
MACRUM 5:c1f1647004c4 23 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
MACRUM 5:c1f1647004c4 24 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
MACRUM 5:c1f1647004c4 25 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
MACRUM 5:c1f1647004c4 26 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
MACRUM 5:c1f1647004c4 27 * THE SOFTWARE.
MACRUM 5:c1f1647004c4 28 */
MACRUM 6:b91c721722d2 29
MACRUM 5:c1f1647004c4 30 /**
MACRUM 1:763a4018aaec 31 * Library for "BME280 temperature, humidity and pressure sensor module" from Switch Science
MACRUM 1:763a4018aaec 32 * https://www.switch-science.com/catalog/2236/
MACRUM 1:763a4018aaec 33 *
MACRUM 1:763a4018aaec 34 * For more information about the BME280:
MACRUM 6:b91c721722d2 35 * https://ae-bst.resource.bosch.com/media/_tech/media/datasheets/BST-BME280_DS001-11.pdf
MACRUM 6:b91c721722d2 36 */
MACRUM 6:b91c721722d2 37
MACRUM 6:b91c721722d2 38 #ifndef MBED_BME280_SPI_H
MACRUM 6:b91c721722d2 39 #define MBED_BME280_SPI_H
MACRUM 0:ade9be832910 40
MACRUM 0:ade9be832910 41 #include "mbed.h"
MACRUM 0:ade9be832910 42
MACRUM 0:ade9be832910 43 #ifdef _DEBUG
MACRUM 0:ade9be832910 44 extern Serial pc;
MACRUM 0:ade9be832910 45 #define DEBUG_PRINT(...) pc.printf(__VA_ARGS__)
MACRUM 0:ade9be832910 46 #else
MACRUM 0:ade9be832910 47 #define DEBUG_PRINT(...)
MACRUM 0:ade9be832910 48 #endif
MACRUM 0:ade9be832910 49
MACRUM 5:c1f1647004c4 50 /** Interface for controlling BME280 Combined humidity and pressure sensor
MACRUM 5:c1f1647004c4 51 *
MACRUM 5:c1f1647004c4 52 * @code
MACRUM 5:c1f1647004c4 53 * #include "mbed.h"
MACRUM 6:b91c721722d2 54 * #include "BME280_SPI.h"
MACRUM 6:b91c721722d2 55 *
MACRUM 5:c1f1647004c4 56 * Serial pc(USBTX, USBRX);
MACRUM 6:b91c721722d2 57 * BME280_SPI sensor(D11, D12, D13, D9); // mosi, miso, sclk, cs
MACRUM 6:b91c721722d2 58 *
MACRUM 5:c1f1647004c4 59 * int main() {
MACRUM 6:b91c721722d2 60 *
MACRUM 5:c1f1647004c4 61 * while(1) {
MACRUM 5:c1f1647004c4 62 * pc.printf("%2.2f degC, %04.2f hPa, %2.2f %%\n", sensor.getTemperature(), sensor.getPressure(), sensor.getHumidity());
MACRUM 5:c1f1647004c4 63 * wait(1);
MACRUM 5:c1f1647004c4 64 * }
MACRUM 5:c1f1647004c4 65 * }
MACRUM 6:b91c721722d2 66 *
MACRUM 5:c1f1647004c4 67 * @endcode
MACRUM 5:c1f1647004c4 68 */
MACRUM 5:c1f1647004c4 69
MACRUM 6:b91c721722d2 70 /** BME280_SPI class
MACRUM 0:ade9be832910 71 *
MACRUM 6:b91c721722d2 72 * BME280_SPI: A library to correct environmental data using Boshe BME280 environmental sensor device
MACRUM 0:ade9be832910 73 *
MACRUM 6:b91c721722d2 74 */
MACRUM 6:b91c721722d2 75 class BME280_SPI
MACRUM 0:ade9be832910 76 {
MACRUM 0:ade9be832910 77 public:
MACRUM 0:ade9be832910 78
MACRUM 0:ade9be832910 79 /** Create a BME280 instance
MACRUM 6:b91c721722d2 80 * which is connected to specified SPI pins
MACRUM 0:ade9be832910 81 *
MACRUM 6:b91c721722d2 82 * @param mosi SPI MOSI pin
MACRUM 6:b91c721722d2 83 * @param miso SPI MISO pin
MACRUM 6:b91c721722d2 84 * @param sclk SPI SCLK pin
MACRUM 6:b91c721722d2 85 * @param cs device CS pin
MACRUM 0:ade9be832910 86 */
MACRUM 6:b91c721722d2 87 BME280_SPI(PinName mosi, PinName miso, PinName sclk, PinName cs);
MACRUM 0:ade9be832910 88
MACRUM 6:b91c721722d2 89 /** Destructor of BME280_SPI
MACRUM 0:ade9be832910 90 */
MACRUM 6:b91c721722d2 91 virtual ~BME280_SPI();
MACRUM 0:ade9be832910 92
MACRUM 0:ade9be832910 93 /** Initializa BME280 sensor
MACRUM 0:ade9be832910 94 *
MACRUM 0:ade9be832910 95 * Configure sensor setting and read parameters for calibration
MACRUM 0:ade9be832910 96 *
MACRUM 0:ade9be832910 97 */
MACRUM 0:ade9be832910 98 void initialize(void);
MACRUM 0:ade9be832910 99
MACRUM 0:ade9be832910 100 /** Read the current temperature value (degree Celsius) from BME280 sensor
MACRUM 0:ade9be832910 101 *
MACRUM 0:ade9be832910 102 */
MACRUM 0:ade9be832910 103 float getTemperature(void);
MACRUM 0:ade9be832910 104
MACRUM 6:b91c721722d2 105 /** Read the current pressure value (hectopascal) from BME280 sensor
MACRUM 0:ade9be832910 106 *
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 0:ade9be832910 112 */
MACRUM 0:ade9be832910 113 float getHumidity(void);
MACRUM 0:ade9be832910 114
MACRUM 0:ade9be832910 115 private:
MACRUM 0:ade9be832910 116
MACRUM 6:b91c721722d2 117 SPI _spi;
MACRUM 6:b91c721722d2 118 DigitalOut _cs;
MACRUM 0:ade9be832910 119 uint16_t dig_T1;
MACRUM 0:ade9be832910 120 int16_t dig_T2, dig_T3;
MACRUM 0:ade9be832910 121 uint16_t dig_P1;
MACRUM 0:ade9be832910 122 int16_t dig_P2, dig_P3, dig_P4, dig_P5, dig_P6, dig_P7, dig_P8, dig_P9;
MACRUM 0:ade9be832910 123 uint16_t dig_H1, dig_H3;
MACRUM 0:ade9be832910 124 int16_t dig_H2, dig_H4, dig_H5, dig_H6;
MACRUM 0:ade9be832910 125 int32_t t_fine;
MACRUM 0:ade9be832910 126
MACRUM 0:ade9be832910 127 };
MACRUM 0:ade9be832910 128
MACRUM 6:b91c721722d2 129 #endif // MBED_BME280_SPI_H