ロケット用プログラム

Dependencies:   mbed

Committer:
ishiyamayuto
Date:
Wed Sep 11 06:37:20 2019 +0000
Revision:
0:d58274531d38
BMP180,MPU6050

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ishiyamayuto 0:d58274531d38 1 /*
ishiyamayuto 0:d58274531d38 2 @file BMP180.h
ishiyamayuto 0:d58274531d38 3
ishiyamayuto 0:d58274531d38 4 @brief Barometric Pressure and Temperature Sensor BMP180 Breakout I2C Library
ishiyamayuto 0:d58274531d38 5
ishiyamayuto 0:d58274531d38 6 @Author spiridion (http://mailme.spiridion.net)
ishiyamayuto 0:d58274531d38 7
ishiyamayuto 0:d58274531d38 8 Tested on LPC1768 and FRDM-KL25Z
ishiyamayuto 0:d58274531d38 9
ishiyamayuto 0:d58274531d38 10 Copyright (c) 2014 spiridion
ishiyamayuto 0:d58274531d38 11 Released under the MIT License (see http://mbed.org/license/mit)
ishiyamayuto 0:d58274531d38 12
ishiyamayuto 0:d58274531d38 13 Documentation regarding the BMP180 can be found here:
ishiyamayuto 0:d58274531d38 14 http://mbed.org/media/uploads/spiridion/bst-bmp180-ds000-09.pdf
ishiyamayuto 0:d58274531d38 15 */
ishiyamayuto 0:d58274531d38 16
ishiyamayuto 0:d58274531d38 17 #ifndef BMP180_H
ishiyamayuto 0:d58274531d38 18 #define BMP180_H
ishiyamayuto 0:d58274531d38 19
ishiyamayuto 0:d58274531d38 20 #include "mbed.h"
ishiyamayuto 0:d58274531d38 21
ishiyamayuto 0:d58274531d38 22 /// default address is 0xEF
ishiyamayuto 0:d58274531d38 23 #define BMP180_I2C_ADDRESS 0xEF
ishiyamayuto 0:d58274531d38 24
ishiyamayuto 0:d58274531d38 25 // Oversampling settings
ishiyamayuto 0:d58274531d38 26 #define BMP180_OSS_ULTRA_LOW_POWER 0 // 1 sample and 4.5ms for conversion
ishiyamayuto 0:d58274531d38 27 #define BMP180_OSS_NORMAL 1 // 2 samples and 7.5ms for conversion
ishiyamayuto 0:d58274531d38 28 #define BMP180_OSS_HIGH_RESOLUTION 2 // 4 samples and 13.5ms for conversion
ishiyamayuto 0:d58274531d38 29 #define BMP180_OSS_ULTRA_HIGH_RESOLUTION 3 // 8 samples and 25.5ms for conversion
ishiyamayuto 0:d58274531d38 30
ishiyamayuto 0:d58274531d38 31 #define UNSET_BMP180_PRESSURE_VALUE 0.F
ishiyamayuto 0:d58274531d38 32 #define UNSET_BMP180_TEMPERATURE_VALUE -273.15F // absolute zero
ishiyamayuto 0:d58274531d38 33
ishiyamayuto 0:d58274531d38 34 /** BMP180 class.
ishiyamayuto 0:d58274531d38 35 * Read Pressure and temperature from the BMP180 Breakout I2C sensor
ishiyamayuto 0:d58274531d38 36 *
ishiyamayuto 0:d58274531d38 37 * Example:
ishiyamayuto 0:d58274531d38 38 * @code
ishiyamayuto 0:d58274531d38 39 * #include "mbed.h"
ishiyamayuto 0:d58274531d38 40 * #include "BMP180.h"
ishiyamayuto 0:d58274531d38 41 *
ishiyamayuto 0:d58274531d38 42 * #if defined(TARGET_LPC1768)
ishiyamayuto 0:d58274531d38 43 * #define PIN_SDA p9
ishiyamayuto 0:d58274531d38 44 * #define PIN_SCL p10
ishiyamayuto 0:d58274531d38 45 * #elif defined(TARGET_KL25Z) // watch out for the PTE0/PTE1 mixed up in the KL25Z doc
ishiyamayuto 0:d58274531d38 46 * #define PIN_SDA PTE0
ishiyamayuto 0:d58274531d38 47 * #define PIN_SCL PTE1
ishiyamayuto 0:d58274531d38 48 * #endif
ishiyamayuto 0:d58274531d38 49 *
ishiyamayuto 0:d58274531d38 50 * int main()
ishiyamayuto 0:d58274531d38 51 * {
ishiyamayuto 0:d58274531d38 52 * BMP180 bmp180(PIN_SDA, PIN_SCL);
ishiyamayuto 0:d58274531d38 53 * float pressure, temperature;
ishiyamayuto 0:d58274531d38 54 *
ishiyamayuto 0:d58274531d38 55 * // bmp180.Initialize(); // no altitude compensation and normal oversampling
ishiyamayuto 0:d58274531d38 56 * bmp180.Initialize(64, BMP180_OSS_ULTRA_LOW_POWER); // 64m altitude compensation and low power oversampling
ishiyamayuto 0:d58274531d38 57 *
ishiyamayuto 0:d58274531d38 58 * while(1)
ishiyamayuto 0:d58274531d38 59 * {
ishiyamayuto 0:d58274531d38 60 * if (bmp180.ReadData(&pressure, &temperature))
ishiyamayuto 0:d58274531d38 61 * printf("Pressure(hPa): %8.2f \t Temperature(C): %8.2f\n", pressure, temperature);
ishiyamayuto 0:d58274531d38 62 * wait(1);
ishiyamayuto 0:d58274531d38 63 * }
ishiyamayuto 0:d58274531d38 64 * }
ishiyamayuto 0:d58274531d38 65 * @endcode
ishiyamayuto 0:d58274531d38 66 */
ishiyamayuto 0:d58274531d38 67 class BMP180
ishiyamayuto 0:d58274531d38 68 {
ishiyamayuto 0:d58274531d38 69
ishiyamayuto 0:d58274531d38 70 public:
ishiyamayuto 0:d58274531d38 71
ishiyamayuto 0:d58274531d38 72 /** Create a BMP180 instance
ishiyamayuto 0:d58274531d38 73 * @param sda pin
ishiyamayuto 0:d58274531d38 74 * @param scl pin
ishiyamayuto 0:d58274531d38 75 * @param address: I2C slave address
ishiyamayuto 0:d58274531d38 76 */
ishiyamayuto 0:d58274531d38 77 BMP180(PinName sda, PinName scl, int address = BMP180_I2C_ADDRESS);
ishiyamayuto 0:d58274531d38 78
ishiyamayuto 0:d58274531d38 79 /** Create a BMP180 instance
ishiyamayuto 0:d58274531d38 80 * @param i2c object
ishiyamayuto 0:d58274531d38 81 * @param address: I2C slave address
ishiyamayuto 0:d58274531d38 82 */
ishiyamayuto 0:d58274531d38 83 BMP180(I2C& i2c, int address = BMP180_I2C_ADDRESS);
ishiyamayuto 0:d58274531d38 84
ishiyamayuto 0:d58274531d38 85 /** Initialization: set member values and read BMP180 calibration parameters
ishiyamayuto 0:d58274531d38 86 * @param altitude (in meter)
ishiyamayuto 0:d58274531d38 87 * @param overSamplingSetting
ishiyamayuto 0:d58274531d38 88 */
ishiyamayuto 0:d58274531d38 89 int Initialize(float altitude = 0.F, int overSamplingSetting = BMP180_OSS_NORMAL);
ishiyamayuto 0:d58274531d38 90
ishiyamayuto 0:d58274531d38 91 /** Read pressure and temperature from the BMP180.
ishiyamayuto 0:d58274531d38 92 * @param pressure (hPa)
ishiyamayuto 0:d58274531d38 93 * @param temperature (C)
ishiyamayuto 0:d58274531d38 94 * @returns
ishiyamayuto 0:d58274531d38 95 * 1 on success,
ishiyamayuto 0:d58274531d38 96 * 0 on error
ishiyamayuto 0:d58274531d38 97 */
ishiyamayuto 0:d58274531d38 98 int ReadData(float* pTemperature = NULL, float* pPressure = NULL);
ishiyamayuto 0:d58274531d38 99
ishiyamayuto 0:d58274531d38 100 /** Get temperature from a previous measurement
ishiyamayuto 0:d58274531d38 101 *
ishiyamayuto 0:d58274531d38 102 * @returns
ishiyamayuto 0:d58274531d38 103 * temperature (C)
ishiyamayuto 0:d58274531d38 104 */
ishiyamayuto 0:d58274531d38 105 float GetTemperature() {return m_temperature;};
ishiyamayuto 0:d58274531d38 106
ishiyamayuto 0:d58274531d38 107 /** Get pressure from a previous measurement
ishiyamayuto 0:d58274531d38 108 *
ishiyamayuto 0:d58274531d38 109 * @returns
ishiyamayuto 0:d58274531d38 110 * pressure (hPa)
ishiyamayuto 0:d58274531d38 111 */
ishiyamayuto 0:d58274531d38 112 float GetPressure() {return m_pressure;};
ishiyamayuto 0:d58274531d38 113
ishiyamayuto 0:d58274531d38 114 protected:
ishiyamayuto 0:d58274531d38 115
ishiyamayuto 0:d58274531d38 116 /** Perform temperature measurement
ishiyamayuto 0:d58274531d38 117 *
ishiyamayuto 0:d58274531d38 118 * @returns
ishiyamayuto 0:d58274531d38 119 * temperature (C)
ishiyamayuto 0:d58274531d38 120 */
ishiyamayuto 0:d58274531d38 121 int ReadRawTemperature(long* pUt);
ishiyamayuto 0:d58274531d38 122
ishiyamayuto 0:d58274531d38 123 /** Perform pressure measurement
ishiyamayuto 0:d58274531d38 124 *
ishiyamayuto 0:d58274531d38 125 * @returns
ishiyamayuto 0:d58274531d38 126 * temperature (C)
ishiyamayuto 0:d58274531d38 127 */
ishiyamayuto 0:d58274531d38 128 int ReadRawPressure(long* pUp);
ishiyamayuto 0:d58274531d38 129
ishiyamayuto 0:d58274531d38 130 /** Calculation of the temperature from the digital output
ishiyamayuto 0:d58274531d38 131 */
ishiyamayuto 0:d58274531d38 132 float TrueTemperature(long ut);
ishiyamayuto 0:d58274531d38 133
ishiyamayuto 0:d58274531d38 134 /** Calculation of the pressure from the digital output
ishiyamayuto 0:d58274531d38 135 */
ishiyamayuto 0:d58274531d38 136 float TruePressure(long up);
ishiyamayuto 0:d58274531d38 137
ishiyamayuto 0:d58274531d38 138 int m_oss;
ishiyamayuto 0:d58274531d38 139 float m_temperature;
ishiyamayuto 0:d58274531d38 140 float m_pressure;
ishiyamayuto 0:d58274531d38 141 float m_altitude;
ishiyamayuto 0:d58274531d38 142
ishiyamayuto 0:d58274531d38 143 I2C m_i2c;
ishiyamayuto 0:d58274531d38 144 int m_addr;
ishiyamayuto 0:d58274531d38 145 char m_data[4];
ishiyamayuto 0:d58274531d38 146
ishiyamayuto 0:d58274531d38 147 short ac1, ac2, ac3;
ishiyamayuto 0:d58274531d38 148 unsigned short ac4, ac5, ac6;
ishiyamayuto 0:d58274531d38 149 short b1, b2;
ishiyamayuto 0:d58274531d38 150 short mb, mc, md;
ishiyamayuto 0:d58274531d38 151 long x1, x2, x3, b3, b5, b6;
ishiyamayuto 0:d58274531d38 152 unsigned long b4, b7;
ishiyamayuto 0:d58274531d38 153
ishiyamayuto 0:d58274531d38 154 };
ishiyamayuto 0:d58274531d38 155
ishiyamayuto 0:d58274531d38 156 #endif