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: mbed BMP280_SPI ADXL345 MPU9250_SPI GPS FATFileSystem
main.cpp
00001 #include "mbed.h" 00002 #include "SDFileSystem.h" 00003 #include "MPU9250.h" 00004 #include "BMP280_SPI.h" 00005 #include "GPS.h" 00006 00007 //SDFileSystem sd(p11, p12, p13, p15, "sd"); 00008 SDFileSystem sd(PB_15, PB_14, PB_13, PB_12, "sd"); 00009 DigitalOut led(PC_13); 00010 GPS gps(PA_9, PA_10); // tx, rx 00011 Serial xbee(PA_11,PA_12,38400); 00012 SPI spi(PA_7, PA_6, PA_5); 00013 mpu9250_spi imu(spi,PA_4); //define the mpu9250 object 00014 BMP280_SPI sensor(PA_7, PA_6, PA_5, PB_0); 00015 Serial pc(PA_2,PA_3); 00016 00017 FILE *fp; 00018 00019 int main() 00020 { 00021 int i=0; 00022 00023 mkdir("/sd/data", 0777); 00024 00025 fp = fopen("/sd/data/sdtest.csv", "w"); 00026 if(fp == NULL) { 00027 error("Could not open file for write\r\n"); 00028 } 00029 00030 if(imu.init(1,BITS_DLPF_CFG_188HZ)) { //INIT the mpu9250 00031 pc.printf("\nCouldn't initialize MPU9250 via SPI!\r"); 00032 } 00033 pc.printf("\nWHOAMI=0x%2x\n\r",imu.whoami()); //output the I2C address to know if SPI is working, it should be 104 00034 wait(1); 00035 pc.printf("Gyro_scale=%u\n\r",imu.set_gyro_scale(BITS_FS_2000DPS)); //Set full scale range for gyros 00036 wait(1); 00037 pc.printf("Acc_scale=%u\n\r",imu.set_acc_scale(BITS_FS_16G)); //Set full scale range for accs 00038 wait(1); 00039 pc.printf("AK8963 WHIAM=0x%2x\n\r",imu.AK8963_whoami()); 00040 wait(0.1); 00041 imu.AK8963_calib_Magnetometer(); 00042 00043 fprintf(fp,"MPU9250_data, , , , , , , , , ,"); 00044 fprintf(fp,"BMP280_data, ,"); 00045 fprintf(fp,"GMT: ,N.Lat: ,E.Lng: ,stat: ,satnum: ,\r\n"); 00046 fprintf(fp,"MPU9250_data, , , , , , , , , ,"); 00047 fprintf(fp,"BMP280_data, ,"); 00048 fprintf(fp,"GMT: ,N.Lat: ,E.Lng: ,stat: ,satnum: ,\r\n"); 00049 00050 while (i<30) { 00051 wait(0.1); 00052 /* 00053 imu.read_temp(); 00054 imu.read_acc(); 00055 imu.read_rot(); 00056 imu.AK8963_read_Magnetometer(); 00057 */ 00058 imu.read_all(); 00059 pc.printf("%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f\n\r", 00060 imu.Temperature, 00061 imu.gyroscope_data[0], 00062 imu.gyroscope_data[1], 00063 imu.gyroscope_data[2], 00064 imu.accelerometer_data[0], 00065 imu.accelerometer_data[1], 00066 imu.accelerometer_data[2], 00067 imu.Magnetometer[0], 00068 imu.Magnetometer[1], 00069 imu.Magnetometer[2] 00070 ); 00071 fprintf(fp,"%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,%10.3f,", 00072 imu.Temperature, 00073 imu.gyroscope_data[0], 00074 imu.gyroscope_data[1], 00075 imu.gyroscope_data[2], 00076 imu.accelerometer_data[0], 00077 imu.accelerometer_data[1], 00078 imu.accelerometer_data[2], 00079 imu.Magnetometer[0], 00080 imu.Magnetometer[1], 00081 imu.Magnetometer[2] 00082 ); 00083 00084 pc.printf("%2.2f degC, %04.2f hPa\n\r", sensor.getTemperature(), sensor.getPressure()); 00085 fprintf(fp,"%2.2f , %04.2f ,", sensor.getTemperature(), sensor.getPressure()); 00086 00087 //accelerometer.read_mg_data(readings); 00088 //pc.printf("x=%f, y=%f, z=%f\r\n",readings[0],readings[1],readings[2]); 00089 //fprintf(fp,"%f, %f, %f,",readings[0],readings[1],readings[2]); 00090 00091 pc.printf("世界標準時:%02dh%02dm%02ds 北緯:%.8f 東経:%.8f 状態:%d 使用衛星数:%d\r\n", 00092 gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt); 00093 fprintf(fp,"%02dh%02dm%02ds ,%.8f ,%.8f ,%d ,%d\r\n", 00094 gps.g_hour, gps.g_min, gps.g_sec, gps.g_hokui, gps.g_tokei, gps.rlock, gps.stlgt); 00095 00096 led=!led; 00097 i++; 00098 } 00099 fclose(fp); 00100 }
Generated on Mon Jul 18 2022 21:54:53 by
1.7.2