AND / Mbed 2 deprecated Sensor_BME680_lowLevel

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
christodoulos
Date:
Mon May 18 10:33:49 2020 +0000
Parent:
6:10523c9e9b68
Commit message:
BME680 low level code

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-os.lib Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri May 01 14:30:25 2020 +0000
+++ b/main.cpp	Mon May 18 10:33:49 2020 +0000
@@ -6,37 +6,26 @@
 int main()
 {
     ble.baud(9600);
-//    char rId[1]; //id read
-    int addr=0xEC; //8bit slave address
+    int BMEaddr=0xEC; //8bit slave BMEaddress
 
     char wHum[2];
     wHum[0]=0x72; //humidity register
     wHum[1]=0x1;//
     char rHum[1];
 
-    bme.write(addr,wHum,2);
-    bme.read(addr,rHum,1);
-    ble.printf("Hum: %x\n",rHum[0]);
+    bme.write(BMEaddr,wHum,2);
+    bme.read(BMEaddr,rHum,1);
+    //ble.printf("Hum: %x\n",rHum[0]);
     wait(0.1);
-    
-//    char wTemp[2]; 
-//    wTemp[0]=0x74;//measurement register
-//    wTemp[1]=0x40; //01000000
-//    char rTemp[1];
-//    
-//    bme.write(addr,wTemp,2);
-//    bme.read(addr,rTemp,1);
-//    ble.printf("%x\n",rTemp[0]);
-//    wait(0.1);
-    
+        
     char wPres[2]; 
     wPres[0]=0x74;//measurement register
     wPres[1]=0x54; //01010100 (kept the temperature)
     char rPres[1];
     
-    bme.write(addr,wPres,2);
-    bme.read(addr,rPres,1);
-    ble.printf("Temp and pres: %x\n",rPres[0]);
+    bme.write(BMEaddr,wPres,2);
+    bme.read(BMEaddr,rPres,1);
+    //ble.printf("Temp and pres: %x\n",rPres[0]);
     wait(0.1);
     
     char wWait[2]; 
@@ -44,9 +33,9 @@
     wWait[1]=0x59; //100 ms
     char rWait[1];
     
-    bme.write(addr,wWait,2);
-    bme.read(addr,rWait,1);
-    ble.printf("Wait: %x\n",rWait[0]);
+    bme.write(BMEaddr,wWait,2);
+    bme.read(BMEaddr,rWait,1);
+    //ble.printf("Wait: %x\n",rWait[0]);
     wait(0.1);
     
     //GET HEAT SETTING PARAMETERS
@@ -69,38 +58,38 @@
     wHV[0]=0x00;
     char rHV[1];
     
-    bme.write(addr,wg1,1);
-    bme.read(addr,rg1,1);//get g1
+    bme.write(BMEaddr,wg1,1);
+    bme.read(BMEaddr,rg1,1);//get g1
     int g1=rg1[0];
-    ble.printf("G1 hex: %x, G1 int: %d\n",rg1[0], g1);
+    //ble.printf("G1 hex: %x, G1 int: %d\n",rg1[0], g1);
     wait(0.1);
     
-    bme.write(addr,wg2M,1);
-    bme.read(addr,rg2M,1);//get g2m
+    bme.write(BMEaddr,wg2M,1);
+    bme.read(BMEaddr,rg2M,1);//get g2m
     
-    bme.write(addr,wg2L,1);
-    bme.read(addr,rg2L,1);//get g2l
-    ble.printf("G2M hex: %x, G2L hex: %x\n",rg2M[0], rg2L[0]);
+    bme.write(BMEaddr,wg2L,1);
+    bme.read(BMEaddr,rg2L,1);//get g2l
+    //ble.printf("G2M hex: %x, G2L hex: %x\n",rg2M[0], rg2L[0]);
     int g2=((rg2M[0]<<8)+rg2L[0]);
-    ble.printf("G2 hex: %x, G2 int: %d\n",g2, g2);
+    //ble.printf("G2 hex: %x, G2 int: %d\n",g2, g2);
     wait(0.1);
     
-    bme.write(addr,wg3,1);
-    bme.read(addr,rg3,1);//get g3
+    bme.write(BMEaddr,wg3,1);
+    bme.read(BMEaddr,rg3,1);//get g3
     int g3=rg3[0];
-    ble.printf("G3 hex: %x, G3 int: %d\n",rg3[0],g3);
+    //ble.printf("G3 hex: %x, G3 int: %d\n",rg3[0],g3);
     wait(0.1);
     
-    bme.write(addr,wHR,1);
-    bme.read(addr,rHR,1);//get heating range
+    bme.write(BMEaddr,wHR,1);
+    bme.read(BMEaddr,rHR,1);//get heating range
     int HR=((rHR[0]<<2)>>6);
-    ble.printf("HR hex: %x, HR int: %d\n",rHR[0], HR);
+    //ble.printf("HR hex: %x, HR int: %d\n",rHR[0], HR);
     wait(0.1);
     
-    bme.write(addr,wHV,1);
-    bme.read(addr,rHV,1);//get g3
+    bme.write(BMEaddr,wHV,1);
+    bme.read(BMEaddr,rHV,1);//get g3
     int HV=rHV[0];
-    ble.printf("HV hex: %x, HV int: %d\n",rHV[0], HV);
+    //ble.printf("HV hex: %x, HV int: %d\n",rHV[0], HV);
     wait(0.1);
     
     double var1=(g1/16.0)+49.0;
@@ -109,7 +98,7 @@
     double var4 = var1 * (1.0 + (var2 *3000)); //target temp 300c
     double var5= var4 + (var3 * 24.0);//ambient 24c
     uint8_t heat=(3.4 * ((var5 * (4.0 / (4.0 + HR)) * (1.0/(1.0 +(HV * 0.002)))) - 25));
-    ble.printf("Re heat: %d\n",heat);
+    //ble.printf("Re heat: %d\n",heat);
     wait(0.1);
     
     //END OF HEAT SETTING PARAMETERS
@@ -119,9 +108,9 @@
     wRes[1]=0x59; //???
     char rRes[1];
     
-    bme.write(addr,wRes,2);
-    bme.read(addr,rRes,1);
-    ble.printf("Heater resistance: %x\n",rRes[0]);
+    bme.write(BMEaddr,wRes,2);
+    bme.read(BMEaddr,rRes,1);
+    //ble.printf("Heater resistance: %x\n",rRes[0]);
     wait(0.1);
     
     char wCG[2];  
@@ -129,9 +118,9 @@
     wCG[1]=0x0; 
     char rCG[1];
     
-    bme.write(addr,wCG,2);
-    bme.read(addr,rCG,1);
-    ble.printf("Control gas: %x\n",rCG[0]);
+    bme.write(BMEaddr,wCG,2);
+    bme.read(BMEaddr,rCG,1);
+    //ble.printf("Control gas: %x\n",rCG[0]);
     wait(0.1);
     
     char wRG[2];  
@@ -139,16 +128,16 @@
     wRG[1]=0x10; 
     char rRG[1];
     
-    bme.write(addr,wRG,2);
-    bme.read(addr,rRG,1);
-    ble.printf("Run gas: %x\n",rRG[0]);
+    bme.write(BMEaddr,wRG,2);
+    bme.read(BMEaddr,rRG,1);
+    //ble.printf("Run gas: %x\n",rRG[0]);
     wait(0.1);
     
     
 
 
 
-    wPres[1]=0x55; //01010100 (kept the temperature and prssure, enabled measurement )
+    wPres[1]=0x55; //01010101 (kept the temperature and prssure, enabled measurement 
     
     ///GET GAS
     char wGasL[1];
@@ -167,23 +156,23 @@
     char rTempM[1];
     
     while(1) {
-        bme.write(addr,wPres,2); //enables measurement
-        bme.read(addr,rPres,1);
+        bme.write(BMEaddr,wPres,2); //enables measurement
+        bme.read(BMEaddr,rPres,1);
         
-        bme.write(addr,wGasL,1);
-        bme.read(addr,rGasL,1); //bits 7:6 are significant
-        bme.write(addr,wGasM,1);
-        bme.read(addr,rGasM,1); //whole byte is significant
+        bme.write(BMEaddr,wGasL,1);
+        bme.read(BMEaddr,rGasL,1); //bits 7:6 are significant
+        bme.write(BMEaddr,wGasM,1);
+        bme.read(BMEaddr,rGasM,1); //whole byte is significant
         
-        bme.write(addr,wTempL,1);
-        bme.read(addr,rTempL,1);
-        bme.write(addr,wTempM,1);
-        bme.read(addr,rTempM,1);
+        bme.write(BMEaddr,wTempL,1);
+        bme.read(BMEaddr,rTempL,1);
+        bme.write(BMEaddr,wTempM,1);
+        bme.read(BMEaddr,rTempM,1);
         
         int temp =(rTempM[0]<<8)+rTempL[0];
         int gas =(rGasM[0]<<2)+(rGasL[0]>>6); //make space on the most of 2 bits to add only the first two bits from the least
         
-        ble.printf("Gas: %i, Tem: %i\n",gas, temp);
+        ble.printf("Gas: %i, Temp L: %x, Temp H: %x\n",gas, rTempL[0],rTempM[0]);
         wait(0.1);
     }
 
--- a/mbed-os.lib	Fri May 01 14:30:25 2020 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://github.com/ARMmbed/mbed-os/#c9e63f14085f5751ff5ead79a7c0382d50a813a2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon May 18 10:33:49 2020 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/3a7713b1edbc
\ No newline at end of file