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.
Dependents: LPC1768-GPS-FUSION-17102018-1
Fork of BME280 by
Revision 5:691e06db489f, committed 2016-11-29
- Comitter:
- jont
- Date:
- Tue Nov 29 18:54:29 2016 +0000
- Parent:
- 4:ddcaa259e65b
- Commit message:
- Replaced original getTemperature Routine as it was returned strange values
Changed in this revision
| BME280.cpp | Show annotated file Show diff for this revision Revisions of this file |
| BME280.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/BME280.cpp Tue May 12 13:32:09 2015 +0000
+++ b/BME280.cpp Tue Nov 29 18:54:29 2016 +0000
@@ -5,6 +5,10 @@
* @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 "BME280 temperature, humidity and pressure sensor module" from Switch Science
* https://www.switch-science.com/catalog/2236/
*
@@ -100,6 +104,13 @@
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);
}
+
+ /*
+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 BME280::getTemperature()
{
uint32_t temp_raw;
@@ -124,6 +135,45 @@
return (tempf/100.0f);
}
+*/
+
+// new version of getTemperature jont@ninelocks.com November 2016
+float BME280::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 BME280::getPressure()
{
--- a/BME280.h Tue May 12 13:32:09 2015 +0000
+++ b/BME280.h Tue Nov 29 18:54:29 2016 +0000
@@ -1,6 +1,5 @@
/**
* BME280 Combined humidity and pressure sensor library
- *
* @author Toyomasa Watarai
* @version 1.0
* @date 06-April-2015
@@ -10,6 +9,8 @@
*
* For more information about the BME280:
* http://ae-bst.resource.bosch.com/media/products/dokumente/bme280/BST-BME280_DS001-10.pdf
+ *
+ *
*/
#ifndef MBED_BME280_H
@@ -18,7 +19,7 @@
#include "mbed.h"
//#define _DEBUG
-#define DEFAULT_SLAVE_ADDRESS (0x76 << 1)
+#define DEFAULT_SLAVE_ADDRESS (0x77 << 1)
#ifdef _DEBUG
extern Serial pc;
@@ -72,7 +73,7 @@
*
*/
float getTemperature(void);
-
+
/** Read the current pressure value (hectopascal)from BME280 sensor
*
*/
