use BMP 280 without a dedicated library?

I would like to write a simple code to read pressure (and obtain altitude from that), without calling a library dedicated to this sensor.

I am on Arduino Nano and BMP 280 GY. I wired it on I2C but I have nothing against spi.

I am not concerned about the accuracy, but about simplicity.

Thank you for reference/ideas!

I realized that I am in a wrong section after posting. I do not know how to move the topic.

What is the problem ?
You can read the datasheet to see how to use it. It does not give the baromic pressure. It gives data and calculations are needed to calculate the pressure. That is what the libraries do.

If you want simplicity, then perhaps you can find a sensor or a module that does the calculations itself.

This section is fine by me.

You could look at the bmp280 library and copy/steal the bits you need. But why bother? Just use the library as it is.

Pete

@ Keopel

I cant figure out the computation method from the library.

MPL115A2 - I2C is an alternative but is 3 times more expensive than BPM280 and less accurate. Besides, I do not know how easy is to use.

@ el_supremo

Nice idea! But I need a better way to edit the library than wordpad. I did some search, but nor very successful.

You want simple? Use the library!

Using the BMP280 requires several 32 or 64 bit calculations. The Adafruit library was written by some very good programmers, if you cannot figure it out, what leads you to think you can do it easier/better/more simply?

Make a coherent argument why you shouldn’t use the library and you might get some help, otherwise, don’t expect to be handed a solution for an problem that doesn’t need to be solved, a problem that you’ve created for yourself by refusing to use the ready made solution. If you want to do everything yourself, abandon the Arduino platform altogether. Otherwise, exploit its strengths, one of many being the available libraries.

@avr_fred

One of the strength of the Arduino platform is to help people learning.

This is achieved if a beginner understands - at least partially - what the Arduino does.

"Understanding" is different from "doing the best". I fully agree that the libraries are written by excellent programmers. But this does not go in line with the learning purposes.

Therefore the aim is learning, not rapid achievements of the expected results, no matter how (in other words in a "black box" approach).

You may agree that most projects are abandoned and one of the reasons are the confusion between "being in principle possible" and "feasible with what I know".

+++

Once a beginner understands what is all about, then he/she can move to the more advanced projects. That is the principle of gradual learning.

In this sense, a library is not a solution, but a problem in itself, because it prevents people to make the effort to understand. At least that is the way I look to this. And my personal opinion.

+++

The rows above does not mean I am against libraries. I recognizes their strenghts and I use them. What I am saying is that I will never learn Arduino if I relay on libraries alone. The opposite is also true: I will never learn Arduino if I code everything on my own.

Therefore, my approach is to code myself whenever possible (at my level of knowledge) and go for libraries only in more complicate situations or when it is clear that alternatives are to time-consuming or to risky in terms of use of resources.

This is the main reason I asked for an alternative to the library.

The second reason is that in this particular case, the avaialble libraries looks like difficult to adapt to a particular version of the sensor. I was not successful in using neither Adafruit library, nor in the Sparkfun one. The internet is also full of mixed experience. I spend three days in searching and experimenting. I ended up in using the Sensor I2C library, which works for me.

@falexandru, you can learn programming by writing good sketches and selecting good libraries.

The BMP280 requires complex calculations and it is really not very usefull to completely understand it. Every sensor has its own special things. Some sensors have a processing unit inside.

Did you read the datasheet and other documentation ? That is what everyone else does when trying to understand a component.
https://www.bosch-sensortec.com/bst/products/all_products/bmp280

Bosch provided code to interface the BMP280. You can make it really really hard for yourself and use that to start with: https://github.com/BoschSensortec/BMP280_driver/blob/master/bmp280.c :o

If you don't want to use the code from Bosch either, maybe you can interview the designer of the sensor and ask him or her how you can interface it without using pre-existing code ::slight_smile:

I hope you can see what I'm trying to say. In my opinion it is complete and utter waste of time, trying to make the BMP280 work from scratch.

@Keopel - in fact that is what I wanted to know: whether it is possible to code the sensor in a reasonable time and with basic coding (medium?) knowledge, without a library.

Also, libraries are not all born equal :-). Some are easier to understand than others.

I read the datasheet. Looks very complex, indeed. But I wanted to be sure. Past summer I spent few weeks in EEPROMs to find it is easier to work with them than usually claimed.

Sometimes is our approach which makes things easy or difficult, not the things themselves.

The reason why I am so verbal is that I am planning to spend more time on Arduino - and on forum equally.

Learn about finite state machines, Blink Without Delay, State Change Detection, ring-buffers, the Arduino Stream class, and so on, you know, the normal Arduino programming things :wink:

I have to warn you: some want to understand the Arduino Wire library for I2C. Some even try to make their own I2C library. Don’t be temped to do that, it is so much worse than the BMP280 library.

@Koepel

Thanks for warning about I2C!

I still have a long way ahead on the "regular" Arduino path. I come from the old school procedural languages (after a very long break), but that is not necessarily an advantage: the object-oriented looks to me like a complication, at least for small applications and I have problems in undestanding why I need so many lines just to read some values. The functions are not from IDE, but from some mysterious outside set - which I cant identify, no list of functions and arguments, I have to discover them one by one.

That thing of libraries drives me crazy sometime. It is said: "just call that library". Maybe half of the libraries I use raised me problems. I refrain myself in poping up in the forum every time I got errors.

Another point is that sensors labeled identically are many times different animals.

I am mainly into sensor work for the moment.

{OT} I hate the BMP sensor! :slight_smile:

Yes, installing and using libraries can be a problem. Feel free to ask for help.

In the Arduino IDE is a Library Manager, try to use that first to find a library. But not every library is for every Arduino board. Some libraries conflict with other libraries, because they use the same timers or interrupts.

Some libraries are only on Github.com, there is button on Github to download a *.zip file. You can use the Arduino IDE to install that *.zip file.

After installing a library with the Arduino IDE, start with the examples that have been added to the menu. Sometimes the examples and the source of the library is all there is.

For documentation you need some luck. In the Library Manager you will find a link to a webpage for every library. Sometimes that webpage is the library on Github, and sometimes the "wiki" of Github has documentation.

This is a good example of a library documentation: https://github.com/olikraus/ucglib/wiki.