Go to most recent revision | Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
1993 | - | 1 | /**************************************************************************** |
2 | * BMP085.h - BMP085/I2C (Digital Pressure Sensor) library for Arduino * |
||
3 | * Copyright 2010-2011 Filipe Vieira & various contributors * |
||
4 | * * |
||
5 | * This file is part of BMP085 Arduino library. * |
||
6 | * * |
||
7 | * This library is free software: you can redistribute it and/or modify * |
||
8 | * it under the terms of the GNU Lesser General Public License as published * |
||
9 | * by the Free Software Foundation, either version 3 of the License, or * |
||
10 | * (at your option) any later version. * |
||
11 | * * |
||
12 | * This program is distributed in the hope that it will be useful, * |
||
13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of * |
||
14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * |
||
15 | * GNU Lesser General Public License for more details. * |
||
16 | * * |
||
17 | * You should have received a copy of the GNU Lesser General Public License * |
||
18 | * along with this program. If not, see <http://www.gnu.org/licenses/>. * |
||
19 | ****************************************************************************/ |
||
20 | /**************************************************************************** |
||
21 | * Tested on Arduino Mega with BMP085 Breakout * |
||
22 | * SDA -> pin 20 (no pull up resistors) * |
||
23 | * SCL -> pin 21 (no pull up resistors) * |
||
24 | * XCLR -> not connected * |
||
25 | * EOC -> not connected * |
||
26 | * GND -> pin GND * |
||
27 | * VCC -> pin 3.3V * |
||
28 | * NOTE: SCL and SDA needs pull-up resistors for each I2C bus. * |
||
29 | * 2.2kOhm..10kOhm, typ. 4.7kOhm * |
||
30 | *****************************************************************************/ |
||
31 | #ifndef BMP085_h |
||
32 | #define BMP085_h |
||
33 | |||
34 | #include "WProgram.h" |
||
35 | |||
36 | #define BMP085_ADDR 0x77 //0x77 default I2C address |
||
37 | #define BUFFER_SIZE 3 |
||
38 | |||
39 | #define AUTO_UPDATE_TEMPERATURE true //default is true |
||
40 | // when true, temperature is measured everytime pressure is measured (Auto). |
||
41 | // when false, user chooses when to measure temperature (just call calcTrueTemperature()). |
||
42 | // used for dynamic measurement to increase sample rate (see BMP085 modes below). |
||
43 | |||
44 | /* ---- Registers ---- */ |
||
45 | #define CAL_AC1 0xAA // R Calibration data (16 bits) |
||
46 | #define CAL_AC2 0xAC // R Calibration data (16 bits) |
||
47 | #define CAL_AC3 0xAE // R Calibration data (16 bits) |
||
48 | #define CAL_AC4 0xB0 // R Calibration data (16 bits) |
||
49 | #define CAL_AC5 0xB2 // R Calibration data (16 bits) |
||
50 | #define CAL_AC6 0xB4 // R Calibration data (16 bits) |
||
51 | #define CAL_B1 0xB6 // R Calibration data (16 bits) |
||
52 | #define CAL_B2 0xB8 // R Calibration data (16 bits) |
||
53 | #define CAL_MB 0xBA // R Calibration data (16 bits) |
||
54 | #define CAL_MC 0xBC // R Calibration data (16 bits) |
||
55 | #define CAL_MD 0xBE // R Calibration data (16 bits) |
||
56 | #define CONTROL 0xF4 // W Control register |
||
57 | #define CONTROL_OUTPUT 0xF6 // R Output registers 0xF6=MSB, 0xF7=LSB, 0xF8=XLSB |
||
58 | |||
59 | // unused registers |
||
60 | #define SOFTRESET 0xE0 |
||
61 | #define VERSION 0xD1 // ML_VERSION pos=0 len=4 msk=0F AL_VERSION pos=4 len=4 msk=f0 |
||
62 | #define CHIPID 0xD0 // pos=0 mask=FF len=8 |
||
63 | // BMP085_CHIP_ID=0x55 |
||
64 | |||
65 | /************************************/ |
||
66 | /* REGISTERS PARAMETERS */ |
||
67 | /************************************/ |
||
68 | // BMP085 Modes |
||
69 | #define MODE_ULTRA_LOW_POWER 0 //oversampling=0, internalsamples=1, maxconvtimepressure=4.5ms, avgcurrent=3uA, RMSnoise_hPA=0.06, RMSnoise_m=0.5 |
||
70 | #define MODE_STANDARD 1 //oversampling=1, internalsamples=2, maxconvtimepressure=7.5ms, avgcurrent=5uA, RMSnoise_hPA=0.05, RMSnoise_m=0.4 |
||
71 | #define MODE_HIGHRES 2 //oversampling=2, internalsamples=4, maxconvtimepressure=13.5ms, avgcurrent=7uA, RMSnoise_hPA=0.04, RMSnoise_m=0.3 |
||
72 | #define MODE_ULTRA_HIGHRES 3 //oversampling=3, internalsamples=8, maxconvtimepressure=25.5ms, avgcurrent=12uA, RMSnoise_hPA=0.03, RMSnoise_m=0.25 |
||
73 | // "Sampling rate can be increased to 128 samples per second (standard mode) for |
||
74 | // dynamic measurement.In this case it is sufficient to measure temperature only |
||
75 | // once per second and to use this value for all pressure measurements during period." |
||
76 | // (from BMP085 datasheet Rev1.2 page 10). |
||
77 | // To use dynamic measurement set AUTO_UPDATE_TEMPERATURE to false and |
||
78 | // call calcTrueTemperature() from your code. |
||
79 | // Control register |
||
80 | #define READ_TEMPERATURE 0x2E |
||
81 | #define READ_PRESSURE 0x34 |
||
82 | //Other |
||
83 | #define MSLP 101325 // Mean Sea Level Pressure = 1013.25 hPA (1hPa = 100Pa = 1mbar) |
||
84 | |||
85 | |||
86 | |||
87 | class BMP085 { |
||
88 | public: |
||
89 | BMP085(); |
||
90 | |||
91 | // BMP initialization |
||
92 | void init(); // sets current elevation above ground level to 0 meters |
||
93 | void init(byte _BMPMode, int32_t _initVal, bool _centimeters); // sets a reference datum |
||
94 | // if _centimeters=false _initVal is Pa |
||
95 | // Who Am I |
||
96 | byte getDevAddr(); |
||
97 | |||
98 | // BMP mode |
||
99 | byte getMode(); |
||
100 | void setMode(byte _BMPMode); // BMP085 mode |
||
101 | // initialization |
||
102 | void setLocalPressure(int32_t _Pa); // set known barometric pressure as reference Ex. QNH |
||
103 | void setLocalAbsAlt(int32_t _centimeters); // set known altitude as reference |
||
104 | void setAltOffset(int32_t _centimeters); // altitude offset |
||
105 | void sethPaOffset(int32_t _Pa); // pressure offset |
||
106 | void zeroCal(int32_t _Pa, int32_t _centimeters);// zero Calibrate output to a specific Pa/altitude |
||
107 | // BMP Sensors |
||
108 | void getPressure(int32_t *_Pa); // pressure in Pa + offset |
||
109 | void getAltitude(int32_t *_centimeters); // altitude in centimeters + offset |
||
110 | void getTemperature(int32_t *_Temperature); // temperature in Cº |
||
111 | void calcTrueTemperature(); // calc temperature data b5 (only needed if AUTO_UPDATE_TEMPERATURE is false) |
||
112 | void calcTruePressure(long *_TruePressure); // calc Pressure in Pa |
||
113 | // dummy stuff |
||
114 | void dumpCalData(); // debug only |
||
115 | |||
116 | void writemem(uint8_t _addr, uint8_t _val); |
||
117 | void readmem(uint8_t _addr, uint8_t _nbytes, uint8_t __buff[]); |
||
118 | |||
119 | private: |
||
120 | |||
121 | int ac1,ac2,ac3,b1,b2,mb,mc,md; // cal data |
||
122 | unsigned int ac4,ac5,ac6; // cal data |
||
123 | long b5, oldEMA; // temperature data |
||
124 | |||
125 | uint8_t _dev_address; |
||
126 | byte _buff[BUFFER_SIZE]; // buffer MSB LSB XLSB |
||
127 | int _oss; // OverSamplingSetting |
||
128 | int _pressure_waittime[4]; // Max. Conversion Time Pressure is ms for each mode |
||
129 | |||
130 | int32_t _cm_Offset, _Pa_Offset; |
||
131 | int32_t _param_datum, _param_centimeters; |
||
132 | |||
133 | void getCalData(); |
||
134 | |||
135 | |||
136 | }; |
||
137 | |||
138 | #endif |