BMP085 barometric pressure/temperature sensor.

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 5.
To post in this forum you must have a registered copy of Flowcode 5 or higher.

Moderator: Benj

Post Reply
Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Hi have just ordered this:
http://www.robotshop.com/productinfo.as ... lang=en-US

I would like to know if someone have already work with this and if there is any exemple on how to interface with it. Thanx a lot!

User avatar
Enamul
Posts: 1772
Joined: Mon Mar 05, 2012 11:34 pm
Location: Nottingham, UK
Has thanked: 271 times
Been thanked: 814 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Enamul »

Although I haven't tried this module, it seems very interesting to study. It says that it should be easy to interface. We can help you in designing the code as it uses I2C.
Enamul
University of Nottingham
enamul4mm@gmail.com

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

I should receive it on friday i will let you know!

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

There is more information including code for arduino that should be adaptable to PIC device on this site!
https://www.adafruit.com/products/391

I don't really care about altitude, but i would like to have the actual barometric pressure in inHg and temperature in &decC

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

Hi Speedy2k,

To save you time, here is a present for you :D merry x-mas
After calling macro get_pressure do the following math:

Code: Select all

pressure = P * 0.01 //pressure in mbar
Best regards,
Mantas
Attachments
i2c sensor macros.zip
BMP085
(12 KiB) Downloaded 458 times
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Wow thanx a lot!! just to make shure, does i need to import every macro you have added to this zip file to my flowchart ?
And if yes is there any procedure to do that correctly ? And finally, Does it handle the temperature side of the sensor too ?

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

Hello Speedy2k,

Yes you have to import every macro but use the (bitwise) macros instead of the ones without the prefix, as far as I remember, Just make sure you select a different interrupt on the initialization macro, as I had it set up for ARM chip, not for pic. But you can just delete it if you want, and not use the interrupt pin, if you don't need a real time system, where you want the super fast conversions, usually faster than 26ms. You can see the loop delay in the get_uval macro where it uses a fixed 26ms delay, but it can be disabled and the loop can be enabled which breaks the loop with interrupt as soon as the conversions are over. As far as it goes for temperatures, it calculates the temperature value needed for pressure calculations, but I never intended to use this value because it is a little bit higher than the real temp, due to electric heat in the sensor itself, thus i use a different TMP102 digital i2C sensor. You just remember to set up the BMP085 address correctly by connecting the SDO to VSS. Or you would have to change the address by yourself. And finally you can choose between 3 oversampling settings, by setting osr value in the the OSR macro. That is it, I spoiled you the fun to scratch you head for a couple of days or more to do it yourself :) good luck with the sensor!

EDIT: almost forgot...don't forget to set up your I2C component correctly, because mine is set up for the ARM chip. And as far as I remember this chip works on 3.3V, and I think PIC's run on 5V so be careful not to fry it and use a logic level converter, but maybe someone who is using PIC can correct me if I am wrong.

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Ok, I have started to work on this, but to be honest, it is my first time a I2C devic and i am completely lost!! This is what i have so far! I am using a PIC18F4685 For now i would just like to show the uptime, temperature in dec celsius and atmospheric pressure, is someone who know can revies this flowchart? It is pretty complicated with so much macro!! Thanx a lot!
Attachments
BMP085_PIC18F4685.fcf
(81.64 KiB) Downloaded 444 times

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

I didn't look at your code, but saying briefly, in the main program you first call macro BMP085_init to initialize sensor registers, as per setup config, and and then create a loop while(1) to create an infinite loop, in which you call BMP085_get_press. And do the rest like i told you in the previous post. As with the temp I will look it up once I have time, cause I pretty busy now.

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Ok i have done a lot of work and i still have a bug!!

Here it is.
I get the BMP085 parameter at start,
"bmp085_get_press"

It goes to the "bmp085_get_ut" macro fine,
so it thru the first "bmp085_read_uval" macro fine and get the RA temperature DATA
the UT value i receive is : 29255
But as soon as it enter the "bmp085_get_up" , it freeze at the first:
----------------------------------------
Call Component Macro:

.ack_nack=MI2C_Transmit_Byte(.slave_address << 1)
----------------------------------------


And even if i try to only call the "bmp085_get_ut" and after the "bmp085_get_temp" macro, i got the perfect value but as soon as i loop a second time on it, it freeze at the first write in the "master_write_i2c" macro. I cannot go thru this macro twice without freezing the code.

I am wired like this:

The SCL pin of the BMP085 to the SCL pin on the PIC (PIN 18)
The SDA pin of the BMP085 to the SDA pin on the PIC (PIN 23)
The EOC pin of the BMP085 to the INT0 pin on the PIC (PIN 33)
The XCLR pin of the BMP085 is left unconnected.

