Kenji Arai / BME280
Revision:
8:4c37112d31cf
Parent:
7:d94871acb463
diff -r d94871acb463 -r 4c37112d31cf BME280.cpp
--- a/BME280.cpp	Tue Jan 15 10:06:32 2019 +0000
+++ b/BME280.cpp	Tue Jan 22 22:18:35 2019 +0000
@@ -74,7 +74,7 @@
     id = getID();
     if (id != 0x60){
         if (address == DEFAULT_SLAVE_ADDRESS){
-            address = DEFAULT_SLAVE_ADDRESS;
+            address = ANOTHER_SLAVE_ADDRESS;
         } else if (address == ANOTHER_SLAVE_ADDRESS){
             address = DEFAULT_SLAVE_ADDRESS;
         }
@@ -155,7 +155,7 @@
     char cmd[4];
 
     if(check_chip() == false){
-        return 100.0f;
+        return -100.0f;
     }
     cmd[0] = 0xfa; // temp_msb
     i2c.write(address, cmd, 1);
@@ -184,7 +184,7 @@
     char cmd[4];
 
     if(check_chip() == false){
-        return 2000.0f;
+        return 0.0f;
     }
 
     cmd[0] = 0xf7; // press_msb
@@ -228,7 +228,7 @@
     char cmd[4];
  
     if(check_chip() == false){
-        return 0.0f;
+        return 120.0f;
     }
 
     cmd[0] = 0xfd; // hum_msb
@@ -276,7 +276,7 @@
     id = getID();
     if (id != 0x60){
         if (address == DEFAULT_SLAVE_ADDRESS){
-            address = DEFAULT_SLAVE_ADDRESS;
+            address = ANOTHER_SLAVE_ADDRESS;
         } else if (address == ANOTHER_SLAVE_ADDRESS){
             address = DEFAULT_SLAVE_ADDRESS;
         }
@@ -346,6 +346,13 @@
     uint32_t raw_data;
     char cmd[8];
 
+    if(check_chip() == false){
+        // If sensor is error then return abnormal data
+        dt->humidity   = 120.0f;
+        dt->temperatue = -100.0f;
+        dt->pressue    = 0.0f;
+        return;
+    }
     // Humidity
     cmd[0] = 0xfd; // hum_msb
     i2c.write(address, cmd, 1);