Code for Altimu10v4, reads all the i2c sensor and display its values trught serial.
Dependencies: L3GD20 LPS25H LSM303D mbed
main.cpp
00001 #include "mbed.h" 00002 #include "L3GD20.h" 00003 #include "LSM303D.h" 00004 #include "LPS25H.h" 00005 00006 I2C i2c(p28,p27); 00007 00008 L3GD20 gyro(p28, p27); 00009 LSM303D lsm(p28, p27); 00010 LPS25H baro(i2c, LPS25H_V_CHIP_ADDR); 00011 00012 Serial pc(USBTX,USBRX); 00013 00014 00015 int main(){ 00016 00017 float g[3]; 00018 float acc[3] ,mag[3]; 00019 pc.baud(9600); 00020 00021 while (1){ 00022 00023 //Gyroscope 00024 gyro.read(&g[0],&g[1],&g[2]); 00025 pc.printf("Gyro-> X:%f Y:%f Z:%f\n",g[0] ,g[1] ,g[2]); 00026 //Acell/Mag 00027 if (lsm.read(&acc[0],&acc[1],&acc[2],&mag[0],&mag[1],&mag[2])) 00028 { 00029 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]); 00030 } 00031 //Barometer 00032 baro.get(); 00033 pc.printf("Pres:%6.1fpa\nTemp: %4.1fc\n", baro.pressure(), baro.temperature()); 00034 wait(0.5); 00035 } 00036 }
Generated on Sat Jul 16 2022 16:05:05 by 1.7.2