Skip to content

Commit 843e163

Browse files
committed
Update BMP085 library.
And additional pressure sensor problems repoted by @magkas. http://forum.mysensors.org/topic/631/pressure-sensor-arduino-low-memory
1 parent ab3db8b commit 843e163

File tree

4 files changed

+49
-29
lines changed

4 files changed

+49
-29
lines changed

libraries/Adafruit_BMP085/Adafruit_BMP085.cpp

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/***************************************************
2-
This is a library for the BMP085 Barometric Pressure & Temp Sensor
2+
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
33
4-
Designed specifically to work with the Adafruit BMP085 Breakout
5-
----> https://www.adafruit.com/products/391
4+
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
5+
----> http://www.adafruit.com/products/391
6+
----> http://www.adafruit.com/products/1603
67
78
These displays use I2C to communicate, 2 pins are required to
89
interface
@@ -15,7 +16,6 @@
1516
****************************************************/
1617

1718
#include "Adafruit_BMP085.h"
18-
#include <util/delay.h>
1919

2020
Adafruit_BMP085::Adafruit_BMP085() {
2121
}
@@ -59,11 +59,19 @@ boolean Adafruit_BMP085::begin(uint8_t mode) {
5959
Serial.print("mc = "); Serial.println(mc, DEC);
6060
Serial.print("md = "); Serial.println(md, DEC);
6161
#endif
62+
63+
return true;
64+
}
65+
66+
int32_t Adafruit_BMP085::computeB5(int32_t UT) {
67+
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
68+
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
69+
return X1 + X2;
6270
}
6371

6472
uint16_t Adafruit_BMP085::readRawTemperature(void) {
6573
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
66-
_delay_ms(5);
74+
delay(5);
6775
#if BMP085_DEBUG == 1
6876
Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA));
6977
#endif
@@ -76,13 +84,13 @@ uint32_t Adafruit_BMP085::readRawPressure(void) {
7684
write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
7785

7886
if (oversampling == BMP085_ULTRALOWPOWER)
79-
_delay_ms(5);
87+
delay(5);
8088
else if (oversampling == BMP085_STANDARD)
81-
_delay_ms(8);
89+
delay(8);
8290
else if (oversampling == BMP085_HIGHRES)
83-
_delay_ms(14);
91+
delay(14);
8492
else
85-
_delay_ms(26);
93+
delay(26);
8694

8795
raw = read16(BMP085_PRESSUREDATA);
8896

@@ -129,10 +137,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
129137
oversampling = 0;
130138
#endif
131139

132-
// do temperature calculations
133-
X1=(UT-(int32_t)(ac6))*((int32_t)(ac5))/pow(2,15);
134-
X2=((int32_t)mc*pow(2,11))/(X1+(int32_t)md);
135-
B5=X1 + X2;
140+
B5 = computeB5(UT);
136141

137142
#if BMP085_DEBUG == 1
138143
Serial.print("X1 = "); Serial.println(X1);
@@ -189,9 +194,13 @@ int32_t Adafruit_BMP085::readPressure(void) {
189194
return p;
190195
}
191196

197+
int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) {
198+
float pressure = readPressure();
199+
return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255));
200+
}
192201

193202
float Adafruit_BMP085::readTemperature(void) {
194-
int32_t UT, X1, X2, B5; // following ds convention
203+
int32_t UT, B5; // following ds convention
195204
float temp;
196205

197206
UT = readRawTemperature();
@@ -205,11 +214,8 @@ float Adafruit_BMP085::readTemperature(void) {
205214
md = 2868;
206215
#endif
207216

208-
// step 1
209-
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2,15);
210-
X2 = ((int32_t)mc * pow(2,11)) / (X1+(int32_t)md);
211-
B5 = X1 + X2;
212-
temp = (B5+8)/pow(2,4);
217+
B5 = computeB5(UT);
218+
temp = (B5+8) >> 4;
213219
temp /= 10;
214220

215221
return temp;

libraries/Adafruit_BMP085/Adafruit_BMP085.h

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
/***************************************************
2-
This is a library for the BMP085 Barometric Pressure & Temp Sensor
2+
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
33
4-
Designed specifically to work with the Adafruit BMP085 Breakout
5-
----> https://www.adafruit.com/products/391
4+
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
5+
----> http://www.adafruit.com/products/391
6+
----> http://www.adafruit.com/products/1603
67
78
These displays use I2C to communicate, 2 pins are required to
89
interface
@@ -14,6 +15,9 @@
1415
BSD license, all text above must be included in any redistribution
1516
****************************************************/
1617

18+
#ifndef ADAFRUIT_BMP085_H
19+
#define ADAFRUIT_BMP085_H
20+
1721
#if (ARDUINO >= 100)
1822
#include "Arduino.h"
1923
#else
@@ -54,11 +58,13 @@ class Adafruit_BMP085 {
5458
boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
5559
float readTemperature(void);
5660
int32_t readPressure(void);
61+
int32_t readSealevelPressure(float altitude_meters = 0);
5762
float readAltitude(float sealevelPressure = 101325); // std atmosphere
5863
uint16_t readRawTemperature(void);
5964
uint32_t readRawPressure(void);
6065

6166
private:
67+
int32_t computeB5(int32_t UT);
6268
uint8_t read8(uint8_t addr);
6369
uint16_t read16(uint8_t addr);
6470
void write8(uint8_t addr, uint8_t data);
@@ -69,3 +75,5 @@ class Adafruit_BMP085 {
6975
uint16_t ac4, ac5, ac6;
7076
};
7177

78+
79+
#endif // ADAFRUIT_BMP085_H

libraries/Adafruit_BMP085/README.txt

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1-
This is a library for the Adafruit BMP085 Barometric Pressure + Temp sensor
1+
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
22

3-
Designed specifically to work with the Adafruit BMP085 Breakout
4-
----> https://www.adafruit.com/products/391
3+
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
4+
----> http://www.adafruit.com/products/391
5+
----> http://www.adafruit.com/products/1603
56

67
These displays use I2C to communicate, 2 pins are required to interface
78
Adafruit invests time and resources providing this open source code,
@@ -17,6 +18,11 @@ products from Adafruit!
1718
Written by Limor Fried/Ladyada for Adafruit Industries.
1819
BSD license, all text above must be included in any redistribution
1920

20-
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder Adafruit_BMP085. Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
21+
To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BMP085.
22+
Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
2123

22-
Place the Adafruit_BMP085 library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
24+
Place the Adafruit_BMP085 library folder your arduinosketchfolder/libraries/ folder.
25+
You may need to create the libraries subfolder if its your first library. Restart the IDE.
26+
27+
We also have a great tutorial on Arduino library installation at:
28+
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use

libraries/MySensors/examples/PressureSensor/PressureSensor.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ void setup() {
4444
}
4545

4646
void loop() {
47-
float pressure = bmp.readPressure()/100;
47+
float pressure = bmp.readSealevelPressure(205)/100; // 205 meters above sealevel
4848
float temperature = bmp.readTemperature();
4949

5050
if (!metric) {
@@ -95,7 +95,7 @@ void loop() {
9595
int sample(float pressure) {
9696
// Algorithm found here
9797
// http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
98-
if (minuteCount > 180)
98+
if (minuteCount == 180)
9999
minuteCount = 5;
100100

101101
pressureSamples[minuteCount] = pressure;

0 commit comments

Comments
 (0)