![](/media/cache/group/default_image.jpg.50x50_q85.jpg)
Code for Altimu10v4, reads all the i2c sensor and display its values trught serial.
Dependencies: L3GD20 LPS25H LSM303D mbed
main.cpp@0:1393d5ef2374, 2018-06-16 (annotated)
- Committer:
- renanbmx123
- Date:
- Sat Jun 16 03:27:53 2018 +0000
- Revision:
- 0:1393d5ef2374
First commit of Altimu10v4.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
renanbmx123 | 0:1393d5ef2374 | 1 | #include "mbed.h" |
renanbmx123 | 0:1393d5ef2374 | 2 | #include "L3GD20.h" |
renanbmx123 | 0:1393d5ef2374 | 3 | #include "LSM303D.h" |
renanbmx123 | 0:1393d5ef2374 | 4 | #include "LPS25H.h" |
renanbmx123 | 0:1393d5ef2374 | 5 | |
renanbmx123 | 0:1393d5ef2374 | 6 | I2C i2c(p28,p27); |
renanbmx123 | 0:1393d5ef2374 | 7 | |
renanbmx123 | 0:1393d5ef2374 | 8 | L3GD20 gyro(p28, p27); |
renanbmx123 | 0:1393d5ef2374 | 9 | LSM303D lsm(p28, p27); |
renanbmx123 | 0:1393d5ef2374 | 10 | LPS25H baro(i2c, LPS25H_V_CHIP_ADDR); |
renanbmx123 | 0:1393d5ef2374 | 11 | |
renanbmx123 | 0:1393d5ef2374 | 12 | Serial pc(USBTX,USBRX); |
renanbmx123 | 0:1393d5ef2374 | 13 | |
renanbmx123 | 0:1393d5ef2374 | 14 | |
renanbmx123 | 0:1393d5ef2374 | 15 | int main(){ |
renanbmx123 | 0:1393d5ef2374 | 16 | |
renanbmx123 | 0:1393d5ef2374 | 17 | float g[3]; |
renanbmx123 | 0:1393d5ef2374 | 18 | float acc[3] ,mag[3]; |
renanbmx123 | 0:1393d5ef2374 | 19 | pc.baud(9600); |
renanbmx123 | 0:1393d5ef2374 | 20 | |
renanbmx123 | 0:1393d5ef2374 | 21 | while (1){ |
renanbmx123 | 0:1393d5ef2374 | 22 | |
renanbmx123 | 0:1393d5ef2374 | 23 | //Gyroscope |
renanbmx123 | 0:1393d5ef2374 | 24 | gyro.read(&g[0],&g[1],&g[2]); |
renanbmx123 | 0:1393d5ef2374 | 25 | pc.printf("Gyro-> X:%f Y:%f Z:%f\n",g[0] ,g[1] ,g[2]); |
renanbmx123 | 0:1393d5ef2374 | 26 | //Acell/Mag |
renanbmx123 | 0:1393d5ef2374 | 27 | if (lsm.read(&acc[0],&acc[1],&acc[2],&mag[0],&mag[1],&mag[2])) |
renanbmx123 | 0:1393d5ef2374 | 28 | { |
renanbmx123 | 0:1393d5ef2374 | 29 | pc.printf("Acc-> X:%.3f Y%.3f Z%.3f\nMag-> X%3f Y%3f Z%3f)\n",acc[0],acc[1],acc[2],mag[0],mag[1],mag[2]); |
renanbmx123 | 0:1393d5ef2374 | 30 | } |
renanbmx123 | 0:1393d5ef2374 | 31 | //Barometer |
renanbmx123 | 0:1393d5ef2374 | 32 | baro.get(); |
renanbmx123 | 0:1393d5ef2374 | 33 | pc.printf("Pres:%6.1fpa\nTemp: %4.1fc\n", baro.pressure(), baro.temperature()); |
renanbmx123 | 0:1393d5ef2374 | 34 | wait(0.5); |
renanbmx123 | 0:1393d5ef2374 | 35 | } |
renanbmx123 | 0:1393d5ef2374 | 36 | } |