Chip: Atmega 2561
Problem: I get wrong data from my Bmp280 sensor when I want to know the temperature. To be exact, i even have an inverted value when i make the sensor warmer the displayed temperature becomes colder. the calculation works I tested it with sample numbers. The I2C interface also works, after the id check. The only 2 things that could cause errors are the conversion to the variables or the config.
I hope someone can help me with this
Solved! Go to Solution.
Thanks for your inquiry.
You can directly use BMP280 API source code at https://github.com/BoschSensortec/BMP280_driver in your project to get final pressure value in the unit of Pa and final temperature value in the unit of degree C.
Or you can refer to the attached "sample_calculation_BMP280.xls" to manually input dig_T1, etc other NVM calibration parameters and then manually input BMP280 raw data UT and UP. The Excel file will calculate the FT and FP for you so that you can check if your conversion is correct or not.
I already know this library and I also have the calculations from it.The part that confuses me is that I get two wrong values for dig_T3 and Adc_T, the others are "fine". dig_T3 confuses me the most because dig_T2 and dig_T1 are OK. Attached is a screenshot of the debugger. By the way the measured temperature is ~23°C.
And even if I could use the library I prefer to write the code I use "myself" because.
1. I am in an apprenticeship and have the time to write code myself and it also brings me more.
2. according to everyone who knows programming in my environment, I should not use anyone else's library without understanding it, which I don't do with the one you provide.
3. i also want to find my mistake so that something similar doesn't happen to me again in the future.
I hope you understand and don't take this badly.
It is ok that you write your own code to operate BMP280 sensor without using library or API. You may refer to Arduino sample code at https://create.arduino.cc/projecthub/SurtrTech/bmp280-measure-temperature-pressure-and-altitude-e1c8... for more information.
From your screenshot, ADC_T should be unsigned integer and dig_T3 should be a negative integer.
Here is what you could do:
1. Check your I2C read function to see if you can always get BMP280 chip_ID value of 0x58 from register 0xD0. If yes, then your I2C read function is working fine.
2. Check your I2C write function. For example you can write value of 0x33 to register 0xF4 to configure BMP280 to be in normal mode with ost_t = x1 and osr_p = x8. Then you can read register 0xF4 to see if the value of 0x33 has been written to this register successfully or not. If yes, then your I2C write function is working fine.
3. Check your I2C burst read function. You can read BMP280 3 bytes pressure data registers from 0xF7 to 0xF9 in one I2C transaction. Or you can read 6 bytes pressure data and temperature data from data registers 0xF7 to 0xFC in one single I2C transaction. And then you can get UT and UP from these 6 bytes data.
4. Check NVM parameters read function.
5. Check if you can convert BMP280 UT and UP raw data together with NVM parameters to correct FT and FP.