Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of BMP280 by
Revision 8:b1fcd102ff93, committed 2016-11-29
- Comitter:
- jont
- Date:
- Tue Nov 29 18:56:16 2016 +0000
- Parent:
- 7:c72b726c7dc9
- Commit message:
- Replaced original getTemperature Routine as it was returned strange values
Changed in this revision
| BMP280.cpp | Show annotated file Show diff for this revision Revisions of this file | 
| BMP280.h | Show annotated file Show diff for this revision Revisions of this file | 
--- a/BMP280.cpp	Tue Apr 19 02:03:35 2016 +0000
+++ b/BMP280.cpp	Tue Nov 29 18:56:16 2016 +0000
@@ -5,6 +5,11 @@
  *  @version 1.0
  *  @date    06-April-2015
  *
+ *  29 November 2016 
+ *  Toyomasa Watarai code Modified  by jon trinder jont@ninelocks.com 
+ *  readtemperature routine replaced
+ *
+ *
  *  Library for "BMP280 temperature, humidity and pressure sensor module" from Switch Science
  *    https://www.switch-science.com/catalog/2236/
  *
@@ -100,8 +105,10 @@
     DEBUG_PRINT("dig_H = 0x%x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x\n", dig_H1, dig_H2, dig_H3, dig_H4, dig_H5, dig_H6);
 */
 }
+ /*
  
-float BMP280::getTemperature()
+ this gives a weird value, one day maybe I will debug it jt
+ float BMP280::getTemperature()
 {
     uint32_t temp_raw;
     float tempf;
@@ -125,6 +132,52 @@
  
     return (tempf/100.0f);
 }
+ */
+ 
+/* 
+As Thomas routine was giving me weird values I rewrote it to look mostly like the adafruit 
+arduino code, which in turn is a lot like the bosch datasheet 
+jon Trinder
+*/
+
+
+float BMP280::getTemperature()
+{
+    int32_t var1, var2, T;
+    int32_t adc_T;
+    float temp_as_float;
+    char cmd[4];
+    cmd[0] = 0xfa; // temp_msb
+    i2c.write(address, cmd, 1);
+    i2c.read(address, &cmd[1], 3);
+
+    //jons slow painful shifting of bits to make it readable
+    adc_T = cmd[1];
+    adc_T <<= 8;
+    adc_T |= cmd[2];
+    adc_T <<= 8;
+    adc_T |= cmd[3];
+     
+    //from here more or less same as ada and bosch
+ 
+    adc_T >>= 4;
+    
+    var1  = ((((adc_T>>3) - ((int32_t)dig_T1 <<1))) *
+       ((int32_t)dig_T2)) >> 11;
+    
+    var2  = (((((adc_T>>4) - ((int32_t)dig_T1)) *
+         ((adc_T>>4) - ((int32_t)dig_T1))) >> 12) *
+       ((int32_t)dig_T3)) >> 14;
+    
+    t_fine = var1 + var2;
+    
+    T  = (t_fine * 5 + 128) >> 8;
+    temp_as_float = T/100.0;
+    return temp_as_float;   
+}
+
+
+
  
 float BMP280::getPressure()
 {
--- a/BMP280.h	Tue Apr 19 02:03:35 2016 +0000
+++ b/BMP280.h	Tue Nov 29 18:56:16 2016 +0000
@@ -72,7 +72,7 @@
      *
      */
     float getTemperature(void);
-
+    float getTemperatureJT(void); //see if we can fix calc
     /** Read the current pressure value (hectopascal)from BME280 sensor
      *
      */
    