Update BMP085 library.

And additional pressure sensor problems repoted by @MagKas.
http://forum.mysensors.org/topic/631/pressure-sensor-arduino-low-memory
This commit is contained in:
Henrik Ekblad
2014-11-25 16:18:40 +01:00
parent ab3db8b28b
commit 843e163328
4 changed files with 49 additions and 29 deletions
+25 -19
View File
@@ -1,8 +1,9 @@
/***************************************************
This is a library for the BMP085 Barometric Pressure & Temp Sensor
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/391
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
----> http://www.adafruit.com/products/391
----> http://www.adafruit.com/products/1603
These displays use I2C to communicate, 2 pins are required to
interface
@@ -15,7 +16,6 @@
****************************************************/
#include "Adafruit_BMP085.h"
#include <util/delay.h>
Adafruit_BMP085::Adafruit_BMP085() {
}
@@ -59,11 +59,19 @@ boolean Adafruit_BMP085::begin(uint8_t mode) {
Serial.print("mc = "); Serial.println(mc, DEC);
Serial.print("md = "); Serial.println(md, DEC);
#endif
return true;
}
int32_t Adafruit_BMP085::computeB5(int32_t UT) {
int32_t X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) >> 15;
int32_t X2 = ((int32_t)mc << 11) / (X1+(int32_t)md);
return X1 + X2;
}
uint16_t Adafruit_BMP085::readRawTemperature(void) {
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
_delay_ms(5);
delay(5);
#if BMP085_DEBUG == 1
Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA));
#endif
@@ -76,13 +84,13 @@ uint32_t Adafruit_BMP085::readRawPressure(void) {
write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
if (oversampling == BMP085_ULTRALOWPOWER)
_delay_ms(5);
delay(5);
else if (oversampling == BMP085_STANDARD)
_delay_ms(8);
delay(8);
else if (oversampling == BMP085_HIGHRES)
_delay_ms(14);
delay(14);
else
_delay_ms(26);
delay(26);
raw = read16(BMP085_PRESSUREDATA);
@@ -129,10 +137,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
oversampling = 0;
#endif
// do temperature calculations
X1=(UT-(int32_t)(ac6))*((int32_t)(ac5))/pow(2,15);
X2=((int32_t)mc*pow(2,11))/(X1+(int32_t)md);
B5=X1 + X2;
B5 = computeB5(UT);
#if BMP085_DEBUG == 1
Serial.print("X1 = "); Serial.println(X1);
@@ -189,9 +194,13 @@ int32_t Adafruit_BMP085::readPressure(void) {
return p;
}
int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) {
float pressure = readPressure();
return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255));
}
float Adafruit_BMP085::readTemperature(void) {
int32_t UT, X1, X2, B5; // following ds convention
int32_t UT, B5; // following ds convention
float temp;
UT = readRawTemperature();
@@ -205,11 +214,8 @@ float Adafruit_BMP085::readTemperature(void) {
md = 2868;
#endif
// step 1
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2,15);
X2 = ((int32_t)mc * pow(2,11)) / (X1+(int32_t)md);
B5 = X1 + X2;
temp = (B5+8)/pow(2,4);
B5 = computeB5(UT);
temp = (B5+8) >> 4;
temp /= 10;
return temp;
+11 -3
View File
@@ -1,8 +1,9 @@
/***************************************************
This is a library for the BMP085 Barometric Pressure & Temp Sensor
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/391
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
----> http://www.adafruit.com/products/391
----> http://www.adafruit.com/products/1603
These displays use I2C to communicate, 2 pins are required to
interface
@@ -14,6 +15,9 @@
BSD license, all text above must be included in any redistribution
****************************************************/
#ifndef ADAFRUIT_BMP085_H
#define ADAFRUIT_BMP085_H
#if (ARDUINO >= 100)
#include "Arduino.h"
#else
@@ -54,11 +58,13 @@ class Adafruit_BMP085 {
boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
float readTemperature(void);
int32_t readPressure(void);
int32_t readSealevelPressure(float altitude_meters = 0);
float readAltitude(float sealevelPressure = 101325); // std atmosphere
uint16_t readRawTemperature(void);
uint32_t readRawPressure(void);
private:
int32_t computeB5(int32_t UT);
uint8_t read8(uint8_t addr);
uint16_t read16(uint8_t addr);
void write8(uint8_t addr, uint8_t data);
@@ -69,3 +75,5 @@ class Adafruit_BMP085 {
uint16_t ac4, ac5, ac6;
};
#endif // ADAFRUIT_BMP085_H
+11 -5
View File
@@ -1,7 +1,8 @@
This is a library for the Adafruit BMP085 Barometric Pressure + Temp sensor
This is a library for the Adafruit BMP085/BMP180 Barometric Pressure + Temp sensor
Designed specifically to work with the Adafruit BMP085 Breakout
----> https://www.adafruit.com/products/391
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
----> http://www.adafruit.com/products/391
----> http://www.adafruit.com/products/1603
These displays use I2C to communicate, 2 pins are required to interface
Adafruit invests time and resources providing this open source code,
@@ -17,6 +18,11 @@ products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
BSD license, all text above must be included in any redistribution
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
To download. click the DOWNLOAD ZIP button, rename the uncompressed folder Adafruit_BMP085.
Check that the Adafruit_BMP085 folder contains Adafruit_BMP085.cpp and Adafruit_BMP085.h
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.
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.
We also have a great tutorial on Arduino library installation at:
http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use
@@ -44,7 +44,7 @@ void setup() {
}
void loop() {
float pressure = bmp.readPressure()/100;
float pressure = bmp.readSealevelPressure(205)/100; // 205 meters above sealevel
float temperature = bmp.readTemperature();
if (!metric) {
@@ -95,7 +95,7 @@ void loop() {
int sample(float pressure) {
// Algorithm found here
// http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
if (minuteCount > 180)
if (minuteCount == 180)
minuteCount = 5;
pressureSamples[minuteCount] = pressure;