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

9 Responses to Using ESP8266 with Arduino IDE 1.6.1 and BMP085 library

  1. Richard says:

    Hi, thanks for your help! managed to get it working on my eps-01!

  2. Ty Tower says:

    BMP085 and BMP180 are almost identical
    I used Sparkfuns SFE_BMP180 library and with a small change mentioned in the git hub issues #1
    Mydevice is happilly churning out temp and pressure data.

    • facebook-profile-picture Dave St. Aubin says:

      Ty,

      Could you kindly share the link to the github repository you have used for Sparkfun’s SFE_BMP180 library?

      All I could find is two using https://github.com/sparkfun?utf8=%E2%9C%93&query=bmp180 but it does not look like these are the ones you are referring to. Neither repository has any issues identified.

      BTW, the library I have been using has also been churning out data that is being logged to mySQL and ThingSpeak every hour on the hour for over a month now.

      Thanks…

  3. max v says:

    which pins did you use on ESP8266, I am trying to BMP180 my ESP-12 along with DHT11.
    thanks
    max

  4. facebook-profile-picture Dave St. Aubin says:

    I used a bmp085, dht11, and 3 ds18b20 sensors with a esp8266-12 in this project . The pins used are identified in the schematic.

  5. max v says:

    Dave,
    Can you please help with simple code to test BMP180/085 with ESP-12, I want to use it with thingspeak.com and show pressure and temp gauges on my weather images blog. Some how I am not able to get BMP085/180 working. I am bit confused with information on the net.
    Thanks in advance,
    max

  6. Roman says:

    Dave,
    many many thanks!! Your tutorial was very usefull for me.
    BTW for all: Randomly disconected wire from SCL pin and ESP was going to dump and reset after run sketch. It was hard job to findout it 🙁
    bye
    Roman

  7. Geovana says:

    before, I can work around it by malualny entering // or /* */, just providing some feedback. You put in some real work on this, serial monitor and everything works well on my Uno. I should try it on my Mega 2560, but you probably tied into the Arduino and it will work fine.By the way, speed of your plugin and ST2 is much better than Arduino IDE.I did mistakenly install your plugin twice on ST2, will try on another Mac and only install once. Will let you know if that works.A great plugin, may get me to use ST2 for more than Arduino. I usually use Textmate 1.5 for my simple programming (70 year old guy trying to keep brain active), found Eclipse and Arduino plugin a bit too much work just to do simple things, but love auto completion and bracket closing. Thanks again for your efforts, you have a fan in Denver, Colorado.

Leave a Reply to Dave St. Aubin Cancel reply