Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: ADXL362 ATParser MPL3115A2 TSL2561 mbed
Fork of Lab91 by
Revision 2:c322c1331eaa, committed 2018-03-09
- Comitter:
- jackclar
- Date:
- Fri Mar 09 01:10:40 2018 +0000
- Parent:
- 0:9a45e4f07b10
- Child:
- 3:cbd71da3ccd4
- Commit message:
- Lab 7;
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 |
--- a/MPL3115A2.lib Fri Mar 02 17:49:50 2018 +0000 +++ b/MPL3115A2.lib Fri Mar 09 01:10:40 2018 +0000 @@ -1,1 +1,1 @@ -http://os.mbed.com/teams/MSS/code/MPL3115A2/#12223b4c88b1 +http://os.mbed.com/teams/MSS/code/MPL3115A2/#95ed2a667364
--- a/main.cpp Fri Mar 02 17:49:50 2018 +0000
+++ b/main.cpp Fri Mar 09 01:10:40 2018 +0000
@@ -1,55 +1,226 @@
#include "mbed.h"
#include "MPL3115A2.h"
-#include "ADXL362.h"
#include <string>
#include <math.h>
-
-ADXL362 ADXL362(PA_0,PA_7,PA_6,PA_1);
Serial pc(SERIAL_TX, SERIAL_RX);
DigitalOut myled(LED1);
-DigitalOut powerpin(PA_8);
+DigitalOut powerpin(PA_8); // GPIO pin
// Selects SDA as I2C1_SDA on pin PB_7
// Selects SCL on I2C1_SCL on pin PB_6
// The I2C address of the pressure sensor is fixed at 0x60.
MPL3115A2 pressure_sensor(PB_7,PB_6,0x60);
+void mpl3115_reg_print(int start, int length); // prototype
int main() {
- int8_t a1, a2, a;
+ int8_t a;
+ uint8_t id;
double p, t;
- double v = 0.0;
+ double v , s;
int cnt = 0;
myled = 0;
+ char c;
powerpin = 0;
-
- wait_ms(600); // we need to wait at least 500ms after ADXL362 reset
- ADXL362.set_mode(ADXL362::MEASUREMENT);
+ double alt1 = pressure_sensor.getAltitude(), alt2; // initial alt
+ while ((id=pressure_sensor.getID())!=0xC4)// wait for the sensor to connect
+ {
+ wait(1);
+ }
while(1)
{
- if(powerpin)
- {
- myled = 1;
- a1=ADXL362.scanz_u8();
- p=pressure_sensor.getPressure();
- t=pressure_sensor.getTemperature();
-
- pc.printf("temp_%d = %f C ; pressure_%d = %f \n\r Pa",cnt,t,cnt,p);
- cnt++;
-
- wait_ms(100);
- a2=ADXL362.scanz_u8();
- a = a1 - a2;
-
- v = v + double(a) * 0.1;
- pc.printf(" velocity = %f \n\r",v);
- }
- else
- {
- myled = 0;
+ if(powerpin) // if the GPIO pin is pulled high
+ {
+ myled != myled;
+ //turn on and off led at 1Hz
+ p=pressure_sensor.getPressure();
+ t=pressure_sensor.getTemperature();
+ alt2=pressure_sensor.getAltitude();
+ v = (alt2 - alt1)/ 1.1;
+ // velocity is just distance / time
+ // we measured the time to be 1.1 seconds between readings
+ // this is as fast as it will go because of the library we were given
+ pc.printf("velocity = %f\n\r", v);
+ alt1 = alt2;
+
+ pc.printf("%f %f\n\r", t, p);
+ cnt++;
+ }
+ else
+ {
+ myled = 0; // so we know when no data is being taken
+ }
}
}
-}
-
\ No newline at end of file
+
+void mpl3115_reg_print(int start, int length)
+{
+ uint8_t i, id;
+ std::string name;
+ uint8_t temp[1];
+ id = pressure_sensor.getID();
+
+ // check start registers
+ if(start >= 0x00 && start <= 0x2D && length >= 0x00 && id == 0xC4)
+ {
+ // print all if length = 0
+ if(length == 0)
+ {
+ start = 0;
+ length = 46;
+ }
+
+ for(i = start; i < start + length; i++)
+ {
+ // make sure name is correct
+ switch(i)
+ {
+ case 0x00:
+ name = "MPL_STATUS";
+ break;
+ case 0x01:
+ name = "MPL_OUT_P_MSB";
+ break;
+ case 0x02:
+ name = "MPL_OUT_P_CSB";
+ break;
+ case 0x03:
+ name = "MPL_OUT_P_LSB";
+ break;
+ case 0x04:
+ name = "MPL_OUT_T_MSB";
+ break;
+ case 0x05:
+ name = "MPL_OUT_T_LSB";
+ break;
+ case 0x06:
+ name = "MPL_DR_STATUS";
+ break;
+ case 0x07:
+ name = "MPL_OUT_P_DELTA_MSB";
+ break;
+ case 0x08:
+ name = "MPL_OUT_P_DELTA_CSB";
+ break;
+ case 0x09:
+ name = "MPL_OUT_P_DELTA_LSB";
+ break;
+ case 0x0A:
+ name = "MPL_OUT_T_DELTA_MSB";
+ break;
+ case 0x0B:
+ name = "MPL_OUT_T_DELTA_LSB";
+ break;
+ case 0x0C:
+ name = "MPL_WHO_AM_I";
+ break;
+ case 0x0D:
+ name = "MPL_F_STATUS";
+ break;
+ case 0x0E:
+ name = "MPL_F_DATA";
+ break;
+ case 0x0F:
+ name = "MPL_F_SETUP";
+ break;
+ case 0x10:
+ name = "MPL_TIME_DLY";
+ break;
+ case 0x11:
+ name = "MPL_SYSMOD";
+ break;
+ case 0x12:
+ name = "MPL_INT_SOURCE";
+ break;
+ case 0x13:
+ name = "MPL_PT_DATA_CFG";
+ break;
+ case 0x14:
+ name = "MPL_BAR_IN_MSB";
+ break;
+ case 0x15:
+ name = "MPL_BAR_IN_LSB";
+ break;
+ case 0x16:
+ name = "MPL_P_TGT_MSB";
+ break;
+ case 0x17:
+ name = "MPL_P_TGT_LSB";
+ break;
+ case 0x18:
+ name = "MPL_T_TGT";
+ break;
+ case 0x19:
+ name = "MPL_P_WND_MSB";
+ break;
+ case 0x1A:
+ name = "MPL_P_WND_LSB";
+ break;
+ case 0x1B:
+ name = "MPL_T_WND";
+ break;
+ case 0x1C:
+ name = "MPL_P_MIN_MSB";
+ break;
+ case 0x1D:
+ name = "MPL_P_MIN_CSB";
+ break;
+ case 0x1E:
+ name = "MPL_P_MIN_LSB";
+ break;
+ case 0x1F:
+ name = "MPL_T_MIN_MSB";
+ break;
+ case 0x20:
+ name = "MPL_T_MIN_LSB";
+ break;
+ case 0x21:
+ name = "MPL_P_MAX_MSB";
+ break;
+ case 0x22:
+ name = "MPL_P_MAX_CSB";
+ break;
+ case 0x23:
+ name = "MPL_P_MAX_LSB";
+ break;
+ case 0x24:
+ name = "MPL_T_MAX_MSB";
+ break;
+ case 0x25:
+ name = "MPL_T_MAX_LSB";
+ break;
+ case 0x26:
+ name = "MPL_CTRL_REG1";
+ break;
+ case 0x27:
+ name = "MPL_CTRL_REG2";
+ break;
+ case 0x28:
+ name = "MPL_CTRL_REG3";
+ break;
+ case 0x29:
+ name = "MPL_CTRL_REG4";
+ break;
+ case 0x2A:
+ name = "MPL_CTRL_REG5";
+ break;
+ case 0x2B:
+ name = "MPL_OFF_P";
+ break;
+ case 0x2C:
+ name = "MPL_OFF_T";
+ break;
+ case 0x2D:
+ name = "MPL_OFF_h";
+ break;
+ }
+ // boy I do love switch statments
+ pressure_sensor.readRegs(i, temp, 1);
+ pc.printf("0x%x: %s=0x%x\n\r", i, name, temp[0]);
+ // actually print the contents of the register
+ }
+
+ }
+}
\ No newline at end of file
