Archives for April 2015

Using ESP8266 with Arduino IDE 1.6.1 and BMP085 library


As I have continued to port my home sensor measurement tasks over the low-cost ESP8266 units, the next driver needed was for the Barometric Pressure Sensor. I have been using the popular BMP085 module for this purpose. The library for this sensor is at:

https://github.com/adafruit/Adafruit-BMP085-Library

Problem: There is one incompatibility using this library with the ESP8266 Arduino IDE platform. When attempting to compile a sketch that uses this library without modification, an error is encountered:

Adafruit_BMP085.cpp:(.text+0x3b8): undefined reference to `pow’

This occurs because the library is not properly linked to the core math.h library.

And changing the platform.txt file linker options to include “-lm” only makes things worse. In that case, the compiler returns an error that there is insufficient space to load the ‘.text’ segment.

Any implementation in c that involves fractional power (such as a double value that is not an even integer) requires the log function, also a math function. And the math.h library does not link correctly when compiling a sketch. So until this is addressed in the Arduino IDE build, the pow function simply cannot be used. Fortunately, pow is only required for the calculated value of altitude. Therefore, the bmp085 altitude features value cannot be used until the Arduino IDE for the ESP8266 supports it.

Solution: For now, BMP085 library can be tweaked slightly to make it usable with this IDE.

What I have not found is an acceptable substitute for the function implemented in c code. I tried some of the recursive algorithms available on the net to replace the missing function. But none of them worked properly. They either hung in endless recursive calls to the function or returned incorrect results.

What does work is the addition of a dummy function to the BMP085 library to replace the math.h “pow” that cannot currently be linked to properly . The name of the function must also be revised to avoid a conflict with the math.h prototype.

Here is the code I added to the BMP085 library, it now compiles properly:

double powr(double a,double b){
return 1.0;
}

Note that the function name was changed from “pow” to “powr”.

And remember to change the function name in the library code. It occurs in two places.

Here:

int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) {
float pressure = readPressure();
return (int32_t)(pressure / powpowr(1.0-altitude_meters/44330, 5.255));
}

And here:

float Adafruit_BMP085::readAltitude(float sealevelPressure) {
float altitude;
float pressure = readPressure();
altitude = 44330 * (1.0 – powpowr(pressure /sealevelPressure,0.1903));
return altitude;
}

Remember, this will result in bogus values for altitude. But it will allow you to use the BMP085 device with the ESP8266 Arduino IDE version 1.6.1 to retrieve the sensor’s pressure and temperature readings.

Hope someone finds this information useful…

Loading

Share This:
FacebooktwitterredditpinterestlinkedintumblrFacebooktwitterredditpinterestlinkedintumblr