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.
Diff: BME280.cpp
- Revision:
- 7:d94871acb463
- Parent:
- 6:f94ffb546799
- Child:
- 8:4c37112d31cf
--- a/BME280.cpp Sat Dec 29 05:49:55 2018 +0000
+++ b/BME280.cpp Tue Jan 15 10:06:32 2019 +0000
@@ -32,8 +32,8 @@
*
* http://www.page.sannet.ne.jp/kenjia/index.html
* http://mbed.org/users/kenjiArai/
- * Created: November 21st, 2018
- * Revised: December 29th, 2018
+ * Started: November 21st, 2018
+ * Revised: January 5th, 2019
*/
#include "mbed.h"
@@ -345,7 +345,26 @@
void BME280::getAll_compensated_data(BME280_Data_TypeDef *dt) {
uint32_t raw_data;
char cmd[8];
-
+
+ // Humidity
+ cmd[0] = 0xfd; // hum_msb
+ i2c.write(address, cmd, 1);
+ i2c.read(address, &cmd[1], 2);
+ raw_data = (cmd[1] << 8) | cmd[2];
+ double var_H;
+ var_H = (((double)t_fine) - 76800.0);
+ var_H = (raw_data - (((double)dig_H4) * 64.0 +
+ ((double)dig_H5) / 16384.0 * var_H)) *
+ (((double)dig_H2) / 65536.0 * (1.0 +
+ ((double)dig_H6) / 67108864.0 * var_H *
+ (1.0 + ((double)dig_H3) / 67108864.0 * var_H)));
+ var_H = var_H * (1.0 - ((double)dig_H1) * var_H / 524288.0);
+ if (var_H > 100.0) {
+ var_H = 100.0;
+ } else if (var_H < 0.0) {
+ var_H = 0.0;
+ }
+ dt->humidity = var_H;
// Temperatue
cmd[0] = 0xfa; // temp_msb
i2c.write(address, cmd, 1);
@@ -382,26 +401,49 @@
var2 = p * ((double)dig_P8) / 32768.0;
p = p + (var1 + var2 + ((double)dig_P7)) / 16.0;
dt->pressue = p / 100.0;
- // Humidity
- cmd[0] = 0xfd; // hum_msb
+}
+
+void BME280::frequency(int hz)
+{
+ i2c.frequency(hz);
+}
+
+#if 0
+double BME280::calcAltitude_relative(double ref_press)
+{
+ double x1, x2;
+ uint32_t raw_data;
+ char cmd[8];
+#if 0
+ // Pressue
+ cmd[0] = 0xf7; // press_msb
i2c.write(address, cmd, 1);
- i2c.read(address, &cmd[1], 2);
- raw_data = (cmd[1] << 8) | cmd[2];
- double var_H;
- var_H = (((double)t_fine) - 76800.0);
- var_H = (raw_data - (((double)dig_H4) * 64.0 +
- ((double)dig_H5) / 16384.0 * var_H)) *
- (((double)dig_H2) / 65536.0 * (1.0 +
- ((double)dig_H6) / 67108864.0 * var_H *
- (1.0 + ((double)dig_H3) / 67108864.0 * var_H)));
- var_H = var_H * (1.0 - ((double)dig_H1) * var_H / 524288.0);
- if (var_H > 100.0) {
- var_H = 100.0;
- } else if (var_H < 0.0) {
- var_H = 0.0;
- }
- dt->humidity = var_H;
+ i2c.read(address, &cmd[1], 3);
+ raw_data = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4);
+ x2 = 1.0 / 5.2553026;
+ x1 = pow((ref_press / (double)raw_data), x2) - 1.0;
+ // Temperatue
+ cmd[0] = 0xfa; // temp_msb
+ i2c.write(address, cmd, 1);
+ i2c.read(address, &cmd[1], 3);
+ raw_data = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4);
+ x2 = x1 * ((double)raw_data + 273.15) / 0.0065;
+ return x2;
+#else
+ cmd[0] = 0xf7; // press_msb
+ i2c.write(address, cmd, 1);
+ i2c.read(address, &cmd[1], 3);
+ raw_data = (cmd[1] << 12) | (cmd[2] << 4) | (cmd[3] >> 4);
+ x1 = pow(((double)raw_data / ref_press), 0.190294957);
+ x2 = 44330.0 * (1.0 - x1);
+ return x2;
+ /*
+ double altitude =
+ 44330.0 * (1.0 - pow(pressure / MEAN_SEA_LEVEL_PRESSURE, 0.190294957));
+ */
+#endif
}
+#endif
#if 0
double calcAltitude(float pressure,float temperature)
@@ -421,4 +463,4 @@
44330.0 * (1.0 - pow(pressure / MEAN_SEA_LEVEL_PRESSURE, 0.190294957));
return altitude;
}
-#endif
\ No newline at end of file
+#endif