BMP085 Sensor I2C

Hello, I am trying to write out the code for an I2C connection to a BMP085 Barometric Pressure Sensor and wanted to see if anyone has already tried this. The funky math for this sensor is pretty long, and I’m still a newbie with Squirrel and formatting the equations. Any help would be appreciated.

Eww, yeah I had problems with that sensor on an arduino. The datasheet and example code are a long way from being clear and it took several attempts to get reasonable looking values out of it… good luck!

Here is the code that I use. The datasheet demo values are commented out. If you can improve on my code - please let me know!

`function getPressure() {


local x1;
local x2;
local x3;
local b3;
local b4;
local b5;
local b6;
local b7;
local p;
local temperature;
local pressure;


//calculate true temperature
x1 = (ut - ac6) * ac5 >> 15;
x2 = (mc << 11) / (x1 + md);
b5 = x1 + x2;

temperature = ((b5 + 8) >> 4)*0.1;

//calculate true pressure
b6 = b5 - 4000;
x1 = (b2 * (b6 * b6 >> 12)) >> 11; 
x2 = (ac2 * b6) >> 11;
x3 = x1 + x2;
b3 = (((ac1 * 4 + x3)<<oversampling_setting) + 2) >> 2;
x1 = ac3 * b6 >> 13;
x2 = (b1 * (b6 * b6 >> 12)) >> 16;
x3 = ((x1 + x2) + 2) >> 2;
b4 = (ac4 * (x3 + 32768)) >> 15;

b7 = (up - b3) * (50000 >> oversampling_setting);
p = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2;

x1 = (p >> 8) * (p >> 8);
x1 = (x1 * 3038) >> 16;
x2 = (-7357 * p) >> 16;
pressure = p + ((x1 + x2 + 3791) >> 4);
server.log(format("Presure sensor %5.1f mbar", math.abs(pressure)/100.0));

return (math.abs(pressure)/100.0);


Thanks! I’ll give that a try and see what I get.

Luckily, I’ve had some semi-accurate results on the Arduino side, however, I’ve had some trouble trying to figure out how to send the data via UART to the imp. I’m not quite sure how to format 4 different types of data (temp, pressure, etc.), send it to the UART, then receive and format on the imp. I’ve been playing with strings, and was about to try a blob, but haven’t had any luck so far.

Any ideas on that would be appreciated as well.

Sorry, I have no experience of UART interface. I have used I2C directly to the BMP085, SparkFun do a convenient breakout board.


Attached is an example class for reading temperature and pressure from the BMP085.
Hope it’s helpful.
- Matt

Many thxs!!!

Thanks, worked great! Took me a little while to understand I needed to change row 207 localmysensorbmp to 12 instead of 89 when using pin 1 and 2.

Worked like a charm. Thank you.

It works very well
i read 22,2 with my bmp085 and my mercury thermo reads 22.0

I didnt use pull ups as i read in the docs
Do i really need them?

You should have pullups, yes. It may just stop working without them.

I’m totally new to electronics, so a basic question, how do i wire pullups?


Just put a resistor from the pin to VCC. The documentation should give you a value to use, but something around 5K should be a good starting point.