The VIN and GN are connected to +5v and GND

Don't forget i got this breakout board:
http://www.adafruit.com/products/391

So it is 5 volts ready.

I can't understand why i stuck on the second time it try to access the BMP085 sensor.

If someone can help.

I leave the new Flowchart that does this bug.
Attachments
BMP085_PIC18F4685.fcf
(88.53 KiB) Downloaded 409 times

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

Hi,

here is an example. It is made for ARM, but just use the import function from the main menu and you should be fine. Do everything the same and it should work, at least it works for me. Just set up your interrupt correctly in the bmp085_init and the I2C connections. Good luck.

Best regards,
Mantas
Attachments
example.fcf_arm
BMP085 example
(45.9 KiB) Downloaded 373 times
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

No go! It does exactly the same!!

Is there any known bug with the I2C in flowcode for PIC?

It is able to loop thru the write/read cycle twice after that no more ack comming from the BMP085! I have a second sensor here, i will try it to see if it is a sensor problem.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Just for a follow-up, i have tested my second sensor and it does exactly the same thing. But i have found that when i change the frequency setting from the default 100Mhz to 400Mhz, one in a while it does the first loop completely so i have a reading of the temperature and the pressure, but it onever finish the second loop. To make in run normally, when it finnaly goes thru the first loop, i must disconnect and reconnect the sensor voltage so now it can goes to the second loop. I am requesting temperature and pressure update at each 60 seconds. So if i touch nothing once ia while it succeed going thru the first temperature/pressure update, but always fail othe second except if i disconnect the sensor for some seconds between the updates this way i can make it work for some updates. I have tried many custom setting for the I2C frequency and the only one that give me some result is othe 400Mhz. Does someone have any idea what is happening here?

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

One more thing you can try, just to make sure that it is not the fault of the EOC pin, is to disconnect the EOC, disable interrupts and disable delay loop (or just delete it), and use a constant delay of 26ms, in the bmp085_read_uval macro, as you are just sampling every 60s. Let me know how it goes.

Also look up this post, as have seen some post that lead to some fixes on I2C for PIC in v5.4
http://www.matrixmultimedia.com/mmforum ... 46&t=11214

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

I have removed the while loop and put a 26ms delay, i have updated the I2C cal file, and it still does the same problem!!!! It seems to freeze on write!!

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Another update, i got a PIC16F887 laying around so i have tested the code on it! Same thing!! but on this one it always go trhu the first loop and give me 1 pressure/temperature reading, after that it just freeze too! I am running the PIC16887 at 4Mhz, the 18F was at 19.6026Mhz.

It really seems to be a timing issue on the I2C port ? I really don't know where to look next!

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

Can you please upload your updated flowcode file? I will check if everything is ok with the code itself. But it seems that the problem is somewhere else if you get one cycle completed correctly.

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

I haven't change the code. This is the exact same one as on my last post. I have tried it on a PIC16F887 and on this PIC, it seems to always do the first cycle and freeze at the second write. On my PIC18F, once in a while it finish the first cycle when the I2C frequency is set to 400Mhz, if set to anything else, it seems to never finish the frst cycle. Is it possible that i need a read last byte or write last byte to let the sensor know this is the last byte? By the way, i seems to get random value when it finish the first cycle. The pressure should be around 1060mbar over here and the sensor give me back 1700mbar and the temperature is varying from -20 to 20 so there is something wrong in the communication.

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

I would suggest you read about the I2C interface a little bit, on how it works, then study my code on how it is implemented, and using BMP085 datasheet try to follow it. Than try to do some debugging yourself, because I can't help you anymore. Best of luck.

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

I understand! Your help is really appreciated! I will have to take a look at it a little bit more, but i really think there is something in the I2C code. I don't understand why it work a little bit better at 400Mhz then at 100Mhz in the I2C config. I really miss something somewhere. Anyone else as any tought on this?

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Good news! believe it or not, i have found the bug!! It was in the master_readi2c macro the while .N_data > 1 must be while .N_Data > 0. IT seems to loop fine now!!

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Mantas »

Hi,

Good to hear that it worked out for you. Just its's very strange...i have like 5 different i2c sensors, and they all seem to work fine with that macro n>1...well anyway, glad that it worked our for you.

Best regards,
Mantas
Science is my true religion.

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Yep it has worked perfectly for over 8 hours! The only thing i notice is the pressure value is way higher then the advertised atmospheric pressire of my local weather channel.
The weather report say it should be 100.2 kPa but the sensor give me around 170 kPa.
I have read that we must compensate the value. I have searched for formula to do this but without luck. Do you have any idea how to do this?

