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: Eigen
BMX055.h
00001 /* 00002 * mbed library program 00003 * BMX055 Small, versatile 9-axis sensor module 00004 * by Bosch Sensortec 00005 * 00006 * Copyright (c) 2018,'19 Kenji Arai / JH1PJL 00007 * http://www.page.sannet.ne.jp/kenjia/index.html 00008 * http://mbed.org/users/kenjiArai/ 00009 * Started: October 24th, 2018 00010 * Revised: March 3rd, 2019 00011 */ 00012 /* 00013 *---------------- REFERENCE --------------------------------------------------- 00014 * Original Information 00015 * https://www.bosch-sensortec.com/bst/products/all_products/bmx055 00016 * Data Sheet BST-BMX055-DS000-02 Rev.1.1 November 7th, 2014 00017 * Sample software 00018 * BMX055 - Combination of bma2x2 + bmg160 + bmm050 APIs 00019 * https://github.com/BoschSensortec/BMA2x2_driver 00020 * https://github.com/BoschSensortec/BMG160_driver 00021 * https://github.com/BoschSensortec/BMM050_driver 00022 * Aplied Board 00023 * AE-BMX055 Module 00024 * http://akizukidenshi.com/catalog/g/gK-13010/ 00025 */ 00026 00027 // NO Interrupt functions are supported due to no pin on AE-BMX055 Module 00028 // Only supprt normal mode (No sleep and/or standby mode) 00029 00030 #ifndef BMX055_H 00031 #define BMX055_H 00032 00033 #include "mbed.h" 00034 00035 #define AKIZUKI_BOARD 00036 00037 // BMX055 00038 // Automatic detection for the address!! 00039 // AE-BMX055 board default setting (All jumpers are open) 00040 #define BMX055_GYR_CHIP_ADDR (0x69 << 1) 00041 #define BMX055_ACC_CHIP_ADDR (0x19 << 1) 00042 #define BMX055_MAG_CHIP_ADDR (0x13 << 1) 00043 00044 // ID's 00045 #define I_AM_BMX055_ACC 0xfa // ACC ID 00046 #define I_AM_BMX055_GYR 0x0f // GYR ID 00047 #define I_AM_BMX055_MAG 0x32 // MAG ID 00048 00049 ////////////// PARAMETER DEFINITION /////////////////////// 00050 // ACC full scale 00051 #define ACC_2G 3 00052 #define ACC_4G 5 00053 #define ACC_8G 8 00054 #define ACC_16G 12 00055 00056 // Support only "filtered mode" 00057 // ACC Bandwidth (BW = ODR/2 (ODR = Output Data Rate)) 00058 #define ACC_BW7R81Hz 8 // 64 ms 00059 #define ACC_BW15R63Hz 9 // 32 ms 00060 #define ACC_BW31R25Hz 10 // 16 ms 00061 #define ACC_BW62R5Hz 11 // 8 ms 00062 #define ACC_BW125Hz 12 // 4 ms 00063 #define ACC_BW250Hz 13 // 2 ms 00064 #define ACC_BW500Hz 14 // 1 ms 00065 #define ACC_BW1kHz 15 // 0.5 ms 00066 00067 // Gyro Sampling (Data per Second) 00068 #define GYR_2000DPS 0 // full scal +/- 2000 Deg/s(61.0 mDeg/sec/LSB) 00069 #define GYR_1000DPS 1 // +/- 1000 Deg/s(30.5 mDeg/sec/LSB) 00070 #define GYR_500DPS 2 // +/- 500 Deg/s(15.3 mDeg/sec/LSB) 00071 #define GYR_250DPS 3 // +/- 250 Deg/s(7.6 mDeg/sec/LSB) 00072 #define GYR_125DPS 4 // +/- 125 Deg/s(3.8 mDeg/sec/LSB) 00073 00074 // Gyro Bandwidth 00075 #define GYR_2000Hz523Hz 0 // 2000 Hz ODR and unfiltered (BW(bandwidth) 523Hz) 00076 #define GYR_2000Hz230Hz 1 // 2000 Hz ODR 230 Hz BW 00077 #define GYR_1000Hz116Hz 2 // 1000 Hz ODR 116 Hz BW 00078 #define GYR_400Hz47Hz 3 // 400 Hz ODR 47 Hz BW 00079 #define GYR_200Hz23Hz 4 // 200 Hz ODR 23 Hz BW 00080 #define GYR_100Hz12Hz 5 // 100 Hz ODR 12 Hz BW 00081 #define GYR_200Hz64Hz 6 // 200 Hz ODR 64 Hz BW 00082 #define GYR_100Hz32Hz 7 // 100 Hz ODR 32 Hz BW 00083 00084 // MAG 00085 #define MAG_ODR10Hz 0 // 10 Hz ODR(default) 00086 #define MAG_ODR2Hz 1 // 2 Hz ODR 00087 #define MAG_ODR6Hz 2 // 6 Hz ODR 00088 #define MAG_ODR8Hz 3 // 8 Hz ODR 00089 #define MAG_ODR15Hz 4 // 15 Hz ODR 00090 #define MAG_ODR20Hz 5 // 20 Hz ODR 00091 #define MAG_ODR25Hz 6 // 25 Hz ODR 00092 #define MAG_ODR30Hz 7 // 30 Hz ODR 00093 00094 ////////////// DATA TYPE DEFINITION /////////////////////// 00095 typedef struct { 00096 // ACC 00097 uint8_t acc_fs; // Accelerometer full scale range 00098 uint8_t acc_bw; // Accelerometer filtered bandwidth 00099 // GYR 00100 uint8_t gyr_fs; // Gyroscope full scale range 00101 uint8_t gyr_bw; // Gyroscope filtered bandwidth 00102 // MAG 00103 uint8_t mag_odr; // Magnetometer Output Data Rate 00104 } BMX055_TypeDef; 00105 00106 ////////////// DEFAULT SETTING //////////////////////////// 00107 // Standard parameter for easy set-up 00108 const BMX055_TypeDef bmx055_std_paramtr = { 00109 // ACC 00110 ACC_2G, 00111 ACC_BW31R25Hz, // ACC_BW31R25Hz -> ODR = 62.5 Hz 00112 // GYR 00113 GYR_500DPS, 00114 GYR_200Hz23Hz, 00115 // MAG 00116 MAG_ODR30Hz 00117 }; 00118 00119 ////////////// DATA TYPE DEFINITION /////////////////////// 00120 typedef struct { 00121 uint8_t acc_addr; 00122 uint8_t mag_addr; 00123 uint8_t gyr_addr; 00124 } BMX055_ADDR_INF_TypeDef; 00125 00126 typedef struct { 00127 uint8_t acc_id; 00128 uint8_t mag_id; 00129 uint8_t gyr_id; 00130 } BMX055_ID_INF_TypeDef; 00131 00132 typedef struct { 00133 float x; 00134 float y; 00135 float z; 00136 } BMX055_ACCEL_TypeDef; 00137 00138 typedef struct { 00139 float x; 00140 float y; 00141 float z; 00142 } BMX055_GRAVITY_TypeDef; 00143 00144 typedef struct { 00145 float x; 00146 float y; 00147 float z; 00148 } BMX055_GYRO_TypeDef; 00149 00150 typedef struct { 00151 float x; 00152 float y; 00153 float z; 00154 } BMX055_MAGNET_TypeDef; 00155 00156 /** BMX055 Small, versatile 9-axis sensor module by Bosch Sensortec 00157 * @code 00158 * #include "mbed.h" 00159 * #include "BMX055.h" 00160 * 00161 * Serial pc(USBTX,USBRX); 00162 * I2C (I2C_SDA, I2C_SCL); 00163 * BMX055 imu(i2c); 00164 * 00165 * const BMX055_TypeDef bmx055_my_parameters = { 00166 * // ACC 00167 * ACC_2G, 00168 * ACC_BW250Hz, 00169 * // GYR 00170 * GYR_125DPS, 00171 * GYR_200Hz23Hz, 00172 * // MAG 00173 * MAG_ODR10Hz 00174 * }; 00175 * 00176 * int main() { 00177 * BMX055_ACCEL_TypeDef acc; 00178 * BMX055_GYRO_TypeDef gyr; 00179 * BMX055_MAGNET_TypeDef mag; 00180 * 00181 * if (imu.imu.chip_ready() == 0){ 00182 * pc.printf("Bosch BMX055 is NOT avirable!!\r\n"); 00183 * } 00184 * imu.set_parameter(&bmx055_my_parameters); 00185 * while(1) { 00186 * imu.get_accel(&acc); 00187 * pc.printf("//ACC: x=%+3.2f y=%+3.2f z=%+3.2f //", 00188 * acc.x, acc.y, acc.z); 00189 * imu.get_gyro(&gyr); 00190 * pc.printf("GYR: x=%+3.2f y=%+3.2f z=%+3.2f //", 00191 * gyr.x, gyr.y, gyr.z); 00192 * imu.get_magnet(&mag); 00193 * pc.printf("MAG: x=%+3.2f y=%+3.2f z=%+3.2f , passed %u sec\r\n", 00194 * mag.x, mag.y, mag.z, n++); 00195 * wait(0.5f); 00196 * } 00197 * } 00198 * @endcode 00199 */ 00200 00201 class BMX055 00202 { 00203 public: 00204 /** Configure data pin 00205 * @param data SDA and SCL pins 00206 * @param Other parameters are set automatically 00207 */ 00208 BMX055(I2C& i2c); 00209 00210 /** Configure data pin (with other devices on I2C line) 00211 * @param I2C previous definition 00212 * @param Other parameters are set automatically 00213 */ 00214 00215 /** Get accel data 00216 * @param float type of 3D data address 00217 */ 00218 float get_chip_temperature(void); 00219 00220 /** Read BMX055 ID information 00221 * @param ID information address 00222 * @return none 00223 */ 00224 void read_id_inf(BMX055_ID_INF_TypeDef *id); 00225 00226 /** Check chip is avairable or not 00227 * @param none 00228 * @return OK = true, NG = false; 00229 */ 00230 bool chip_ready(void); 00231 00232 /** Check chip is avairable or not 00233 * @param configration parameter 00234 * @return none 00235 */ 00236 void set_parameter(const BMX055_TypeDef *bmx055_parameter); 00237 00238 /** Set I2C clock frequency 00239 * @param freq. 00240 * @return none 00241 */ 00242 void frequency(int hz); 00243 00244 /** Read register 00245 * @param register's address 00246 * @return register data 00247 */ 00248 uint8_t read_reg(uint8_t addr); 00249 00250 /** Write register 00251 * @param register's address 00252 * @param data 00253 * @return register data 00254 */ 00255 uint8_t write_reg(uint8_t addr, uint8_t data); 00256 void readAccel(void); 00257 void readGyro(void); 00258 void readMag(void); 00259 float gyroX, gyroY, gyroZ; // x, y, and z axis readings of the gyroscope (float value) 00260 float accX, accY, accZ; // x, y, and z axis readings of the accelerometer (float value) 00261 float magX, magY, magZ; // x, y, and z axis readings of the magnetometer (float value) 00262 uint16_t begin(); 00263 protected: 00264 void initialize(void); 00265 void check_id(void); 00266 void set_parameters_to_regs(void); 00267 00268 I2C &i2c; 00269 00270 00271 private: 00272 char dt[16]; // working buffer 00273 uint8_t chip_addr; 00274 BMX055_ADDR_INF_TypeDef inf_addr; 00275 BMX055_ID_INF_TypeDef inf_id; 00276 float gyr_factor, acc_factor; 00277 uint8_t ready_flag; 00278 00279 00280 00281 BMX055_TypeDef bmx055_parameters; 00282 uint8_t acc_id; 00283 uint8_t mag_id; 00284 uint8_t gyr_id; 00285 }; 00286 00287 00288 #endif // BMX055_H
Generated on Thu Jul 14 2022 22:08:52 by
1.7.2