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:
@@ -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
|
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||||
----> https://www.adafruit.com/products/391
|
----> http://www.adafruit.com/products/391
|
||||||
|
----> http://www.adafruit.com/products/1603
|
||||||
|
|
||||||
These displays use I2C to communicate, 2 pins are required to
|
These displays use I2C to communicate, 2 pins are required to
|
||||||
interface
|
interface
|
||||||
@@ -15,7 +16,6 @@
|
|||||||
****************************************************/
|
****************************************************/
|
||||||
|
|
||||||
#include "Adafruit_BMP085.h"
|
#include "Adafruit_BMP085.h"
|
||||||
#include <util/delay.h>
|
|
||||||
|
|
||||||
Adafruit_BMP085::Adafruit_BMP085() {
|
Adafruit_BMP085::Adafruit_BMP085() {
|
||||||
}
|
}
|
||||||
@@ -59,11 +59,19 @@ boolean Adafruit_BMP085::begin(uint8_t mode) {
|
|||||||
Serial.print("mc = "); Serial.println(mc, DEC);
|
Serial.print("mc = "); Serial.println(mc, DEC);
|
||||||
Serial.print("md = "); Serial.println(md, DEC);
|
Serial.print("md = "); Serial.println(md, DEC);
|
||||||
#endif
|
#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) {
|
uint16_t Adafruit_BMP085::readRawTemperature(void) {
|
||||||
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
|
write8(BMP085_CONTROL, BMP085_READTEMPCMD);
|
||||||
_delay_ms(5);
|
delay(5);
|
||||||
#if BMP085_DEBUG == 1
|
#if BMP085_DEBUG == 1
|
||||||
Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA));
|
Serial.print("Raw temp: "); Serial.println(read16(BMP085_TEMPDATA));
|
||||||
#endif
|
#endif
|
||||||
@@ -76,13 +84,13 @@ uint32_t Adafruit_BMP085::readRawPressure(void) {
|
|||||||
write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
|
write8(BMP085_CONTROL, BMP085_READPRESSURECMD + (oversampling << 6));
|
||||||
|
|
||||||
if (oversampling == BMP085_ULTRALOWPOWER)
|
if (oversampling == BMP085_ULTRALOWPOWER)
|
||||||
_delay_ms(5);
|
delay(5);
|
||||||
else if (oversampling == BMP085_STANDARD)
|
else if (oversampling == BMP085_STANDARD)
|
||||||
_delay_ms(8);
|
delay(8);
|
||||||
else if (oversampling == BMP085_HIGHRES)
|
else if (oversampling == BMP085_HIGHRES)
|
||||||
_delay_ms(14);
|
delay(14);
|
||||||
else
|
else
|
||||||
_delay_ms(26);
|
delay(26);
|
||||||
|
|
||||||
raw = read16(BMP085_PRESSUREDATA);
|
raw = read16(BMP085_PRESSUREDATA);
|
||||||
|
|
||||||
@@ -129,10 +137,7 @@ int32_t Adafruit_BMP085::readPressure(void) {
|
|||||||
oversampling = 0;
|
oversampling = 0;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// do temperature calculations
|
B5 = computeB5(UT);
|
||||||
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;
|
|
||||||
|
|
||||||
#if BMP085_DEBUG == 1
|
#if BMP085_DEBUG == 1
|
||||||
Serial.print("X1 = "); Serial.println(X1);
|
Serial.print("X1 = "); Serial.println(X1);
|
||||||
@@ -189,9 +194,13 @@ int32_t Adafruit_BMP085::readPressure(void) {
|
|||||||
return p;
|
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) {
|
float Adafruit_BMP085::readTemperature(void) {
|
||||||
int32_t UT, X1, X2, B5; // following ds convention
|
int32_t UT, B5; // following ds convention
|
||||||
float temp;
|
float temp;
|
||||||
|
|
||||||
UT = readRawTemperature();
|
UT = readRawTemperature();
|
||||||
@@ -205,11 +214,8 @@ float Adafruit_BMP085::readTemperature(void) {
|
|||||||
md = 2868;
|
md = 2868;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// step 1
|
B5 = computeB5(UT);
|
||||||
X1 = (UT - (int32_t)ac6) * ((int32_t)ac5) / pow(2,15);
|
temp = (B5+8) >> 4;
|
||||||
X2 = ((int32_t)mc * pow(2,11)) / (X1+(int32_t)md);
|
|
||||||
B5 = X1 + X2;
|
|
||||||
temp = (B5+8)/pow(2,4);
|
|
||||||
temp /= 10;
|
temp /= 10;
|
||||||
|
|
||||||
return temp;
|
return temp;
|
||||||
|
|||||||
@@ -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
|
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||||
----> https://www.adafruit.com/products/391
|
----> http://www.adafruit.com/products/391
|
||||||
|
----> http://www.adafruit.com/products/1603
|
||||||
|
|
||||||
These displays use I2C to communicate, 2 pins are required to
|
These displays use I2C to communicate, 2 pins are required to
|
||||||
interface
|
interface
|
||||||
@@ -14,6 +15,9 @@
|
|||||||
BSD license, all text above must be included in any redistribution
|
BSD license, all text above must be included in any redistribution
|
||||||
****************************************************/
|
****************************************************/
|
||||||
|
|
||||||
|
#ifndef ADAFRUIT_BMP085_H
|
||||||
|
#define ADAFRUIT_BMP085_H
|
||||||
|
|
||||||
#if (ARDUINO >= 100)
|
#if (ARDUINO >= 100)
|
||||||
#include "Arduino.h"
|
#include "Arduino.h"
|
||||||
#else
|
#else
|
||||||
@@ -54,11 +58,13 @@ class Adafruit_BMP085 {
|
|||||||
boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
|
boolean begin(uint8_t mode = BMP085_ULTRAHIGHRES); // by default go highres
|
||||||
float readTemperature(void);
|
float readTemperature(void);
|
||||||
int32_t readPressure(void);
|
int32_t readPressure(void);
|
||||||
|
int32_t readSealevelPressure(float altitude_meters = 0);
|
||||||
float readAltitude(float sealevelPressure = 101325); // std atmosphere
|
float readAltitude(float sealevelPressure = 101325); // std atmosphere
|
||||||
uint16_t readRawTemperature(void);
|
uint16_t readRawTemperature(void);
|
||||||
uint32_t readRawPressure(void);
|
uint32_t readRawPressure(void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
int32_t computeB5(int32_t UT);
|
||||||
uint8_t read8(uint8_t addr);
|
uint8_t read8(uint8_t addr);
|
||||||
uint16_t read16(uint8_t addr);
|
uint16_t read16(uint8_t addr);
|
||||||
void write8(uint8_t addr, uint8_t data);
|
void write8(uint8_t addr, uint8_t data);
|
||||||
@@ -69,3 +75,5 @@ class Adafruit_BMP085 {
|
|||||||
uint16_t ac4, ac5, ac6;
|
uint16_t ac4, ac5, ac6;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
#endif // ADAFRUIT_BMP085_H
|
||||||
|
|||||||
@@ -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
|
Designed specifically to work with the Adafruit BMP085 or BMP180 Breakout
|
||||||
----> https://www.adafruit.com/products/391
|
----> http://www.adafruit.com/products/391
|
||||||
|
----> http://www.adafruit.com/products/1603
|
||||||
|
|
||||||
These displays use I2C to communicate, 2 pins are required to interface
|
These displays use I2C to communicate, 2 pins are required to interface
|
||||||
Adafruit invests time and resources providing this open source code,
|
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.
|
Written by Limor Fried/Ladyada for Adafruit Industries.
|
||||||
BSD license, all text above must be included in any redistribution
|
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() {
|
void loop() {
|
||||||
float pressure = bmp.readPressure()/100;
|
float pressure = bmp.readSealevelPressure(205)/100; // 205 meters above sealevel
|
||||||
float temperature = bmp.readTemperature();
|
float temperature = bmp.readTemperature();
|
||||||
|
|
||||||
if (!metric) {
|
if (!metric) {
|
||||||
@@ -95,7 +95,7 @@ void loop() {
|
|||||||
int sample(float pressure) {
|
int sample(float pressure) {
|
||||||
// Algorithm found here
|
// Algorithm found here
|
||||||
// http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
|
// http://www.freescale.com/files/sensors/doc/app_note/AN3914.pdf
|
||||||
if (minuteCount > 180)
|
if (minuteCount == 180)
|
||||||
minuteCount = 5;
|
minuteCount = 5;
|
||||||
|
|
||||||
pressureSamples[minuteCount] = pressure;
|
pressureSamples[minuteCount] = pressure;
|
||||||
|
|||||||
Reference in New Issue
Block a user