Barometric Pressure Sensor / Wrong pressure and altitude output with TinyZero

WillemH

  • Jr. Member
  • **
    • Posts: 5
    • View Profile
Reuse of a sketch with standard BMP280 library files BMP280.cpp and BMP280.h on a TinyZero with Combo Sensor TinyShield gave instable pressure and altitude measurements.
It turned out that reading of the compensation parameters (in BMP280.cpp) goes wrong for negative BMP280 chip parameters.
The BMP280 datasheet states that 10 of the 12 parameters have to be interpreted as signed short (so signed 16 bit).
However in BMP280.h the related variables are declared as int.
This works well for TinyDuino, but for TinyZero int is 32 bit. This means that in case of TinyZero the negative values are read as positive ones (between 32768 and 65535), leading to wrong compensations, e.g. to barometric pressure even outside the interval of 800 - 1200 mBar.

Different solutions are possible:
- changing the declaration of the signed parameters from int to short (in BMP280.h). In this case also readInt has to be adapted in BMP280.cpp and BMP280.h.
- logging the parameters and including these as constants in BMP280.cpp. The normal parameter reading process in BMP280.cpp has to be blocked.
- check the read (signed) parameters for values > 32767 and if true reduce with 65536. This is only useful for TinyZero.

I have checked the two first solutions and both are working properly with TinyZero (and also with TinyDuino).
My preference is the first solution because it is correcting the real error.
However, the second one provides additional insight in the parameters of different BMP280 chips.

I think it would be good to update the BMP280 Arduino Library to avoid problems with TinyZero.


lennevia

  • Administrator
  • Sr. Member
  • *****
    • Posts: 87
    • View Profile
Hello,

Thanks for the investigation and fix you found!

If you would like, you can submit a pull request for the software change you talked about on the GitHub repository: https://github.com/TinyCircuits/TinyCircuits-TinyShield-Sensor-ASD2511/tree/master/examples/Barometric-Pressure_TinyShield_example

Or, you can attach the code here to be tested.

Thank you for your time!

Réna


WillemH

  • Jr. Member
  • **
    • Posts: 5
    • View Profile
Réna,

thanks for your reaction.
Herewith the code related to the first solution
(- changing the declaration of the signed parameters from int to short (in BMP280.h). In this case also readInt has to be adapted in BMP280.cpp and BMP280.h.)

In fact only three changes in total related to change of signed parameters, two in BMP280.h and one in BMP280.cpp.
See attachments.

It is perhaps cleaner to change the declaration of the unsigned parameters too, but not necessary, so I have not included it.

Willem


lennevia

  • Administrator
  • Sr. Member
  • *****
    • Posts: 87
    • View Profile
Hello Willem,

Got the code fix pushed so it should be fixed across everything now.

Thanks again for finding that!

Réna


WillemH

  • Jr. Member
  • **
    • Posts: 5
    • View Profile
Hello Réna,

Many thanks for pushing the code fix.
The updated BMP280 Arduino Library now gives stable results for both TinyZero and TinyDuino with comparable output for two different shields with BMP280.
So issue has been solved.

Willem


WillemH

  • Jr. Member
  • **
    • Posts: 5
    • View Profile
Just an additional remark.

It would be logical that other SAMD based processors than TinyZero could have given comparable wrong pressure and altitude results in case of negative BMP280 chip parameters.

For instance, for the problem described as ".The altimeter readings I get on the barometer are totally different on the TinyScreen+ and make no sense. "  in "Skydive Altimeter on TinyScreen and Tinyscreen+ ", see User Projects / Code examples September 17, 2018, this probably has been the main cause as the SAMD of the Tinyscreen+ also has 32 bit int.

So the recent update of BMP280.h and  BMP280.cpp should also solve this problem.

Willem


 

SMF spam blocked by CleanTalk