![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
revisions to pressure and magnetometer
Dependencies: HMC5883L IMU MPU6050 MS5803 MS5837 mbed-rtos mbed sensor
Fork of sensor_library_test by
main.cpp@4:60340d6eed1f, 2016-07-25 (annotated)
- Committer:
- srago001
- Date:
- Mon Jul 25 04:04:53 2016 +0000
- Revision:
- 4:60340d6eed1f
- Parent:
- 3:6ca88b9c44c1
sonya's revisions to pressure
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
onehorse | 0:65aa78c10981 | 1 | |
aolgu003 | 3:6ca88b9c44c1 | 2 | /* |
aolgu003 | 3:6ca88b9c44c1 | 3 | Connections information: |
aolgu003 | 3:6ca88b9c44c1 | 4 | MPU to stm32F401RE NUCLEO Connection information |
aolgu003 | 3:6ca88b9c44c1 | 5 | VCC -> 3.3V |
aolgu003 | 3:6ca88b9c44c1 | 6 | SCL -> D15 |
aolgu003 | 3:6ca88b9c44c1 | 7 | SDA -> D14 |
aolgu003 | 3:6ca88b9c44c1 | 8 | AD0 -> high |
aolgu003 | 3:6ca88b9c44c1 | 9 | |
aolgu003 | 3:6ca88b9c44c1 | 10 | HMC5883L |
aolgu003 | 3:6ca88b9c44c1 | 11 | VCC -> 3.3V |
aolgu003 | 3:6ca88b9c44c1 | 12 | SCL -> D7 |
aolgu003 | 3:6ca88b9c44c1 | 13 | SDA -> D5 |
aolgu003 | 3:6ca88b9c44c1 | 14 | |
aolgu003 | 3:6ca88b9c44c1 | 15 | MS5803 |
aolgu003 | 3:6ca88b9c44c1 | 16 | VCC -> 3.3V |
aolgu003 | 3:6ca88b9c44c1 | 17 | SCL -> D7 |
aolgu003 | 3:6ca88b9c44c1 | 18 | SDA -> D5 |
aolgu003 | 3:6ca88b9c44c1 | 19 | |
aolgu003 | 3:6ca88b9c44c1 | 20 | All grounds go to common ground |
onehorse | 0:65aa78c10981 | 21 | */ |
onehorse | 0:65aa78c10981 | 22 | |
onehorse | 1:cea9d83b8636 | 23 | #include "mbed.h" |
aolgu003 | 3:6ca88b9c44c1 | 24 | #include "sensor.h" |
onehorse | 0:65aa78c10981 | 25 | |
srago001 | 4:60340d6eed1f | 26 | |
aolgu003 | 3:6ca88b9c44c1 | 27 | int main() { |
srago001 | 4:60340d6eed1f | 28 | device.attach(&callback); |
aolgu003 | 3:6ca88b9c44c1 | 29 | sensor_init(); |
aolgu003 | 3:6ca88b9c44c1 | 30 | while (1) { |
aolgu003 | 3:6ca88b9c44c1 | 31 | sensor_update(); |
aolgu003 | 3:6ca88b9c44c1 | 32 | print_data(); |
aolgu003 | 3:6ca88b9c44c1 | 33 | //sensor_msg(); |
aolgu003 | 3:6ca88b9c44c1 | 34 | } |
aolgu003 | 3:6ca88b9c44c1 | 35 | } |
onehorse | 0:65aa78c10981 | 36 | |
aolgu003 | 3:6ca88b9c44c1 | 37 | /*#include "MPU6050.h" |
aolgu003 | 3:6ca88b9c44c1 | 38 | #include "MS5803.h" |
aolgu003 | 3:6ca88b9c44c1 | 39 | #include "MS5837.h" |
aolgu003 | 3:6ca88b9c44c1 | 40 | #include "IMU.h" |
aolgu003 | 3:6ca88b9c44c1 | 41 | #include "HMC5883L.h" |
onehorse | 1:cea9d83b8636 | 42 | |
aolgu003 | 3:6ca88b9c44c1 | 43 | MPU6050 mpu6050; |
aolgu003 | 3:6ca88b9c44c1 | 44 | DigitalOut led1(LED1); |
aolgu003 | 3:6ca88b9c44c1 | 45 | //MS5837 pressure_sensor_1 = MS5803(I2C_SDA, I2C_SCL); |
aolgu003 | 3:6ca88b9c44c1 | 46 | //MS5837 pressure_sensor_2 = MS5803(PB_4, PA_8); |
onehorse | 1:cea9d83b8636 | 47 | |
aolgu003 | 3:6ca88b9c44c1 | 48 | HMC5883L compass(PB_4, PA_8); |
aolgu003 | 3:6ca88b9c44c1 | 49 | MS5837 pressure_sensor_1 = MS5837(I2C_SDA, I2C_SCL, ms5837_addr_no_CS); |
aolgu003 | 3:6ca88b9c44c1 | 50 | MS5837 pressure_sensor_2 = MS5837(PB_4, PA_8, ms5837_addr_no_CS); |
onehorse | 1:cea9d83b8636 | 51 | |
aolgu003 | 3:6ca88b9c44c1 | 52 | //Serial pc(USBTX, USBRX); |
aolgu003 | 3:6ca88b9c44c1 | 53 | |
onehorse | 1:cea9d83b8636 | 54 | int main() |
onehorse | 1:cea9d83b8636 | 55 | { |
aolgu003 | 3:6ca88b9c44c1 | 56 | //Test Compass |
aolgu003 | 3:6ca88b9c44c1 | 57 | //pc.printf("Compass mode: %b\n", compass.getMode()); |
aolgu003 | 3:6ca88b9c44c1 | 58 | int16_t mag[3] = {0}; |
aolgu003 | 3:6ca88b9c44c1 | 59 | |
aolgu003 | 3:6ca88b9c44c1 | 60 | printf("Begining Initialization\n"); |
aolgu003 | 3:6ca88b9c44c1 | 61 | |
aolgu003 | 3:6ca88b9c44c1 | 62 | int error_cnt = 0; |
onehorse | 1:cea9d83b8636 | 63 | |
aolgu003 | 3:6ca88b9c44c1 | 64 | float depth; |
aolgu003 | 3:6ca88b9c44c1 | 65 | float pressure1, depth1; |
aolgu003 | 3:6ca88b9c44c1 | 66 | float pressure2, depth2; |
onehorse | 1:cea9d83b8636 | 67 | |
aolgu003 | 3:6ca88b9c44c1 | 68 | pressure_sensor_1.MS5837Init(); |
aolgu003 | 3:6ca88b9c44c1 | 69 | pressure_sensor_2.MS5837Init(); |
aolgu003 | 3:6ca88b9c44c1 | 70 | pc.printf("Initialized begining readings\n"); |
onehorse | 0:65aa78c10981 | 71 | |
aolgu003 | 3:6ca88b9c44c1 | 72 | IMUinit(mpu6050); |
onehorse | 0:65aa78c10981 | 73 | |
aolgu003 | 3:6ca88b9c44c1 | 74 | while(1) { |
aolgu003 | 3:6ca88b9c44c1 | 75 | pressure_sensor_1.Barometer_MS5837(); |
aolgu003 | 3:6ca88b9c44c1 | 76 | pressure_sensor_2.Barometer_MS5837(); |
aolgu003 | 3:6ca88b9c44c1 | 77 | pressure1 = pressure_sensor_1.MS5837_Pressure(); |
aolgu003 | 3:6ca88b9c44c1 | 78 | pressure2 = pressure_sensor_2.MS5837_Pressure(); |
aolgu003 | 3:6ca88b9c44c1 | 79 | |
aolgu003 | 3:6ca88b9c44c1 | 80 | //Do some error checking |
aolgu003 | 3:6ca88b9c44c1 | 81 | if ((pressure1 > 900 && pressure1 < 3000) && (pressure2 > 900 && pressure2 < 3000)) { |
aolgu003 | 3:6ca88b9c44c1 | 82 | depth1 = pressure_sensor_1.depth(); |
aolgu003 | 3:6ca88b9c44c1 | 83 | depth2 = pressure_sensor_2.depth(); |
aolgu003 | 3:6ca88b9c44c1 | 84 | |
aolgu003 | 3:6ca88b9c44c1 | 85 | depth = (depth1 + depth2) / 2; |
aolgu003 | 3:6ca88b9c44c1 | 86 | error_cnt = 0; |
aolgu003 | 3:6ca88b9c44c1 | 87 | } else if (pressure2 > 900 && pressure2 < 3000) { |
aolgu003 | 3:6ca88b9c44c1 | 88 | depth = pressure_sensor_2.depth(); |
aolgu003 | 3:6ca88b9c44c1 | 89 | |
aolgu003 | 3:6ca88b9c44c1 | 90 | error_cnt = 0; |
aolgu003 | 3:6ca88b9c44c1 | 91 | } else if (pressure1 > 900 && pressure1 < 3000) { |
aolgu003 | 3:6ca88b9c44c1 | 92 | depth = pressure_sensor_1.depth(); |
aolgu003 | 3:6ca88b9c44c1 | 93 | error_cnt = 0; |
aolgu003 | 3:6ca88b9c44c1 | 94 | } else { |
aolgu003 | 3:6ca88b9c44c1 | 95 | error_cnt++; |
aolgu003 | 3:6ca88b9c44c1 | 96 | if (error_cnt > 50) { |
aolgu003 | 3:6ca88b9c44c1 | 97 | //do something |
aolgu003 | 3:6ca88b9c44c1 | 98 | pc.printf("Pressure sensor error"); |
aolgu003 | 3:6ca88b9c44c1 | 99 | } |
aolgu003 | 3:6ca88b9c44c1 | 100 | } |
aolgu003 | 3:6ca88b9c44c1 | 101 | pc.printf("Depth is: %f\n", depth); |
aolgu003 | 3:6ca88b9c44c1 | 102 | |
aolgu003 | 3:6ca88b9c44c1 | 103 | //IMU Read |
aolgu003 | 3:6ca88b9c44c1 | 104 | IMUUpdate(mpu6050); |
onehorse | 0:65aa78c10981 | 105 | |
aolgu003 | 3:6ca88b9c44c1 | 106 | //Compass read |
aolgu003 | 3:6ca88b9c44c1 | 107 | compass.getXYZ(mag); |
aolgu003 | 3:6ca88b9c44c1 | 108 | pc.printf("Mag values: %d, %d, %d\n", mag[0], mag[1], mag[2]); |
aolgu003 | 3:6ca88b9c44c1 | 109 | pc.printf("Heading: %f\n",compass.getHeadingXYDeg()); |
aolgu003 | 3:6ca88b9c44c1 | 110 | |
aolgu003 | 3:6ca88b9c44c1 | 111 | led1 = !led1; |
aolgu003 | 3:6ca88b9c44c1 | 112 | //Thread::wait(500); |
aolgu003 | 3:6ca88b9c44c1 | 113 | } |
aolgu003 | 3:6ca88b9c44c1 | 114 | }*/ |