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.