valeria toffoli
/
COG4050_adxrs290_adxrs453
driver for gyro
Fork of COG4050_adxl355_adxl357-ver2 by
Diff: main.cpp
- Revision:
- 9:1afd906c5ed2
- Parent:
- 8:9e6ead2ee8d7
--- a/main.cpp Tue Aug 21 13:25:37 2018 +0000 +++ b/main.cpp Fri Sep 07 15:49:25 2018 +0000 @@ -1,65 +1,40 @@ #include "mbed.h" #include <math.h> #include <inttypes.h> -#include "ADXL355.h" #include "ADXRS290.h" -#include "CALIBRATION.h" - + Serial pc(USBTX, USBRX); -ADXL355 accl(SPI1_CS0, SPI1_MOSI, SPI1_MISO, SPI1_SCLK); // PMOD port ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_SCLK); // PMOD port -CALIBRATION test; -float angle[3][12] = { {-55, -125, -147, 33, -128, 52, 0, 0, 0, 0, 0, 0}, - {6, -6, 20, -20, -69, 69, 0, 0, 0, 0, 0, 0 }, - {1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0}}; - float meas[3][12] = { {-0.09, 0.16, -0.31, 0.37, 0.91, -0.88}, - {-0.78, 0.81, -0.46, 0.49, -0.28, 0.32}, - {0.54, -0.55, -0.78, 0.76, -0.20, 0.20}}; +Timeout t_loop; + + + +void meas() { + gyro.rate_data = gyro.scan(); + float x =float(gyro.rate_data.rt_x)*0.005*0.1; + float y =float(gyro.rate_data.rt_y)*0.005*0.1; + float z =float(gyro.rate_data.rt_z)*0.005*0.1; + pc.printf("°data = %f \t %f \t %f \r\n", x , y , z); +} + int main(){ pc.baud(9600); - pc.printf("SPI ADXL355 and ADXL357 Demo\n"); + pc.printf("SPI ADXRS Demo\n"); + // device info pc.printf("GET device ID\n"); - accl.reset(); uint8_t d; - d=accl.read_reg(accl.DEVID_AD); + d=gyro.read_reg(gyro.ADI_ID); pc.printf("AD id = %x \r\n",d); - d=accl.read_reg(accl.DEVID_MST); + d=gyro.read_reg(gyro.MEMS_ID); pc.printf("MEMS id = %x \r\n",d); - d=accl.read_reg(accl.PARTID); + d=gyro.read_reg(gyro.DEV_ID); pc.printf("device id = %x \r\n",d); - d=accl.read_reg(accl.REVID); + d=gyro.read_reg(gyro.REV_ID); pc.printf("revision id = %x \r\n",d); + // device data pc.printf("GET device data [x, y, z, t] \r\n"); - accl.set_power_ctl_reg(accl.MEASUREMENT); - d=accl.read_reg(accl.POWER_CTL); - pc.printf("power control on measurement mode = %x \r\n",d); - float x, y,z; - float t; - // save data info a file - for(int i=0; i<100; i++) { - x = accl.convert(accl.scanx())*accl.axis355_sens; - y = accl.convert(accl.scany())*accl.axis355_sens; - z = accl.convert(accl.scanz())*accl.axis355_sens; - t = 25+float(accl.scant()-1852)/(-9.05); - pc.printf("%f \t %f \t %f \t %f \r\n" , x,y,z,t); - wait(0.1);} // test the calibration procedure - // test.matrix_reset(); - // test.matrix_g(angle); - // test.matrix_x(meas); - // int i, j; - - /* output each array element's value */ - /* - pc.printf("power control on measurement mode = %x \r\n",d); - for ( i = 0; i < 3; i++ ) { - for ( j = 0; j < 12; j++ ) { - pc.printf( "%f\n", i,j, test.g_matrix[i][j] ); - } - pc.printf("\r\n"); - */ - - //} - -} - \ No newline at end of file + do { + t_loop.attach(&meas, 0.1); // setup to call measurement function after 0.1 seconds + } while(1); +} \ No newline at end of file