The integration of BME680 sensor with Nucleo board. ROS Enabled

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
zillkhan
Date:
Tue Sep 28 12:41:58 2021 +0000
Parent:
1:ca82df4237eb
Commit message:
final changes

Changed in this revision

BME680.lib Show annotated file Show diff for this revision Revisions of this file
BME680_driver.lib Show annotated file Show diff for this revision Revisions of this file
SHARPIR.lib Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r ca82df4237eb -r 816ad5bfa327 BME680.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME680.lib	Tue Sep 28 12:41:58 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/sensidev/BME680/#cd2aeb67003ce13c4e51a56a4fb935844289de53
diff -r ca82df4237eb -r 816ad5bfa327 BME680_driver.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BME680_driver.lib	Tue Sep 28 12:41:58 2021 +0000
@@ -0,0 +1,1 @@
+https://github.com/BoschSensortec/BME680_driver/#9014031fa00a5cc1eea1498c4cd1f94ec4b8ab11
diff -r ca82df4237eb -r 816ad5bfa327 SHARPIR.lib
--- a/SHARPIR.lib	Fri Sep 10 09:24:48 2021 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,1 +0,0 @@
-https://os.mbed.com/users/zillkhan/code/SHARPIR_GP2Y0A51SK0F/#acdd61a2aac7
diff -r ca82df4237eb -r 816ad5bfa327 main.cpp
--- a/main.cpp	Fri Sep 10 09:24:48 2021 +0000
+++ b/main.cpp	Tue Sep 28 12:41:58 2021 +0000
@@ -1,33 +1,43 @@
 #include "mbed.h"
 #include <ros.h>
-#include <std_msgs/Float32.h>
-#include <std_msgs/String.h>
-#include "SHARPIR.h"
+#include "std_msgs/String.h"
+#include "mbed_bme680.h"
+
+#define I2C_SDA D14
+#define I2C_SCL D15
+
+I2C i2c(I2C_SDA, I2C_SCL);  // Used inside the BME680 Mbed Lib.
+
+BME680 bme680(0xEE);
 
 
-ros::NodeHandle  nh;
+ros::NodeHandle nh;
 
-std_msgs::Float32 data;
-ros::Publisher sharpir("sharpir", &data);
-
-SHARPIR Sensor(A0); 
-
+std_msgs::String msg;
+ros::Publisher sensor_bme("sensor_bme", &msg);
 
 int main() {
-    float DistanceCM;
     
-    nh.initNode();
-    nh.advertise(sharpir);
-    
+    if (!bme680.begin()) {
+        printf("BME680 Begin failed \r\n");
+        return 1;
+    }
+    nh.initNode();  
+    nh.advertise(sensor_bme);
+
     while (1) { //creates an eternal loop
-    
-        DistanceCM=Sensor.cm();  
-        //sprintf (buffer, "%f", DistanceCM);
+        char* buffer = (char*) malloc(sizeof(char) * 50);
+        
+        bme680.performReading();
+        sprintf (buffer, "Temp: %0.2f degC,Humi: %0.2f %%,Pres: %0.2f hPa,VOC: %0.2f KOhms", bme680.getTemperature(),bme680.getHumidity(),(bme680.getPressure() / 100.0),(bme680.getGasResistance() / 1000.0));
+        
         
-        data.data = DistanceCM;
-        sharpir.publish( &data );
-        
+        msg.data = buffer;
+        sensor_bme.publish(&msg);
+               
         nh.spinOnce();
+        free(buffer);
         wait_ms(1000);
+
     }
 }