Amir Chaudhary / Mbed 2 deprecated humidity-temp-pressure

Dependencies:   mbed LoRaWAN-lib SX1276Lib

Files at this revision

API Documentation at this revision

Comitter:
amir_chaudhary
Date:
Mon Jun 27 08:54:36 2022 +0000
Parent:
12:85b3174c8b30
Commit message:
This code measures Vbat, Pressure, Temp and Humiidity

Changed in this revision

app/main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/app/main.cpp	Wed May 25 15:11:42 2022 +0000
+++ b/app/main.cpp	Mon Jun 27 08:54:36 2022 +0000
@@ -1,3 +1,4 @@
+
 #include "mbed.h"
 #include "Si7021.h"
 
@@ -69,7 +70,7 @@
 int main() {
     pc.printf("Starting Pressure/Temp/Humidity Sensor Test..\r\n");
     
-  // PWEN = 1; 
+   PWEN = 1; 
     
     myGreenLed = 1; // LED is ON 
     wait(0.25);
@@ -91,7 +92,7 @@
     for(int i=0; i<5; i++){
         
     myGreenLed = 1; // LED is ON   
-     PWEN = 1;  
+  //   PWEN = 1;  
     LoraPin = 1; 
     I2C1Pin = 1; 
     I2C2Pin = 1; 
@@ -99,7 +100,7 @@
     myGreenLed = 0; // LED is ON
 
     myRedLed = 1; // LED is ON  
-    PWEN = 0;   
+  //  PWEN = 0;   
     LoraPin = 0; 
     I2C1Pin = 0; 
     I2C2Pin = 0; 
@@ -110,22 +111,12 @@
     
     float meas_Vbat = BAT_PIN.read();
     float Vbat = meas_Vbat*Vref;
-    pc.printf("%.03f\n\n\r", Vbat);
+    pc.printf("%.03f\n\r", Vbat);
     
-
+    wait(1);
     count++;
     
     }
-
-    myBlueLed = 1; // LED is ON    
-    wait(1);
-    myBlueLed = 0; // LED is ON    
-    wait(1);
-    
-    myRedLed = 1; // LED is ON    
-    wait(1);
-    myRedLed = 0; // LED is ON    
-    wait(1);
         
     wait(1);
     
@@ -135,7 +126,7 @@
     char reset_command[1] = {0x06};
     
     // Reset the pressure sensor
-    pc.printf("Resetting Pressure Sensor...\r\n");
+ //   pc.printf("Resetting Pressure Sensor...\r\n");
     if ( spd800_i2c.write(0x00, reset_command, 1) != 0 ) {
         pc.printf("RESET FAILED!\r\n");        
     }
@@ -144,73 +135,69 @@
     si7021_power_pin = 1;
 //  Si7021 si7021 = Si7021(PB_9, PB_8);
     Si7021 si7021 = Si7021(PB_11, PB_10);
-    
-    myGreenLed = 1; // LED is ON 
-    wait(0.05);
-    myGreenLed = 0; // LED is ON    
-    wait(0.05);     
-    
-    myBlueLed = 1; // LED is ON    
-    wait(0.05); 
-    myBlueLed = 0; // LED is ON  
-    wait(0.05); 
-    
-    
+     
     wait(1);
     
-    
+    count=0;  
+                 
+                 
     // Take a few manual measurements
     while( true ) {
         
         
-        pc.printf("\r\n\n");
-        pc.printf("Measuring Pressure...\r\n");
+    pc.printf("%d\t",count);
+    float meas_Vbat = BAT_PIN.read();
+    float Vbat = meas_Vbat*Vref;
+    pc.printf("%.03f\n\r", Vbat);
+    
+    wait(1);
+    count++;  
+        
+        
+        
+    //    myRedLed = 1; // LED is ON  
+    //    wait(0.1);
+        myRedLed = 0; // LED is ON 
+        
+        LoraPin = 0; 
+        I2C1Pin = 0; 
+        I2C2Pin = 0; 
+        
+        wait(1);
+           
+ //       pc.printf("\r\n\n");
+ //       pc.printf("Measuring Pressure...\r\n");
         if ( spd800_i2c.write((0x25 << 1), single_measure_command, 2) != 0 ) {
             pc.printf("FAILED TO WRITE TO PRESSURE SENSOR\r\n");
         }
         wait(1);
         
                
-        pc.printf("Measuring Temp/Humidity...\r\n");
+  //      pc.printf("Measuring Temp/Humidity...\r\n");
         if ( !si7021.check() ) {
-            pc.printf("TEMP/HUMIDITY SENSOR NOT WORKING\r\n");
+  //          pc.printf("TEMP/HUMIDITY SENSOR NOT WORKING\r\n");
         } else {
             si7021.measure();
         }
         
         
-        pc.printf("Humidity: %d\r\n", si7021.get_humidity());
-        pc.printf("Temperature: %d\r\n", si7021.get_temperature());
-        pc.printf("Pressure: %f\r\n", read_pressure_measurement());
+  //      pc.printf("Humidity: %d\r\n", si7021.get_humidity());
+  //      pc.printf("Temperature: %d\r\n", si7021.get_temperature());
+ //       pc.printf("Pressure: %f\r\n", read_pressure_measurement());
         wait(1);
+     
         
-        myGreenLed = 1; // LED is ON 
-        wait(0.05);
-        myGreenLed = 0; // LED is ON    
-        wait(0.05);     
+
+        myGreenLed = 1; // LED is ON   
+        wait(0.1);
+        myGreenLed = 0; // LED is ON     
         
-        myBlueLed = 1; // LED is ON    
-        wait(0.05); 
-        myBlueLed = 0; // LED is ON  
-        wait(0.05); 
-    
+        LoraPin = 1; 
+        I2C1Pin = 1; 
+        I2C2Pin = 1;     
+        wait(54);
 
     }
-    
-    
-    
-    
-    /*// Start Pressure Measurements
-    pc.printf("Starting Measurements...\r\n");
-    if ( i2c.write((0x25 << 1), cont_measure_command, 2) != 0 ) {
-         pc.printf("START COMMAND FAILED!\r\n");
-    }
-    wait(1);
-    
-    while( true ) {
-         pc.printf("%f\r\n", read_measurement());  
-        wait(1);
-    }*/
-    
+ 
       
-}
+}
\ No newline at end of file