/ ̄\ | | \_/ | /  ̄  ̄ \ / \ / \ / ⌒ ⌒ \ | (__人__) | \ ` ⌒´ / / ̄ ̄ ̄ ̄ ̄ ̄ ̄ \
Dependencies: mbed BMP280_SPI ADXL345 MPU9250_SPI GPS FATFileSystem
main.cpp@5:212df3af29ca, 2020-03-05 (annotated)
- Committer:
- IKobayashi
- Date:
- Thu Mar 05 05:38:28 2020 +0000
- Revision:
- 5:212df3af29ca
- Parent:
- 4:667f0168f471
- Child:
- 6:49b2f2583f31
F411
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
IKobayashi | 0:56002cd6879d | 1 | #include "mbed.h" |
IKobayashi | 4:667f0168f471 | 2 | #include "SDFileSystem.h" |
IKobayashi | 0:56002cd6879d | 3 | #include "MPU9250.h" |
IKobayashi | 0:56002cd6879d | 4 | #include "BMP280_SPI.h" |
IKobayashi | 0:56002cd6879d | 5 | #include "GPS.h" |
IKobayashi | 0:56002cd6879d | 6 | |
IKobayashi | 4:667f0168f471 | 7 | //SDFileSystem sd(p11, p12, p13, p15, "sd"); |
IKobayashi | 5:212df3af29ca | 8 | SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd"); |
IKobayashi | 5:212df3af29ca | 9 | DigitalOut led(PC_13); |
IKobayashi | 5:212df3af29ca | 10 | GPS gps(PA_9, PA_10); // tx, rx |
IKobayashi | 5:212df3af29ca | 11 | Serial xbee(PA_11,PA_12,38400); |
IKobayashi | 5:212df3af29ca | 12 | SPI spi(PA_7, PA_6, PA_5); |
IKobayashi | 5:212df3af29ca | 13 | mpu9250_spi imu(spi,PA_4); //define the mpu9250 object |
IKobayashi | 5:212df3af29ca | 14 | BMP280_SPI sensor(PA_7, PA_6, PA_5, PB_0); |
IKobayashi | 5:212df3af29ca | 15 | Serial pc(PA_2,PA_3); |
IKobayashi | 5:212df3af29ca | 16 | |
IKobayashi | 5:212df3af29ca | 17 | FILE *fp; |
IKobayashi | 0:56002cd6879d | 18 | |
IKobayashi | 0:56002cd6879d | 19 | int main() |
IKobayashi | 0:56002cd6879d | 20 | { |
IKobayashi | 0:56002cd6879d | 21 | int i=0; |
IKobayashi | 0:56002cd6879d | 22 | |
IKobayashi | 3:1bc7fe4442c3 | 23 | mkdir("/sd/data", 0777); |
IKobayashi | 0:56002cd6879d | 24 | |
IKobayashi | 5:212df3af29ca | 25 | fp = fopen("/sd/data/sdtest.csv", "w"); |
IKobayashi | 0:56002cd6879d | 26 | if(fp == NULL) { |
IKobayashi | 4:667f0168f471 | 27 | error("Could not open file for write\r\n"); |
IKobayashi | 0:56002cd6879d | 28 | } |
IKobayashi | 0:56002cd6879d | 29 | |
IKobayashi | 0:56002cd6879d | 30 | if(imu.init(1,BITS_DLPF_CFG_188HZ)) { //INIT the mpu9250 |
IKobayashi | 4:667f0168f471 | 31 | pc.printf("\nCouldn't initialize MPU9250 via SPI!\r"); |
IKobayashi | 0:56002cd6879d | 32 | } |
IKobayashi | 0:56002cd6879d | 33 | pc.printf("\nWHOAMI=0x%2x\n\r",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 |
IKobayashi | 0:56002cd6879d | 34 | wait(1); |
IKobayashi | 0:56002cd6879d | 35 | pc.printf("Gyro_scale=%u\n\r",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros |
IKobayashi | 0:56002cd6879d | 36 | wait(1); |
IKobayashi | 0:56002cd6879d | 37 | pc.printf("Acc_scale=%u\n\r",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs |
IKobayashi | 0:56002cd6879d | 38 | wait(1); |
IKobayashi | 0:56002cd6879d | 39 | pc.printf("AK8963 WHIAM=0x%2x\n\r",imu.AK8963_whoami()); |
IKobayashi | 0:56002cd6879d | 40 | wait(0.1); |
IKobayashi | 0:56002cd6879d | 41 | imu.AK8963_calib_Magnetometer(); |
IKobayashi | 0:56002cd6879d | 42 | |
IKobayashi | 0:56002cd6879d | 43 | fprintf(fp,"MPU9250_data, , , , , , , , , ,"); |
IKobayashi | 0:56002cd6879d | 44 | fprintf(fp,"BMP280_data, ,"); |
IKobayashi | 0:56002cd6879d | 45 | fprintf(fp,"世界標準時: ,北緯: ,東経: ,状態: ,使用衛星数: ,\r\n"); |
IKobayashi | 0:56002cd6879d | 46 | |
IKobayashi | 3:1bc7fe4442c3 | 47 | while (i<30) { |
IKobayashi | 0:56002cd6879d | 48 | wait(0.1); |
IKobayashi | 0:56002cd6879d | 49 | /* |
IKobayashi | 0:56002cd6879d | 50 | imu.read_temp(); |
IKobayashi | 0:56002cd6879d | 51 | imu.read_acc(); |
IKobayashi | 0:56002cd6879d | 52 | imu.read_rot(); |
IKobayashi | 0:56002cd6879d | 53 | imu.AK8963_read_Magnetometer(); |
IKobayashi | 0:56002cd6879d | 54 | */ |
IKobayashi | 0:56002cd6879d | 55 | imu.read_all(); |
IKobayashi | 0:56002cd6879d | 56 | pc.printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n\r", |
IKobayashi | 0:56002cd6879d | 57 | imu.Temperature, |
IKobayashi | 0:56002cd6879d | 58 | imu.gyroscope_data[0], |
IKobayashi | 0:56002cd6879d | 59 | imu.gyroscope_data[1], |
IKobayashi | 0:56002cd6879d | 60 | imu.gyroscope_data[2], |
IKobayashi | 0:56002cd6879d | 61 | imu.accelerometer_data[0], |
IKobayashi | 0:56002cd6879d | 62 | imu.accelerometer_data[1], |
IKobayashi | 0:56002cd6879d | 63 | imu.accelerometer_data[2], |
IKobayashi | 0:56002cd6879d | 64 | imu.Magnetometer[0], |
IKobayashi | 0:56002cd6879d | 65 | imu.Magnetometer[1], |
IKobayashi | 0:56002cd6879d | 66 | imu.Magnetometer[2] |
IKobayashi | 0:56002cd6879d | 67 | ); |
IKobayashi | 4:667f0168f471 | 68 | fprintf(fp,"%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,", |
IKobayashi | 0:56002cd6879d | 69 | imu.Temperature, |
IKobayashi | 0:56002cd6879d | 70 | imu.gyroscope_data[0], |
IKobayashi | 0:56002cd6879d | 71 | imu.gyroscope_data[1], |
IKobayashi | 0:56002cd6879d | 72 | imu.gyroscope_data[2], |
IKobayashi | 0:56002cd6879d | 73 | imu.accelerometer_data[0], |
IKobayashi | 0:56002cd6879d | 74 | imu.accelerometer_data[1], |
IKobayashi | 0:56002cd6879d | 75 | imu.accelerometer_data[2], |
IKobayashi | 0:56002cd6879d | 76 | imu.Magnetometer[0], |
IKobayashi | 0:56002cd6879d | 77 | imu.Magnetometer[1], |
IKobayashi | 0:56002cd6879d | 78 | imu.Magnetometer[2] |
IKobayashi | 0:56002cd6879d | 79 | ); |
IKobayashi | 0:56002cd6879d | 80 | |
IKobayashi | 0:56002cd6879d | 81 | pc.printf("%2.2f degC, %04.2f hPa\n\r", sensor.getTemperature(), sensor.getPressure()); |
IKobayashi | 0:56002cd6879d | 82 | fprintf(fp,"%2.2f , %04.2f ,", sensor.getTemperature(), sensor.getPressure()); |
IKobayashi | 0:56002cd6879d | 83 | |
IKobayashi | 4:667f0168f471 | 84 | //accelerometer.read_mg_data(readings); |
IKobayashi | 4:667f0168f471 | 85 | //pc.printf("x=%f, y=%f, z=%f\r\n",readings[0],readings[1],readings[2]); |
IKobayashi | 4:667f0168f471 | 86 | //fprintf(fp,"%f, %f, %f,",readings[0],readings[1],readings[2]); |
IKobayashi | 0:56002cd6879d | 87 | |
IKobayashi | 0:56002cd6879d | 88 | pc.printf("世界標準時:%02dh%02dm%02ds 北緯:%.8f 東経:%.8f 状態:%d 使用衛星数:%d\r\n", |
IKobayashi | 0:56002cd6879d | 89 | gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt); |
IKobayashi | 0:56002cd6879d | 90 | fprintf(fp,"%02dh%02dm%02ds ,%.8f ,%.8f ,%d ,%d\r\n", |
IKobayashi | 0:56002cd6879d | 91 | gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt); |
IKobayashi | 0:56002cd6879d | 92 | |
IKobayashi | 0:56002cd6879d | 93 | led=!led; |
IKobayashi | 0:56002cd6879d | 94 | i++; |
IKobayashi | 0:56002cd6879d | 95 | } |
IKobayashi | 0:56002cd6879d | 96 | fclose(fp); |
IKobayashi | 0:56002cd6879d | 97 | } |