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: X_NUCLEO_IKS01A2 mbed
Fork of HelloWorld_IKS01A2 by
main.cpp
00001 00002 /* Includes */ 00003 #include "mbed.h" 00004 #include "x_nucleo_iks01a2.h" 00005 00006 /* Instantiate the expansion board */ 00007 static X_NUCLEO_IKS01A2 *mems_expansion_board = X_NUCLEO_IKS01A2::Instance(D14, D15, D4, D5); 00008 00009 00010 #define sens 70 00011 00012 static LSM6DSLSensor *acc_gyro = mems_expansion_board->acc_gyro; 00013 00014 00015 /* Simple main function */ 00016 int main() { 00017 uint8_t id; 00018 int32_t axes[3]; 00019 int32_t off[3]; 00020 float parziale[3]; 00021 float finale[3]; 00022 int32_t k=0; 00023 for(int i=0;i<3;i++) 00024 {parziale[i]=0;} 00025 00026 for(int i=0;i<3;i++) 00027 {finale [i]=0;} 00028 /* Enable all sensors */ 00029 00030 acc_gyro->Enable_X(); 00031 acc_gyro->Enable_G(); 00032 00033 printf("\r\n--- Starting new run ---\r\n"); 00034 acc_gyro->ReadID(&id); 00035 printf("LSM6DSL accelerometer & gyroscope = 0x%X\r\n", id); 00036 wait(1.5); 00037 acc_gyro->Get_G_Axes(axes); 00038 printf("LSM6DSL [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); 00039 for(int i=0;i<3;i++){ 00040 off[i]=axes[i];} 00041 printf("off [gyro/mdps]: %6ld, %6ld, %6ld\r\n", off[0], off[1], off[2]); 00042 while(1) { 00043 printf("\r\n"); 00044 00045 acc_gyro->Get_X_Axes(axes); 00046 printf("LSM6DSL [acc/mg]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); 00047 00048 acc_gyro->Get_G_Axes(axes); 00049 printf("LSM6DSLrow [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); 00050 for(int i=0;i<3;i++) 00051 {axes[i]=axes[i]-off[i];} 00052 printf("LSM6DSLfine [gyro/mdps]: %6ld, %6ld, %6ld\r\n", axes[0], axes[1], axes[2]); 00053 k=k+1; 00054 wait_m(1); 00055 00056 // ricavo l'parziale dalla velocità angolare 00057 00058 for(int i=0;i<3;i++) 00059 { 00060 parziale[i]=(axes[i]*sens)/1000; 00061 00062 00063 parziale[i]/= 1000; 00064 if (axes[i]>150 ||axes[i]<-150) 00065 finale[i] += parziale[i]; 00066 00067 } 00068 printf("finale [gyro/d]: %6f, %6f, %6f\r\n", finale[0], finale[1], finale[2]);//angolo 00069 } 00070 }
Generated on Thu Jul 14 2022 09:38:11 by
1.7.2
