report

Dependencies:   ADXL362 Lab7 mbed

Files at this revision

API Documentation at this revision

Comitter:
dprowe
Date:
Fri Mar 09 17:25:32 2018 +0000
Parent:
6:f6010330dbbf
Child:
8:9d29dec6c0b7
Commit message:
LAB seven

Changed in this revision

MPL3115A2.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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MPL3115A2.lib	Fri Mar 09 17:25:32 2018 +0000
@@ -0,0 +1,1 @@
+http://os.mbed.com/teams/MSS/code/MPL3115A2/#d893e6f4c1ba
--- a/main.cpp	Fri Feb 23 17:41:03 2018 +0000
+++ b/main.cpp	Fri Mar 09 17:25:32 2018 +0000
@@ -1,10 +1,29 @@
 #include "mbed.h"
 #include "ADXL362.h"
+#include "MPL3115A2.h"
 #include <stdio.h>
 #include <stdlib.h>
 
+Serial pc(SERIAL_TX, SERIAL_RX);
 DigitalOut myled(LED1);
 ADXL362 adxl362(PA_0,PA_7,PA_6,PA_1);
+MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
+InterruptIn event(PA_4);
+
+char *arr[] = {
+    "MPL_STATUS","MPL_OUT_P_MSB", "MPL_OUT_P_CSB","MPL_OUT_P_LSB","MPL_OUT_P_LSB",
+    "MPL_OUT_T_LSB","MPL_DR_STATUS","MPL_OUT_P_DELTA_MSB","MPL_OUT_P_DELTA_MSB",
+    "MPL_OUT_P_DELTA_LSB","MPL_OUT_T_DELTA_MSB","MPL_OUT_T_DELTA_LSB",
+    "MPL_WHO_AM_I","MPL_F_STATUS","MPL_F_DATA","MPL_F_SETUP","MPL_TIME_DLY",
+    "MPL_SYSMOD","MPL_INT_SOURCE","MPL_PT_DATA_CFG","MPL_BAR_IN_MSB",
+    "MPL_BAR_IN_LSB","MPL_P_TGT_MSB","MPL_P_TGT_LSB","MPL_T_TGT","MPL_P_WND_MSB",
+    "MPL_P_WND_LSB","MPL_T_WND","MPL_P_MIN_MSB","MPL_P_MIN_CSB","MPL_P_MIN_LSB",
+    "MPL_T_MIN_MSB", "MPL_T_MIN_LSB", "MPL_P_MAX_MSB", "MPL_P_MAX_CSB",
+    "MPL_P_MAX_LSB","MPL_T_MAX_MSB","MPL_T_MAX_LSB","MPL_CTRL_REG1",
+    "MPL_CTRL_REG2","MPL_CTRL_REG3","MPL_CTRL_REG4","MPL_CTRL_REG5",
+    "MPL_OFF_P","MPL_OFF_T","MPL_OFF_H" 
+    };
+
 
 int adxl362_reg_print(int start, int length) {
     int rvalue = 0;
@@ -324,7 +343,99 @@
         return 0;
 }
 
+int mpl3115_reg_print(int start, int length){
+    
+    uint8_t id;
+    
+    if ((start < 0) || (start > 45)) {
+        pc.printf("break 1 \n\r");
+        return -1;
+        }
+    if (length < 0) {
+        pc.printf("break 2 \n\r");
+        return -1;
+        }
+    id = pressure_sensor.getID();
+    if (id!=0xC4) {
+        pc.printf("break 3 \n\r");
+        return -1;
+        }
+    
+    uint8_t a[45];
+            
+    pressure_sensor.readRegs(start, a, length);
+    
+    int i = 0;
+    for (i=0;i<length;i++){
+        pc.printf("0x%X: %s is 0x%X \n\r",i, arr[i], a[i]);
+        }
+    return 0;
+
+}
+
+int printA(double* ar1, double* ar2, int start, int end){
+    int i = 0;
+    for (i = start; i < end; i++){
+        pc.printf("value at %d : temp: %f pressure: %f \n\r",i,ar1[i], ar2[i]);
+        }
+    return 0;
+}
+
 int main() {
+    int arraySize = 250; //approximately the time it takes to ride one elevator floors 1-6
+    double altitudeReading[arraySize];
+    double tempReading[arraySize];
+    int i = 0, j = 0;
+
+    j = mpl3115_reg_print(0, 45); 
+
+    for (i = 0; i < arraySize; i++) { 
+        altitudeReading[i] = -1;
+    }
+    for(j = 0; j < arraySize; j++) {
+        tempReading[j] = -1;
+        }
+    i = 0;
+    pc.printf("reading an altitude at this point at 10hz\r\n");
+    pc.printf("Enter p to print, enter s to stop: ");
+    while (1) {
+        wait_us(100);
+        altitudeReading[i] = pressure_sensor.getAltitude();
+        i++;
+        tempReading[j] = pressure_sensor.getTemperature();
+        j++;
+        if (i > arraySize) {
+            i = 0;
+        }
+        if( j > arraySize) {
+            j = 0;
+        }
+        if (pc.readable()) {
+            char c = pc.getc();
+            pc.printf("we read a char, it was %c\r\n",c);
+            if (c == 'p') { //press p to show what is currently in the array
+                pc.printf("read a p\r\n");
+                int h = 0;
+                for (h = 0; h < arraySize; h++) { 
+                    pc.printf("temperature = %f, altitude = %f\r\n", tempReading[h], altitudeReading[h]);                
+                }
+            }
+            if( c == 's') { //press s to get it to stop reading
+                break;
+                }
+        }
+
+    }
+    
+   
+
+    
+    
+    
+    
+    
+     /*     Lab 6 work
+    
     wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
     adxl362.set_mode(ADXL362::MEASUREMENT);
     int8_t x,y,z; 
@@ -352,5 +463,6 @@
             printf("number of knocks detected: %d\n\r",blink_c);
             blink();
         }
-    } 
+    } */
+    
 }
\ No newline at end of file