BME280 Combined humidity and pressure sensor library

Dependents:   mDot_TTN_OTAA_Node LoraGPSLogger mDot_TTN_OTAA_Node_send_data_as_string

Fork of BME280 by Toyomasa Watarai

Files at this revision

API Documentation at this revision

Comitter:
SomeRandomBloke
Date:
Wed Dec 14 11:13:38 2016 +0000
Parent:
5:64b7a81c61e4
Commit message:
Removed debugs, updated constructors

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	Wed May 11 06:17:58 2016 +0000
+++ b/BME280.cpp	Wed Dec 14 11:13:38 2016 +0000
@@ -15,8 +15,8 @@
 #include "mbed.h"
 #include "BME280.h"
 
-BME280::BME280(PinName sda, PinName scl, char slave_adr)
-    :
+
+BME280::BME280(PinName sda, PinName scl, char slave_adr) :
     i2c_p(new I2C(sda, scl)), 
     i2c(*i2c_p),
     address(slave_adr),
@@ -25,8 +25,7 @@
     initialize();
 }
 
-BME280::BME280(I2C &i2c_obj, char slave_adr)
-    :
+BME280::BME280(I2C &i2c_obj, char slave_adr) :
     i2c_p(NULL), 
     i2c(i2c_obj),
     address(slave_adr),
@@ -99,6 +98,16 @@
  
     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);
 }
+
+bool BME280::deviceExists() {
+    char cmd[4];
+ 
+    cmd[0] = 0xd0; // device ID
+    i2c.write(address, cmd, 1);
+    i2c.read(address, &cmd[1], 1);
+
+    return ( cmd[1] == 0x60 );
+}
  
 float BME280::getTemperature()
 {
--- a/BME280.h	Wed May 11 06:17:58 2016 +0000
+++ b/BME280.h	Wed Dec 14 11:13:38 2016 +0000
@@ -67,6 +67,12 @@
      *
      */
     void initialize(void);
+    
+    /** Test if device exists on the bus
+     *
+     * 
+     */
+    bool deviceExists(void);
 
     /** Read the current temperature value (degree Celsius) from BME280 sensor
      *