BMP280 interface
JRoark
Posts: 1,215
Does anyone have any P2 code that reads a BMP280 and returns temperature and pressure that is compatible with Flex?
This blasted thing is just kicking my butt and Bosch is less than helpful. Beer and eternal gratitude is available for all who can help. 🤣
Comments
You, me, and a whole lot of other people have found Bosch less that helpful with this device. It's irritating that they won't show the formulas, except in code.
My experience exactly. And if you ask them about it, they say “just use our libraries!”. And then when I ask for one for a Parallax chip, they get really quiet. 🙈
I got so far with reading the BMP280 written in Taqoz Reloaded, the SD card resident forth system. My code for reading and converting temperature works fine - it checks out with the example values given on page 23 of Bosch's document BST-BMP280-DS001-11. I can read raw pressure OK - raising and lowering the device by an arm's length produces a change in the value, but there's a bug still in my conversion, which produces values that are consistently low. Here's my forth code so far:-
If you're not familiar with forth - think of each word as a call to machine code. This glossary might be helpful too. Download and open it, so that the bookmark sidebar is visible to quickly locate categories of words.
Remember:-
1. A forth word is anything separated by one or more spaces
2. Stack comments e.g. ( n1 n2 -- n3 ) this would indicate two input longs n1 and n2 are needed on the stack and the word consumes them both and leaves n3 on the stack as the result
3. Other comments are preceded by ---
Cheers, Bob, ham radio call G4BBY
Hi
Can you convert spin code?
@avsa242 a prodigious driver writer has this
https://github.com/avsa242/bmp280-spin
Dave
Thanks for the mention, but I wouldn't recommend placing much faith in that...I started that years ago thinking "how hard could it be?" but as Jon pointed out, very. I don't even remember the last time I touched it or what state it was in, sorry (edit: 2018...yikes)
I thought before about maybe trying to use someone's C algorithm as a child object in flexspin, but I haven't really looked into it.
Thanks all for the good input!
I looked at the @avsa242 repo, but I’m up against a steep learning curve as I really struggle with Spin. It just makes no sense to me. I have to support this code eventually and it doesnt seem fair to just steal code blindly with zero comprehension (I’m looking at you Arduino wags. Heheh). I have had good success translating @JonnyMac code into C and BASIC, and he’s indicated he may take swing at this too, so there may be light at the end of this tunnel! Or at least a high-octane dinner for Jon. 🤣
Have you taken another look at the datasheet
@DigitalBob Thank you for posting that data sheet as it is a bit more current than the one I had. Yup, I’ve seen it. Studied it pretty closely. It is closer to the mark, but there are still bugs.
If you stare at that one long enough (just like its predecessors) you’ll find things like this:
That is not an isolated example. There is also the occasional term referenced but not defined.
I’ll take another swing at it this weekend with your improved data sheet (thank you!) and report back. But jeeze, Bosch, why is this so complex and obscure when it could be so simple?!?
I’ll make the following promise: if I get it working, I’ll post the code so nobody ever needs to guess at this mess again. 👍
Well… success! Of a sort. And a story too.
I got the maths working after I had a look at some code from the amazing @JonnyMac. I translated it to BASIC and then I hooked-in some I2C comms in order to use live data. Epic fail. I had been using BMP280’s from a dodgy Amazon vendor and I couldnt get anything like a rational pressure. When I ran the numbers manually by hand, it became clear that my code was working fine but the data being returned from the sensors was junk. ALL THREE SENSORS WERE JUNK.
In desperation I popped-in a BME-680 sensor breakout from Parallax, changed the code accordingly, and it now works flawlessly. (I had avoided this originally thinking it was a much more complex sensor. It really isnt).
So once again I am reminded that there is a good reason to pay top-dollar for this stuff when it comes from a reputable vendor using top-grade parts! Thank you Parallax. And Jon!
Bosch has a library for driving this sensor and it compiles just fine in Flexprop which I have been using.
Here is my github sample: P2 Custom Libraries
They have since released the BME68X library for use with the new BME688 which is a warmed over BME680.
Again to use their GAS sensor you need to use their tools and their compiled libraries to build an air quality sensor. They don't have a library for P2.
They use AI to build a profile for whatever GAS your trying to smell.
The library work just fine with Flexprop and you can read all the sensor values including the GAS sensor which make very little sense.
I did however find a problem with Flexprop I2C driver as it did not work for me. Fortunately, I had built my own which works just fine.
Sample program using Flexprop and Bosch library:
Mike
@iseries Thank you for that! I’ll queue that up this weekend and see if I can improve on what I have. For this design, I need a very accurate pressure and density altitude.
A giggle: in a few weeks I’m leaving for Leadville, CO for a few days. Why? I need to test this creature and all of the code in a real-world “live fire” scenario over 10,000 feet. This should be FUN! 🤣