/ ̄\                |     |                  \_/                  |               /  ̄  ̄ \             /  \ /  \            /   ⌒   ⌒   \            |    (__人__)     |            \    ` ⌒´    /            / ̄ ̄ ̄ ̄ ̄ ̄ ̄ \

Dependencies:   mbed BMP280_SPI ADXL345 MPU9250_SPI GPS FATFileSystem

Committer:
IKobayashi
Date:
Mon Mar 16 14:22:11 2020 +0000
Revision:
6:49b2f2583f31
Parent:
5:212df3af29ca
for_stm

Who changed what in which revision?

UserRevisionLine numberNew 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 6:49b2f2583f31 45 fprintf(fp,"GMT: ,N.Lat: ,E.Lng: ,stat: ,satnum: ,\r\n");
IKobayashi 6:49b2f2583f31 46 fprintf(fp,"MPU9250_data, , , , , , , , , ,");
IKobayashi 6:49b2f2583f31 47 fprintf(fp,"BMP280_data, ,");
IKobayashi 6:49b2f2583f31 48 fprintf(fp,"GMT: ,N.Lat: ,E.Lng: ,stat: ,satnum: ,\r\n");
IKobayashi 0:56002cd6879d 49
IKobayashi 3:1bc7fe4442c3 50 while (i<30) {
IKobayashi 0:56002cd6879d 51 wait(0.1);
IKobayashi 0:56002cd6879d 52 /*
IKobayashi 0:56002cd6879d 53 imu.read_temp();
IKobayashi 0:56002cd6879d 54 imu.read_acc();
IKobayashi 0:56002cd6879d 55 imu.read_rot();
IKobayashi 0:56002cd6879d 56 imu.AK8963_read_Magnetometer();
IKobayashi 0:56002cd6879d 57 */
IKobayashi 0:56002cd6879d 58 imu.read_all();
IKobayashi 0:56002cd6879d 59 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 60 imu.Temperature,
IKobayashi 0:56002cd6879d 61 imu.gyroscope_data[0],
IKobayashi 0:56002cd6879d 62 imu.gyroscope_data[1],
IKobayashi 0:56002cd6879d 63 imu.gyroscope_data[2],
IKobayashi 0:56002cd6879d 64 imu.accelerometer_data[0],
IKobayashi 0:56002cd6879d 65 imu.accelerometer_data[1],
IKobayashi 0:56002cd6879d 66 imu.accelerometer_data[2],
IKobayashi 0:56002cd6879d 67 imu.Magnetometer[0],
IKobayashi 0:56002cd6879d 68 imu.Magnetometer[1],
IKobayashi 0:56002cd6879d 69 imu.Magnetometer[2]
IKobayashi 0:56002cd6879d 70 );
IKobayashi 4:667f0168f471 71 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 72 imu.Temperature,
IKobayashi 0:56002cd6879d 73 imu.gyroscope_data[0],
IKobayashi 0:56002cd6879d 74 imu.gyroscope_data[1],
IKobayashi 0:56002cd6879d 75 imu.gyroscope_data[2],
IKobayashi 0:56002cd6879d 76 imu.accelerometer_data[0],
IKobayashi 0:56002cd6879d 77 imu.accelerometer_data[1],
IKobayashi 0:56002cd6879d 78 imu.accelerometer_data[2],
IKobayashi 0:56002cd6879d 79 imu.Magnetometer[0],
IKobayashi 0:56002cd6879d 80 imu.Magnetometer[1],
IKobayashi 0:56002cd6879d 81 imu.Magnetometer[2]
IKobayashi 0:56002cd6879d 82 );
IKobayashi 0:56002cd6879d 83
IKobayashi 0:56002cd6879d 84 pc.printf("%2.2f degC, %04.2f hPa\n\r", sensor.getTemperature(), sensor.getPressure());
IKobayashi 0:56002cd6879d 85 fprintf(fp,"%2.2f , %04.2f ,", sensor.getTemperature(), sensor.getPressure());
IKobayashi 0:56002cd6879d 86
IKobayashi 4:667f0168f471 87 //accelerometer.read_mg_data(readings);
IKobayashi 4:667f0168f471 88 //pc.printf("x=%f, y=%f, z=%f\r\n",readings[0],readings[1],readings[2]);
IKobayashi 4:667f0168f471 89 //fprintf(fp,"%f, %f, %f,",readings[0],readings[1],readings[2]);
IKobayashi 0:56002cd6879d 90
IKobayashi 0:56002cd6879d 91 pc.printf("世界標準時:%02dh%02dm%02ds 北緯:%.8f 東経:%.8f 状態:%d 使用衛星数:%d\r\n",
IKobayashi 0:56002cd6879d 92 gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt);
IKobayashi 0:56002cd6879d 93 fprintf(fp,"%02dh%02dm%02ds ,%.8f ,%.8f ,%d ,%d\r\n",
IKobayashi 0:56002cd6879d 94 gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt);
IKobayashi 0:56002cd6879d 95
IKobayashi 0:56002cd6879d 96 led=!led;
IKobayashi 0:56002cd6879d 97 i++;
IKobayashi 0:56002cd6879d 98 }
IKobayashi 0:56002cd6879d 99 fclose(fp);
IKobayashi 0:56002cd6879d 100 }