-
Notifications
You must be signed in to change notification settings - Fork 25
/
SFE_BMP180.h
executable file
·122 lines (97 loc) · 4.08 KB
/
SFE_BMP180.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
/*
SFE_BMP180.h
Bosch BMP180 pressure sensor library for the Arduino microcontroller
Mike Grusin, SparkFun Electronics
Uses floating-point equations from the Weather Station Data Logger project
http://wmrx00.sourceforge.net/
http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf
Forked from BMP085 library by M.Grusin
version 1.0 2013/09/20 initial version
version 1.1 2018/02/25 int -> int16_t (ESP8266)
Our example code uses the "beerware" license. You can do anything
you like with this code. No really, anything. If you find it useful,
buy me a (root) beer someday.
*/
#ifndef SFE_BMP180_h
#define SFE_BMP180_h
#if defined(ARDUINO) && ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
class SFE_BMP180
{
public:
SFE_BMP180(); // base type
char begin();
// call pressure.begin() to initialize BMP180 before use
// returns 1 if success, 0 if failure (bad component or I2C bus shorted?)
char startTemperature(void);
// command BMP180 to start a temperature measurement
// returns (number of ms to wait) for success, 0 for fail
char getTemperature(double &T);
// return temperature measurement from previous startTemperature command
// places returned value in T variable (deg C)
// returns 1 for success, 0 for fail
char startPressure(char oversampling);
// command BMP180 to start a pressure measurement
// oversampling: 0 - 3 for oversampling value
// returns (number of ms to wait) for success, 0 for fail
char getPressure(double &P, double &T);
// return absolute pressure measurement from previous startPressure command
// note: requires previous temperature measurement in variable T
// places returned value in P variable (mbar)
// returns 1 for success, 0 for fail
double sealevel(double P, double A);
// convert absolute pressure to sea-level pressure (as used in weather data)
// P: absolute pressure (mbar)
// A: current altitude (meters)
// returns sealevel pressure in mbar
double altitude(double P, double P0);
// convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.)
// P: absolute pressure (mbar)
// P0: fixed baseline pressure (mbar)
// returns signed altitude in meters
char getError(void);
// If any library command fails, you can retrieve an extended
// error code using this command. Errors are from the wire library:
// 0 = Success
// 1 = Data too long to fit in transmit buffer
// 2 = Received NACK on transmit of address
// 3 = Received NACK on transmit of data
// 4 = Other error
private:
char readInt(char address, int16_t &value);
// read an signed int (16 bits) from a BMP180 register
// address: BMP180 register address
// value: external signed int for returned value (16 bits)
// returns 1 for success, 0 for fail, with result in value
char readUInt(char address, uint16_t &value);
// read an unsigned int (16 bits) from a BMP180 register
// address: BMP180 register address
// value: external unsigned int for returned value (16 bits)
// returns 1 for success, 0 for fail, with result in value
char readBytes(unsigned char *values, char length);
// read a number of bytes from a BMP180 register
// values: array of char with register address in first location [0]
// length: number of bytes to read back
// returns 1 for success, 0 for fail, with read bytes in values[] array
char writeBytes(unsigned char *values, char length);
// write a number of bytes to a BMP180 register (and consecutive subsequent registers)
// values: array of char with register address in first location [0]
// length: number of bytes to write
// returns 1 for success, 0 for fail
int16_t AC1,AC2,AC3,VB1,VB2,MB,MC,MD;
uint16_t AC4,AC5,AC6;
double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2;
char _error;
};
#define BMP180_ADDR 0x77 // 7-bit address
#define BMP180_REG_CONTROL 0xF4
#define BMP180_REG_RESULT 0xF6
#define BMP180_COMMAND_TEMPERATURE 0x2E
#define BMP180_COMMAND_PRESSURE0 0x34
#define BMP180_COMMAND_PRESSURE1 0x74
#define BMP180_COMMAND_PRESSURE2 0xB4
#define BMP180_COMMAND_PRESSURE3 0xF4
#endif