1/*
2SFE_BMP180.h
3Bosch BMP180 pressure sensor library for the Arduino microcontroller
4Mike Grusin, SparkFun Electronics
56
Uses floating-point equations from the Weather Station Data Logger project
7http://wmrx00.sourceforge.net/
8http://wmrx00.sourceforge.net/Arduino/BMP085-Calcs.pdf
910
Forked from BMP085 library by M.Grusin
1112
version 1.0 2013/09/20 initial version
13Verison 1.1.2 - Updated for Arduino 1.6.4 5/2015
1415
Our example code uses the "beerware" license. You can do anything
16you like with this code. No really, anything. If you find it useful,
17buy me a (root) beer someday.
18*/
1920
#ifndef SFE_BMP180_h
21#define SFE_BMP180_h
2223
#if defined(ARDUINO) && ARDUINO >= 100
24#include "Arduino.h"
25#else
26#include "WProgram.h"
27#endif
2829
class SFE_BMP180
30{
31public:
32SFE_BMP180(); // base type
3334
char begin();
35// call pressure.begin() to initialize BMP180 before use
36// returns 1 if success, 0 if failure (bad component or I2C bus shorted?)
3738
char startTemperature(void);
39// command BMP180 to start a temperature measurement
40// returns (number of ms to wait) for success, 0 for fail
4142
char getTemperature(double &T);
43// return temperature measurement from previous startTemperature command
44// places returned value in T variable (deg C)
45// returns 1 for success, 0 for fail
4647
char startPressure(char oversampling);
48// command BMP180 to start a pressure measurement
49// oversampling: 0 - 3 for oversampling value
50// returns (number of ms to wait) for success, 0 for fail
5152
char getPressure(double &P, double &T);
53// return absolute pressure measurement from previous startPressure command
54// note: requires previous temperature measurement in variable T
55// places returned value in P variable (mbar)
56// returns 1 for success, 0 for fail
5758
double sealevel(double P, double A);
59// convert absolute pressure to sea-level pressure (as used in weather data)
60// P: absolute pressure (mbar)
61// A: current altitude (meters)
62// returns sealevel pressure in mbar
6364
double altitude(double P, double P0);
65// convert absolute pressure to altitude (given baseline pressure; sea-level, runway, etc.)
66// P: absolute pressure (mbar)
67// P0: fixed baseline pressure (mbar)
68// returns signed altitude in meters
6970
char getError(void);
71// If any library command fails, you can retrieve an extended
72// error code using this command. Errors are from the wire library:
73// 0 = Success
74// 1 = Data too long to fit in transmit buffer
75// 2 = Received NACK on transmit of address
76// 3 = Received NACK on transmit of data
77// 4 = Other error
7879
private:
8081
char readInt(char address, int16_t &value);
82// read an signed int (16 bits) from a BMP180 register
83// address: BMP180 register address
84// value: external signed int for returned value (16 bits)
85// returns 1 for success, 0 for fail, with result in value
8687
char readUInt(char address, uint16_t &value);
88// read an unsigned int (16 bits) from a BMP180 register
89// address: BMP180 register address
90// value: external unsigned int for returned value (16 bits)
91// returns 1 for success, 0 for fail, with result in value
9293
char readBytes(unsigned char *values, char length);
94// read a number of bytes from a BMP180 register
95// values: array of char with register address in first location [0]
96// length: number of bytes to read back
97// returns 1 for success, 0 for fail, with read bytes in values[] array
9899
char writeBytes(unsigned char *values, char length);
100// write a number of bytes to a BMP180 register (and consecutive subsequent registers)
101// values: array of char with register address in first location [0]
102// length: number of bytes to write
103// returns 1 for success, 0 for fail
104105
int16_t AC1,AC2,AC3,VB1,VB2,MB,MC,MD;
106uint16_t AC4,AC5,AC6;
107double c5,c6,mc,md,x0,x1,x2,y0,y1,y2,p0,p1,p2;
108char _error;
109};
110111
#define BMP180_ADDR 0x77 // 7-bit address
112113
#define BMP180_REG_CONTROL 0xF4
114#define BMP180_REG_RESULT 0xF6
115116
#define BMP180_COMMAND_TEMPERATURE 0x2E
117#define BMP180_COMMAND_PRESSURE0 0x34
118#define BMP180_COMMAND_PRESSURE1 0x74
119#define BMP180_COMMAND_PRESSURE2 0xB4
120#define BMP180_COMMAND_PRESSURE3 0xF4
121122
#endif