valeria toffoli
/
COG4050_adxrs290_adxrs453
driver for gyro
Fork of COG4050_adxl355_adxl357-ver2 by
main.cpp@10:f1345517cdcf, 2018-09-21 (annotated)
- Committer:
- vtoffoli
- Date:
- Fri Sep 21 07:50:24 2018 +0000
- Revision:
- 10:f1345517cdcf
- Parent:
- 9:1afd906c5ed2
drivers;
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
APS_Lab | 0:74a0756399ff | 1 | #include "mbed.h" |
vtoffoli | 8:9e6ead2ee8d7 | 2 | #include <math.h> |
vtoffoli | 4:23b53636b576 | 3 | #include <inttypes.h> |
vtoffoli | 7:5aaa09c40283 | 4 | #include "ADXRS290.h" |
vtoffoli | 9:1afd906c5ed2 | 5 | |
vtoffoli | 2:14dc1ec57f3b | 6 | Serial pc(USBTX, USBRX); |
vtoffoli | 2:14dc1ec57f3b | 7 | |
vtoffoli | 7:5aaa09c40283 | 8 | ADXRS290 gyro(SPI0_CS2, SPI0_MOSI, SPI0_MISO, SPI0_SCLK); // PMOD port |
vtoffoli | 9:1afd906c5ed2 | 9 | Timeout t_loop; |
vtoffoli | 9:1afd906c5ed2 | 10 | |
vtoffoli | 9:1afd906c5ed2 | 11 | |
vtoffoli | 9:1afd906c5ed2 | 12 | |
vtoffoli | 9:1afd906c5ed2 | 13 | void meas() { |
vtoffoli | 9:1afd906c5ed2 | 14 | gyro.rate_data = gyro.scan(); |
vtoffoli | 9:1afd906c5ed2 | 15 | float x =float(gyro.rate_data.rt_x)*0.005*0.1; |
vtoffoli | 9:1afd906c5ed2 | 16 | float y =float(gyro.rate_data.rt_y)*0.005*0.1; |
vtoffoli | 9:1afd906c5ed2 | 17 | float z =float(gyro.rate_data.rt_z)*0.005*0.1; |
vtoffoli | 9:1afd906c5ed2 | 18 | pc.printf("°data = %f \t %f \t %f \r\n", x , y , z); |
vtoffoli | 9:1afd906c5ed2 | 19 | } |
vtoffoli | 9:1afd906c5ed2 | 20 | |
vtoffoli | 2:14dc1ec57f3b | 21 | int main(){ |
vtoffoli | 2:14dc1ec57f3b | 22 | pc.baud(9600); |
vtoffoli | 9:1afd906c5ed2 | 23 | pc.printf("SPI ADXRS Demo\n"); |
vtoffoli | 9:1afd906c5ed2 | 24 | // device info |
vtoffoli | 2:14dc1ec57f3b | 25 | pc.printf("GET device ID\n"); |
vtoffoli | 4:23b53636b576 | 26 | uint8_t d; |
vtoffoli | 9:1afd906c5ed2 | 27 | d=gyro.read_reg(gyro.ADI_ID); |
vtoffoli | 7:5aaa09c40283 | 28 | pc.printf("AD id = %x \r\n",d); |
vtoffoli | 9:1afd906c5ed2 | 29 | d=gyro.read_reg(gyro.MEMS_ID); |
vtoffoli | 7:5aaa09c40283 | 30 | pc.printf("MEMS id = %x \r\n",d); |
vtoffoli | 9:1afd906c5ed2 | 31 | d=gyro.read_reg(gyro.DEV_ID); |
vtoffoli | 7:5aaa09c40283 | 32 | pc.printf("device id = %x \r\n",d); |
vtoffoli | 9:1afd906c5ed2 | 33 | d=gyro.read_reg(gyro.REV_ID); |
vtoffoli | 7:5aaa09c40283 | 34 | pc.printf("revision id = %x \r\n",d); |
vtoffoli | 9:1afd906c5ed2 | 35 | // device data |
vtoffoli | 4:23b53636b576 | 36 | pc.printf("GET device data [x, y, z, t] \r\n"); |
vtoffoli | 9:1afd906c5ed2 | 37 | do { |
vtoffoli | 9:1afd906c5ed2 | 38 | t_loop.attach(&meas, 0.1); // setup to call measurement function after 0.1 seconds |
vtoffoli | 9:1afd906c5ed2 | 39 | } while(1); |
vtoffoli | 9:1afd906c5ed2 | 40 | } |