Program to collect data from a BMP280 combination pressure temperature sensor & send it over a CAN interface, using an LPC1768

Dependencies:   BMP280 mbed

Files at this revision

API Documentation at this revision

Comitter:
maximusismax
Date:
Fri Oct 21 15:39:32 2016 +0000
Commit message:
V1

Changed in this revision

BMP280.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r b087f3aae9e5 BMP280.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BMP280.lib	Fri Oct 21 15:39:32 2016 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/12104404/code/BMP280/#c72b726c7dc9
diff -r 000000000000 -r b087f3aae9e5 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Oct 21 15:39:32 2016 +0000
@@ -0,0 +1,42 @@
+#include "mbed.h"
+#include "BMP280.h"
+
+#define BMP_TMP_ID 0x8
+#define BMP_PRES_ID 0x9
+
+Serial pc(USBTX, USBRX); // tx, rx
+CAN can(p30,p29); //CAN
+I2C i2c(p9,p10); //SDA, SCL
+BMP280 bmp(i2c); //Default address = 0x76
+
+
+int main() {
+    
+    //Serial config
+    pc.baud(115200);
+    pc.format(8, SerialBase::None, 1);
+    pc.set_flow_control(SerialBase::Disabled, NC, NC);
+    
+    //CAN bus config
+    can.frequency(125000); //125k Hz CAN bus speed
+    can.reset();
+    
+    //bmp.initialize(); 
+    
+    float BMPTemp = 0;
+    float BMPPressure = 0;
+    
+    while(1) {
+        
+        BMPTemp = (bmp.getTemperature() - 32) / 1.8f;
+        BMPPressure = bmp.getPressure();
+        pc.printf("Temp: %f, Pressure: %f\r\n",BMPTemp, BMPPressure);
+        
+        can.write(CANMessage(BMP_TMP_ID, (char*)&BMPTemp, sizeof(BMPTemp)/sizeof(char)));
+        wait(0.1); //Need waits for some reason, without them the data doesnt always arrive in a neat order
+        can.write(CANMessage(BMP_PRES_ID, (char*)&BMPPressure, sizeof(BMPPressure)/sizeof(char)));
+        wait(0.1);
+        
+        
+    }
+}
diff -r 000000000000 -r b087f3aae9e5 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Fri Oct 21 15:39:32 2016 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/2e9cc70d1897
\ No newline at end of file