Speedy2k
Posts: 91
Joined: Mon Aug 06, 2012 5:04 am
Has thanked: 2 times

Re: BMP085 barometric pressure/temperature sensor.

Post by Speedy2k »

Ok, now i got a problem for Ben!! I am strugling with the formula, it seems that on a variable i got a too long uLong number.
So i will post the current value of my sensor. and how i read them to make shure it is ok for a PIC microcontroller.

Sensor EEPROM calibration data:

Code: Select all

AC1 = 7382
AC2 = -1137
AC3 = -14545
AC4 = 33755
AC5 = 24818
AC6 = 21703
B1 = 5498
B2 = 60
MB = -32768
MC = -11075
MD = 5498
This is read from the eeprom and it seems to be good.
After that i read the temperature from the sensor. The temperature is in 16 bit so the sensor send the first 8 bit to the rdata[0] and the last 8 bit to the rdata[1]
Right now the sensor is outside, and when i print the return value not calculated of rdata[0] and rdata[1],

Code: Select all

rdata[0] = 104
rdata[1] = 173
Here i put them togheter, but i am far from shure it is the right way to do it.

Code: Select all

UT = rdata[0] << 8 | rdata[1]
Once done the value of UT is:

Code: Select all

UT = 26817
After that i do the calculation to get true temperature as the datasheet:

Code: Select all

X1 = (UT - AC6) * AC5 >> 15
X2 = (MC << 11) / (X1 + MD)
B5 = X1 + X2
T = ((B5 + 8) >> 4)
At the specified rdata over, i got a t value of 16 so 1.6 degree celcius that is not pretty far from reality! THe temperature seems to be ok. The problem is with the pressure! The pressure value is from 16 to 19 bit depending on the oversampling_setting. So right now let got with a OSS of 0 so the pressure should be 16 bit. so here is the rdata i receive from the sensor:

Code: Select all

OSS = 0
rdata[0] = 169
rdata[1] = 118
rdata[2] = 0
UP = (rdata[0] << 16 | rdata[1] << 8 | rdata[2]) << (8 - oss)
This give me this UP:

Code: Select all

UP = 7733248
I am pretty shure there is an error here. this is how they say to do it on the datasheet!

After that here is the calculation i got to get the true pressure:

Code: Select all

B6 = B5 - 4000
X1 = (B2 * (B6 * B6 / 4096)) >> 11
X2 = AC2 * B6 >> 11
X3 = X1 + X2
B3 = ((AC1 * 4 + X3) << oss + 2) >> 2
B6 = B5 - 4000
X1 = (B2 * (B6 * B6 / 4096)) >> 11
X2 = AC2 * B6 >> 11
X3 = X1 + X2
B3 = ((AC1 * 4 + X3) << oss + 2) >> 2
X1 = AC3 * B6 >> 13
X2 = (B1 * (B6 * B6 >> 12)) >> 16
X3 = ((X1 + X2) + 2) >> 2
ulong = (X3 + 32768)
B4 = (AC4 * ulong) >> 15
ulong = UP
B7 = (ulong - B3) * (50000 >> oss)
If  B7 < 0x80000000 ?
	<TRUE BRANCH>
P = (B7 * 4) / B4
	</TRUE BRANCH>
	<FALSE BRANCH>
P = ((B7 * 2) / B4) * 2
</FALSE BRANCH>
X1 = (P >> 8) * (P >> 8)
X1 = (X1 * 3038) >> 16
X2 = (-7357 * P) >> 16
P = P + ((X1 + X2 + 3791) >> 4)
This is all the calculation i got. And here is the result for each variable on the exact same order. by the way this is the data i have printed on my LCD.

Code: Select all

B6 = -3747
X1 = 100
X2 = 2080
X3 = 2180
B3 = 31708
X1 = 6652
X2 = 287
X3 = 1735
B4 = 35542
Here is the bug i see, the B7 variable is a uLong variable!

Code: Select all

B7 = -1470056640
P = 76238
X1 = 88209
X1 = 4089
X2 = -8559
P = 76195
So the final result is a pressur of 76.195 kPa and this is far from the reality and when there is a change of 1 in the rdata[1] variable, the pressure goes from 4 kPa to 200 kPa, When i am using the value we got in the datasheet, i got the exact same result, but on my exemple here, the B7 ulong variable seems to get over its limit and get to negative value. but why is it getting over its limit value? I am pretty shure that i am not putting the rdata array togheter the good way. I am pretty shure the UP value i got is not OK. what you guy think of it ?

I have attached the flowchart i am using to debug, there is plenty of LCD print, so this is all messy but this is only for debugging. Thanx a lot!
Attachments
ErabliTEK-0_1.fcf
(113.56 KiB) Downloaded 339 times

Post Reply