├── DFRobot_BMX160.cpp ├── DFRobot_BMX160.h ├── LICENSE ├── README.md ├── README_CN.md ├── examples ├── readAccelData │ └── readAccelData.ino ├── readAllData │ └── readAllData.ino ├── readGyroData │ └── readGyroData.ino ├── readMagnData │ └── readMagnData.ino └── setLowPower │ └── setLowPower.ino ├── keywords.txt ├── library.properties ├── python └── raspberrypi │ ├── DFRobot_BMX160.py │ ├── README.md │ ├── README_CN.md │ └── examples │ ├── read_accel_data │ └── read_accel_data.py │ ├── read_all_data │ └── read_all_data.py │ ├── read_gyro_data │ └── read_gyro_data.py │ ├── read_magn_data │ └── read_magn_data.py │ └── set_low_power │ └── set_low_power.py └── resources └── images └── SEN0373.png /DFRobot_BMX160.cpp: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file DFRobot_BMX160.cpp 3 | * @brief define DFRobot_BMX160 class infrastructure, the implementation of basic methods 4 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 5 | * @license The MIT License (MIT) 6 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 7 | * @maintainer [Fary](feng.yang@dfrobot.com) 8 | * @version V1.0 9 | * @date 2021-10-20 10 | * @url https://github.com/DFRobot/DFRobot_BMX160 11 | */ 12 | #include "DFRobot_BMX160.h" 13 | 14 | DFRobot_BMX160::DFRobot_BMX160(TwoWire *pWire) 15 | { 16 | _pWire = pWire; 17 | Obmx160 = (sBmx160Dev_t *)malloc(sizeof(sBmx160Dev_t)); 18 | Oaccel = ( sBmx160SensorData_t*)malloc(sizeof( sBmx160SensorData_t)); 19 | Ogyro = ( sBmx160SensorData_t*)malloc(sizeof( sBmx160SensorData_t)); 20 | Omagn = ( sBmx160SensorData_t*)malloc(sizeof( sBmx160SensorData_t)); 21 | } 22 | 23 | const uint8_t int_mask_lookup_table[13] = { 24 | BMX160_INT1_SLOPE_MASK, 25 | BMX160_INT1_SLOPE_MASK, 26 | BMX160_INT2_LOW_STEP_DETECT_MASK, 27 | BMX160_INT1_DOUBLE_TAP_MASK, 28 | BMX160_INT1_SINGLE_TAP_MASK, 29 | BMX160_INT1_ORIENT_MASK, 30 | BMX160_INT1_FLAT_MASK, 31 | BMX160_INT1_HIGH_G_MASK, 32 | BMX160_INT1_LOW_G_MASK, 33 | BMX160_INT1_NO_MOTION_MASK, 34 | BMX160_INT2_DATA_READY_MASK, 35 | BMX160_INT2_FIFO_FULL_MASK, 36 | BMX160_INT2_FIFO_WM_MASK 37 | }; 38 | 39 | bool DFRobot_BMX160::begin() 40 | { 41 | _pWire->begin(); 42 | if (scan() == true){ 43 | softReset(); 44 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x11); 45 | delay(50); 46 | /* Set gyro to normal mode */ 47 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x15); 48 | delay(100); 49 | /* Set mag to normal mode */ 50 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x19); 51 | delay(10); 52 | setMagnConf(); 53 | return true; 54 | } 55 | else 56 | return false; 57 | } 58 | 59 | void DFRobot_BMX160::setLowPower(){ 60 | softReset(); 61 | delay(100); 62 | setMagnConf(); 63 | delay(100); 64 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x12); 65 | delay(100); 66 | /* Set gyro to normal mode */ 67 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x17); 68 | delay(100); 69 | /* Set mag to normal mode */ 70 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x1B); 71 | delay(100); 72 | } 73 | 74 | void DFRobot_BMX160::wakeUp(){ 75 | softReset(); 76 | delay(100); 77 | setMagnConf(); 78 | delay(100); 79 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x11); 80 | delay(100); 81 | /* Set gyro to normal mode */ 82 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x15); 83 | delay(100); 84 | /* Set mag to normal mode */ 85 | writeBmxReg(BMX160_COMMAND_REG_ADDR, 0x19); 86 | delay(100); 87 | } 88 | 89 | bool DFRobot_BMX160::softReset() 90 | { 91 | int8_t rslt=BMX160_OK; 92 | if (Obmx160 == NULL){ 93 | rslt = BMX160_E_NULL_PTR; 94 | } 95 | rslt = _softReset(Obmx160); 96 | if (rslt == 0) 97 | return true; 98 | else 99 | return false; 100 | } 101 | 102 | int8_t DFRobot_BMX160:: _softReset(sBmx160Dev_t *dev) 103 | { 104 | int8_t rslt=BMX160_OK; 105 | uint8_t data = BMX160_SOFT_RESET_CMD; 106 | if (dev==NULL){ 107 | rslt = BMX160_E_NULL_PTR; 108 | } 109 | writeBmxReg(BMX160_COMMAND_REG_ADDR, data); 110 | delay(BMX160_SOFT_RESET_DELAY_MS); 111 | if (rslt == BMX160_OK){ 112 | DFRobot_BMX160::defaultParamSettg(dev); 113 | } 114 | return rslt; 115 | } 116 | 117 | void DFRobot_BMX160::defaultParamSettg(sBmx160Dev_t *dev) 118 | { 119 | // Initializing accel and gyro params with 120 | dev->gyroCfg.bw = BMX160_GYRO_BW_NORMAL_MODE; 121 | dev->gyroCfg.odr = BMX160_GYRO_ODR_100HZ; 122 | dev->gyroCfg.power = BMX160_GYRO_SUSPEND_MODE; 123 | dev->gyroCfg.range = BMX160_GYRO_RANGE_2000_DPS; 124 | dev->accelCfg.bw = BMX160_ACCEL_BW_NORMAL_AVG4; 125 | dev->accelCfg.odr = BMX160_ACCEL_ODR_100HZ; 126 | dev->accelCfg.power = BMX160_ACCEL_SUSPEND_MODE; 127 | dev->accelCfg.range = BMX160_ACCEL_RANGE_2G; 128 | 129 | 130 | dev->prevMagnCfg = dev->magnCfg; 131 | dev->prevGyroCfg = dev->gyroCfg; 132 | dev->prevAccelCfg = dev->accelCfg; 133 | } 134 | 135 | void DFRobot_BMX160::setMagnConf() 136 | { 137 | writeBmxReg(BMX160_MAGN_IF_0_ADDR, 0x80); 138 | delay(50); 139 | // Sleep mode 140 | writeBmxReg(BMX160_MAGN_IF_3_ADDR, 0x01); 141 | writeBmxReg(BMX160_MAGN_IF_2_ADDR, 0x4B); 142 | // REPXY regular preset 143 | writeBmxReg(BMX160_MAGN_IF_3_ADDR, 0x04); 144 | writeBmxReg(BMX160_MAGN_IF_2_ADDR, 0x51); 145 | // REPZ regular preset 146 | writeBmxReg(BMX160_MAGN_IF_3_ADDR, 0x0E); 147 | writeBmxReg(BMX160_MAGN_IF_2_ADDR, 0x52); 148 | 149 | writeBmxReg(BMX160_MAGN_IF_3_ADDR, 0x02); 150 | writeBmxReg(BMX160_MAGN_IF_2_ADDR, 0x4C); 151 | writeBmxReg(BMX160_MAGN_IF_1_ADDR, 0x42); 152 | writeBmxReg(BMX160_MAGN_CONFIG_ADDR, 0x08); 153 | writeBmxReg(BMX160_MAGN_IF_0_ADDR, 0x03); 154 | delay(50); 155 | } 156 | 157 | void DFRobot_BMX160::setGyroRange(eGyroRange_t bits){ 158 | switch (bits){ 159 | case eGyroRange_125DPS: 160 | gyroRange = BMX160_GYRO_SENSITIVITY_125DPS; 161 | break; 162 | case eGyroRange_250DPS: 163 | gyroRange = BMX160_GYRO_SENSITIVITY_250DPS; 164 | break; 165 | case eGyroRange_500DPS: 166 | gyroRange = BMX160_GYRO_SENSITIVITY_500DPS; 167 | break; 168 | case eGyroRange_1000DPS: 169 | gyroRange = BMX160_GYRO_SENSITIVITY_1000DPS; 170 | break; 171 | case eGyroRange_2000DPS: 172 | gyroRange = BMX160_GYRO_SENSITIVITY_2000DPS; 173 | break; 174 | default: 175 | gyroRange = BMX160_GYRO_SENSITIVITY_250DPS; 176 | break; 177 | } 178 | } 179 | 180 | void DFRobot_BMX160::setAccelRange(eAccelRange_t bits){ 181 | switch (bits){ 182 | case eAccelRange_2G: 183 | accelRange = BMX160_ACCEL_MG_LSB_2G * 10; 184 | break; 185 | case eAccelRange_4G: 186 | accelRange = BMX160_ACCEL_MG_LSB_4G * 10; 187 | break; 188 | case eAccelRange_8G: 189 | accelRange = BMX160_ACCEL_MG_LSB_8G * 10; 190 | break; 191 | case eAccelRange_16G: 192 | accelRange = BMX160_ACCEL_MG_LSB_16G * 10; 193 | break; 194 | default: 195 | accelRange = BMX160_ACCEL_MG_LSB_2G * 10; 196 | break; 197 | } 198 | } 199 | 200 | void DFRobot_BMX160::getAllData(sBmx160SensorData_t *magn, sBmx160SensorData_t *gyro, sBmx160SensorData_t *accel){ 201 | 202 | uint8_t data[23] = {0}; 203 | int16_t x=0,y=0,z=0; 204 | // put your main code here, to run repeatedly: 205 | readReg(BMX160_MAG_DATA_ADDR, data, 23); 206 | if(magn){ 207 | x = (int16_t) (((uint16_t)data[1] << 8) | data[0]); 208 | y = (int16_t) (((uint16_t)data[3] << 8) | data[2]); 209 | z = (int16_t) (((uint16_t)data[5] << 8) | data[4]); 210 | magn->x = x * BMX160_MAGN_UT_LSB; 211 | magn->y = y * BMX160_MAGN_UT_LSB; 212 | magn->z = z * BMX160_MAGN_UT_LSB; 213 | } 214 | if(gyro){ 215 | x = (int16_t) (((uint16_t)data[9] << 8) | data[8]); 216 | y = (int16_t) (((uint16_t)data[11] << 8) | data[10]); 217 | z = (int16_t) (((uint16_t)data[13] << 8) | data[12]); 218 | gyro->x = x * gyroRange; 219 | gyro->y = y * gyroRange; 220 | gyro->z = z * gyroRange; 221 | } 222 | if(accel){ 223 | x = (int16_t) (((uint16_t)data[15] << 8) | data[14]); 224 | y = (int16_t) (((uint16_t)data[17] << 8) | data[16]); 225 | z = (int16_t) (((uint16_t)data[19] << 8) | data[18]); 226 | accel->x = x * accelRange; 227 | accel->y = y * accelRange; 228 | accel->z = z * accelRange; 229 | } 230 | } 231 | 232 | void DFRobot_BMX160::writeBmxReg(uint8_t reg, uint8_t value) 233 | { 234 | uint8_t buffer[1] = {value}; 235 | writeReg(reg, buffer, 1); 236 | } 237 | 238 | void DFRobot_BMX160::writeReg(uint8_t reg, uint8_t *pBuf, uint16_t len) 239 | { 240 | _pWire->beginTransmission(_addr); 241 | _pWire->write(reg); 242 | for(uint16_t i = 0; i < len; i ++) 243 | _pWire->write(pBuf[i]); 244 | _pWire->endTransmission(); 245 | } 246 | 247 | void DFRobot_BMX160::readReg(uint8_t reg, uint8_t *pBuf, uint16_t len) 248 | { 249 | _pWire->beginTransmission(_addr); 250 | _pWire->write(reg); 251 | if(_pWire->endTransmission() != 0) 252 | return; 253 | _pWire->requestFrom(_addr, (uint8_t) len); 254 | for(uint16_t i = 0; i < len; i ++) { 255 | pBuf[i] =_pWire->read(); 256 | } 257 | _pWire->endTransmission(); 258 | } 259 | 260 | bool DFRobot_BMX160::scan() 261 | { 262 | _pWire->beginTransmission(_addr); 263 | if (_pWire->endTransmission() == 0){ 264 | return true; 265 | } 266 | return false; 267 | } -------------------------------------------------------------------------------- /DFRobot_BMX160.h: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file DFRobot_BMX160.h 3 | * @brief DFRobot_BMX160 class infrastructure 4 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 5 | * @license The MIT License (MIT) 6 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 7 | * @maintainer [Fary](feng.yang@dfrobot.com) 8 | * @version V1.0 9 | * @date 2021-10-20 10 | * @url https://github.com/DFRobot/DFRobot_BMX160 11 | */ 12 | #include 13 | #include 14 | #include 15 | 16 | /** Mask definitions */ 17 | #define BMX160_ACCEL_BW_MASK 0x70 18 | #define BMX160_ACCEL_ODR_MASK 0x0F 19 | #define BMX160_ACCEL_UNDERSAMPLING_MASK 0x80 20 | #define BMX160_ACCEL_RANGE_MASK 0x0F 21 | #define BMX160_GYRO_BW_MASK 0x30 22 | #define BMX160_GYRO_ODR_MASK 0x0F 23 | #define BMX160_GYRO_RANGE_MSK 0x07 24 | 25 | /** Mask definitions for INT_EN registers */ 26 | #define BMX160_ANY_MOTION_X_INT_EN_MASK 0x01 27 | #define BMX160_HIGH_G_X_INT_EN_MASK 0x01 28 | #define BMX160_NO_MOTION_X_INT_EN_MASK 0x01 29 | #define BMX160_ANY_MOTION_Y_INT_EN_MASK 0x02 30 | #define BMX160_HIGH_G_Y_INT_EN_MASK 0x02 31 | #define BMX160_NO_MOTION_Y_INT_EN_MASK 0x02 32 | #define BMX160_ANY_MOTION_Z_INT_EN_MASK 0x04 33 | #define BMX160_HIGH_G_Z_INT_EN_MASK 0x04 34 | #define BMX160_NO_MOTION_Z_INT_EN_MASK 0x04 35 | #define BMX160_SIG_MOTION_INT_EN_MASK 0x07 36 | #define BMX160_ANY_MOTION_ALL_INT_EN_MASK 0x07 37 | #define BMX160_STEP_DETECT_INT_EN_MASK 0x08 38 | #define BMX160_DOUBLE_TAP_INT_EN_MASK 0x10 39 | #define BMX160_SINGLE_TAP_INT_EN_MASK 0x20 40 | #define BMX160_FIFO_FULL_INT_EN_MASK 0x20 41 | #define BMX160_ORIENT_INT_EN_MASK 0x40 42 | #define BMX160_FIFO_WATERMARK_INT_EN_MASK 0x40 43 | #define BMX160_LOW_G_INT_EN_MASK 0x08 44 | #define BMX160_STEP_DETECT_EN_MASK 0x08 45 | #define BMX160_FLAT_INT_EN_MASK 0x80 46 | #define BMX160_DATA_RDY_INT_EN_MASK 0x10 47 | 48 | /** Mask definitions for INT_OUT_CTRL register */ 49 | #define BMX160_INT1_EDGE_CTRL_MASK 0x01 50 | #define BMX160_INT1_OUTPUT_MODE_MASK 0x04 51 | #define BMX160_INT1_OUTPUT_TYPE_MASK 0x02 52 | #define BMX160_INT1_OUTPUT_EN_MASK 0x08 53 | #define BMX160_INT2_EDGE_CTRL_MASK 0x10 54 | #define BMX160_INT2_OUTPUT_MODE_MASK 0x40 55 | #define BMX160_INT2_OUTPUT_TYPE_MASK 0x20 56 | #define BMX160_INT2_OUTPUT_EN_MASK 0x80 57 | 58 | /** Mask definitions for INT_LATCH register */ 59 | #define BMX160_INT1_INPUT_EN_MASK 0x10 60 | #define BMX160_INT2_INPUT_EN_MASK 0x20 61 | #define BMX160_INT_LATCH_MASK 0x0F 62 | 63 | /** Mask definitions for INT_MAP register */ 64 | #define BMX160_INT1_LOW_G_MASK 0x01 65 | #define BMX160_INT1_HIGH_G_MASK 0x02 66 | #define BMX160_INT1_SLOPE_MASK 0x04 67 | #define BMX160_INT1_NO_MOTION_MASK 0x08 68 | #define BMX160_INT1_DOUBLE_TAP_MASK 0x10 69 | #define BMX160_INT1_SINGLE_TAP_MASK 0x20 70 | #define BMX160_INT1_FIFO_FULL_MASK 0x20 71 | #define BMX160_INT1_FIFO_WM_MASK 0x40 72 | #define BMX160_INT1_ORIENT_MASK 0x40 73 | #define BMX160_INT1_FLAT_MASK 0x80 74 | #define BMX160_INT1_DATA_READY_MASK 0x80 75 | #define BMX160_INT2_LOW_G_MASK 0x01 76 | #define BMX160_INT1_LOW_STEP_DETECT_MASK 0x01 77 | #define BMX160_INT2_LOW_STEP_DETECT_MASK 0x01 78 | #define BMX160_INT2_HIGH_G_MASK 0x02 79 | #define BMX160_INT2_FIFO_FULL_MASK 0x02 80 | #define BMX160_INT2_FIFO_WM_MASK 0x04 81 | #define BMX160_INT2_SLOPE_MASK 0x04 82 | #define BMX160_INT2_DATA_READY_MASK 0x08 83 | #define BMX160_INT2_NO_MOTION_MASK 0x08 84 | #define BMX160_INT2_DOUBLE_TAP_MASK 0x10 85 | #define BMX160_INT2_SINGLE_TAP_MASK 0x20 86 | #define BMX160_INT2_ORIENT_MASK 0x40 87 | #define BMX160_INT2_FLAT_MASK 0x80 88 | 89 | /** Mask definitions for INT_DATA register */ 90 | #define BMX160_TAP_SRC_INT_MASK 0x08 91 | #define BMX160_LOW_HIGH_SRC_INT_MASK 0x80 92 | #define BMX160_MOTION_SRC_INT_MASK 0x80 93 | 94 | /** Mask definitions for INT_MOTION register */ 95 | #define BMX160_SLOPE_INT_DUR_MASK 0x03 96 | #define BMX160_NO_MOTION_INT_DUR_MASK 0xFC 97 | #define BMX160_NO_MOTION_SEL_BIT_MASK 0x01 98 | 99 | /** Mask definitions for INT_TAP register */ 100 | #define BMX160_TAP_DUR_MASK 0x07 101 | #define BMX160_TAP_SHOCK_DUR_MASK 0x40 102 | #define BMX160_TAP_QUIET_DUR_MASK 0x80 103 | #define BMX160_TAP_THRES_MASK 0x1F 104 | 105 | /** Mask definitions for INT_FLAT register */ 106 | #define BMX160_FLAT_THRES_MASK 0x3F 107 | #define BMX160_FLAT_HOLD_TIME_MASK 0x30 108 | #define BMX160_FLAT_HYST_MASK 0x07 109 | 110 | /** Mask definitions for INT_LOWHIGH register */ 111 | #define BMX160_LOW_G_HYST_MASK 0x03 112 | #define BMX160_LOW_G_LOW_MODE_MASK 0x04 113 | #define BMX160_HIGH_G_HYST_MASK 0xC0 114 | 115 | /** Mask definitions for INT_SIG_MOTION register */ 116 | #define BMX160_SIG_MOTION_SEL_MASK 0x02 117 | #define BMX160_SIG_MOTION_SKIP_MASK 0x0C 118 | #define BMX160_SIG_MOTION_PROOF_MASK 0x30 119 | 120 | /** Mask definitions for INT_ORIENT register */ 121 | #define BMX160_ORIENT_MODE_MASK 0x03 122 | #define BMX160_ORIENT_BLOCK_MASK 0x0C 123 | #define BMX160_ORIENT_HYST_MASK 0xF0 124 | #define BMX160_ORIENT_THETA_MASK 0x3F 125 | #define BMX160_ORIENT_UD_ENABLE 0x40 126 | #define BMX160_AXES_EN_MASK 0x80 127 | 128 | /** Mask definitions for FIFO_CONFIG register */ 129 | #define BMX160_FIFO_GYRO 0x80 130 | #define BMX160_FIFO_ACCEL 0x40 131 | #define BMX160_FIFO_MAGN 0x20 132 | #define BMX160_FIFO_TAG_INT1 0x08 133 | #define BMX160_FIFO_TAG_INT2 0x04 134 | #define BMX160_FIFO_TIME 0x02 135 | #define BMX160_FIFO_HEADER 0x10 136 | #define BMX160_FIFO_CONFIG_1_MASK 0xFE 137 | 138 | 139 | /** Mask definitions for STEP_CONF register */ 140 | #define BMX160_STEP_COUNT_EN_BIT_MASK 0x08 141 | #define BMX160_STEP_DETECT_MIN_THRES_MASK 0x18 142 | #define BMX160_STEP_DETECT_STEPTIME_MIN_MASK 0x07 143 | #define BMX160_STEP_MIN_BUF_MASK 0x07 144 | 145 | /** Mask definition for FIFO Header Data Tag */ 146 | #define BMX160_FIFO_TAG_INTR_MASK 0xFC 147 | 148 | /** Fifo byte counter mask definitions */ 149 | #define BMX160_FIFO_BYTE_COUNTER_MASK 0x07 150 | 151 | /** Enable/disable bit value */ 152 | #define BMX160_ENABLE 0x01 153 | #define BMX160_DISABLE 0x00 154 | 155 | /** Latch Duration */ 156 | #define BMX160_LATCH_DUR_NONE 0x00 157 | #define BMX160_LATCH_DUR_312_5_MICRO_SEC 0x01 158 | #define BMX160_LATCH_DUR_625_MICRO_SEC 0x02 159 | #define BMX160_LATCH_DUR_1_25_MILLI_SEC 0x03 160 | #define BMX160_LATCH_DUR_2_5_MILLI_SEC 0x04 161 | #define BMX160_LATCH_DUR_5_MILLI_SEC 0x05 162 | #define BMX160_LATCH_DUR_10_MILLI_SEC 0x06 163 | #define BMX160_LATCH_DUR_20_MILLI_SEC 0x07 164 | #define BMX160_LATCH_DUR_40_MILLI_SEC 0x08 165 | #define BMX160_LATCH_DUR_80_MILLI_SEC 0x09 166 | #define BMX160_LATCH_DUR_160_MILLI_SEC 0x0A 167 | #define BMX160_LATCH_DUR_320_MILLI_SEC 0x0B 168 | #define BMX160_LATCH_DUR_640_MILLI_SEC 0x0C 169 | #define BMX160_LATCH_DUR_1_28_SEC 0x0D 170 | #define BMX160_LATCH_DUR_2_56_SEC 0x0E 171 | #define BMX160_LATCHED 0x0F 172 | 173 | /** bmx160 Register map */ 174 | #define BMX160_CHIP_ID_ADDR 0x00 175 | #define BMX160_ERROR_REG_ADDR 0x02 176 | #define BMX160_MAG_DATA_ADDR 0x04 177 | #define BMX160_GYRO_DATA_ADDR 0x0C 178 | #define BMX160_ACCEL_DATA_ADDR 0x12 179 | #define BMX160_STATUS_ADDR 0x1B 180 | #define BMX160_INT_STATUS_ADDR 0x1C 181 | #define BMX160_FIFO_LENGTH_ADDR 0x22 182 | #define BMX160_FIFO_DATA_ADDR 0x24 183 | #define BMX160_ACCEL_CONFIG_ADDR 0x40 184 | #define BMX160_ACCEL_RANGE_ADDR 0x41 185 | #define BMX160_GYRO_CONFIG_ADDR 0x42 186 | #define BMX160_GYRO_RANGE_ADDR 0x43 187 | #define BMX160_MAGN_CONFIG_ADDR 0x44 188 | #define BMX160_FIFO_DOWN_ADDR 0x45 189 | #define BMX160_FIFO_CONFIG_0_ADDR 0x46 190 | #define BMX160_FIFO_CONFIG_1_ADDR 0x47 191 | #define BMX160_MAGN_RANGE_ADDR 0x4B 192 | #define BMX160_MAGN_IF_0_ADDR 0x4C 193 | #define BMX160_MAGN_IF_1_ADDR 0x4D 194 | #define BMX160_MAGN_IF_2_ADDR 0x4E 195 | #define BMX160_MAGN_IF_3_ADDR 0x4F 196 | #define BMX160_INT_ENABLE_0_ADDR 0x50 197 | #define BMX160_INT_ENABLE_1_ADDR 0x51 198 | #define BMX160_INT_ENABLE_2_ADDR 0x52 199 | #define BMX160_INT_OUT_CTRL_ADDR 0x53 200 | #define BMX160_INT_LATCH_ADDR 0x54 201 | #define BMX160_INT_MAP_0_ADDR 0x55 202 | #define BMX160_INT_MAP_1_ADDR 0x56 203 | #define BMX160_INT_MAP_2_ADDR 0x57 204 | #define BMX160_INT_DATA_0_ADDR 0x58 205 | #define BMX160_INT_DATA_1_ADDR 0x59 206 | #define BMX160_INT_LOWHIGH_0_ADDR 0x5A 207 | #define BMX160_INT_LOWHIGH_1_ADDR 0x5B 208 | #define BMX160_INT_LOWHIGH_2_ADDR 0x5C 209 | #define BMX160_INT_LOWHIGH_3_ADDR 0x5D 210 | #define BMX160_INT_LOWHIGH_4_ADDR 0x5E 211 | #define BMX160_INT_MOTION_0_ADDR 0x5F 212 | #define BMX160_INT_MOTION_1_ADDR 0x60 213 | #define BMX160_INT_MOTION_2_ADDR 0x61 214 | #define BMX160_INT_MOTION_3_ADDR 0x62 215 | #define BMX160_INT_TAP_0_ADDR 0x63 216 | #define BMX160_INT_TAP_1_ADDR 0x64 217 | #define BMX160_INT_ORIENT_0_ADDR 0x65 218 | #define BMX160_INT_ORIENT_1_ADDR 0x66 219 | #define BMX160_INT_FLAT_0_ADDR 0x67 220 | #define BMX160_INT_FLAT_1_ADDR 0x68 221 | #define BMX160_FOC_CONF_ADDR 0x69 222 | #define BMX160_CONF_ADDR 0x6A 223 | 224 | #define BMX160_IF_CONF_ADDR 0x6B 225 | #define BMX160_SELF_TEST_ADDR 0x6D 226 | #define BMX160_OFFSET_ADDR 0x71 227 | #define BMX160_OFFSET_CONF_ADDR 0x77 228 | #define BMX160_INT_STEP_CNT_0_ADDR 0x78 229 | #define BMX160_INT_STEP_CONFIG_0_ADDR 0x7A 230 | #define BMX160_INT_STEP_CONFIG_1_ADDR 0x7B 231 | #define BMX160_COMMAND_REG_ADDR 0x7E 232 | #define BMX160_SPI_COMM_TEST_ADDR 0x7F 233 | #define BMX160_INTL_PULLUP_CONF_ADDR 0x85 234 | 235 | /** Error code definitions */ 236 | #define BMX160_OK 0 237 | #define BMX160_E_NULL_PTR -1 238 | #define BMX160_E_COM_FAIL -2 239 | #define BMX160_E_DEV_NOT_FOUND -3 240 | #define BMX160_E_OUT_OF_RANGE -4 241 | #define BMX160_E_INVALID_INPUT -5 242 | #define BMX160_E_ACCEL_ODR_BW_INVALID -6 243 | #define BMX160_E_GYRO_ODR_BW_INVALID -7 244 | #define BMX160_E_LWP_PRE_FLTR_INT_INVALID -8 245 | #define BMX160_E_LWP_PRE_FLTR_INVALID -9 246 | #define BMX160_E_MAGN_NOT_FOUND -10 247 | #define BMX160_FOC_FAILURE -11 248 | #define BMX160_ERR_CHOOSE -12 249 | 250 | /**\name API warning codes */ 251 | #define BMX160_W_GYRO_SELF_TEST_FAIL (1) 252 | #define BMX160_W_ACCEl_SELF_TEST_FAIL (2) 253 | 254 | /** bmx160 unique chip identifier */ 255 | #define BMX160_CHIP_ID 0xD8 256 | 257 | /** Soft reset command */ 258 | #define BMX160_SOFT_RESET_CMD 0xb6 259 | #define BMX160_SOFT_RESET_DELAY_MS 15 260 | /** Start FOC command */ 261 | #define BMX160_START_FOC_CMD 0x03 262 | /** NVM backup enabling command */ 263 | #define BMX160_NVM_BACKUP_EN 0xA0 264 | 265 | /* Delay in ms settings */ 266 | #define BMX160_ACCEL_DELAY_MS 5 267 | #define BMX160_GYRO_DELAY_MS 81 268 | #define BMX160_ONE_MS_DELAY 1 269 | #define BMX160_MAGN_COM_DELAY 10 270 | #define BMX160_GYRO_SELF_TEST_DELAY 20 271 | #define BMX160_ACCEL_SELF_TEST_DELAY 50 272 | 273 | /** Self test configurations */ 274 | #define BMX160_ACCEL_SELF_TEST_CONFIG 0x2C 275 | #define BMX160_ACCEL_SELF_TEST_POSITIVE_EN 0x0D 276 | #define BMX160_ACCEL_SELF_TEST_NEGATIVE_EN 0x09 277 | #define BMX160_ACCEL_SELF_TEST_LIMIT 8192 278 | 279 | /** Power mode settings */ 280 | /* Accel power mode */ 281 | #define BMX160_ACCEL_NORMAL_MODE 0x11 282 | #define BMX160_ACCEL_LOWPOWER_MODE 0x12 283 | #define BMX160_ACCEL_SUSPEND_MODE 0x10 284 | 285 | /* Gyro power mode */ 286 | #define BMX160_GYRO_SUSPEND_MODE 0x14 287 | #define BMX160_GYRO_NORMAL_MODE 0x15 288 | #define BMX160_GYRO_FASTSTARTUP_MODE 0x17 289 | 290 | /* Magn power mode */ 291 | #define BMX160_MAGN_SUSPEND_MODE 0x18 292 | #define BMX160_MAGN_NORMAL_MODE 0x19 293 | #define BMX160_MAGN_LOWPOWER_MODE 0x1A 294 | 295 | /** Range settings */ 296 | /* Accel Range */ 297 | #define BMX160_ACCEL_RANGE_2G 0x03 298 | #define BMX160_ACCEL_RANGE_4G 0x05 299 | #define BMX160_ACCEL_RANGE_8G 0x08 300 | #define BMX160_ACCEL_RANGE_16G 0x0C 301 | 302 | /* Gyro Range */ 303 | #define BMX160_GYRO_RANGE_2000_DPS 0x00 304 | #define BMX160_GYRO_RANGE_1000_DPS 0x01 305 | #define BMX160_GYRO_RANGE_500_DPS 0x02 306 | #define BMX160_GYRO_RANGE_250_DPS 0x03 307 | #define BMX160_GYRO_RANGE_125_DPS 0x04 308 | 309 | 310 | #define BMX160_ACCEL_MG_LSB_2G 0.000061035F ///< Macro for mg per LSB at +/- 2g sensitivity (1 LSB = 0.000061035mg) */ 311 | #define BMX160_ACCEL_MG_LSB_4G 0.000122070F ///< Macro for mg per LSB at +/- 4g sensitivity (1 LSB = 0.000122070mg) */ 312 | #define BMX160_ACCEL_MG_LSB_8G 0.000244141F ///< Macro for mg per LSB at +/- 8g sensitivity (1 LSB = 0.000244141mg) */ 313 | #define BMX160_ACCEL_MG_LSB_16G 0.000488281F ///< Macro for mg per LSB at +/- 16g sensitivity (1 LSB = 0.000488281mg) */ 314 | 315 | #define BMX160_GYRO_SENSITIVITY_125DPS 0.0038110F ///< Gyroscope sensitivity at 125dps */ 316 | #define BMX160_GYRO_SENSITIVITY_250DPS 0.0076220F ///< Gyroscope sensitivity at 250dps */ 317 | #define BMX160_GYRO_SENSITIVITY_500DPS 0.0152439F ///< Gyroscope sensitivity at 500dps */ 318 | #define BMX160_GYRO_SENSITIVITY_1000DPS 0.0304878F ///< Gyroscope sensitivity at 1000dps */ 319 | #define BMX160_GYRO_SENSITIVITY_2000DPS 0.0609756F ///< Gyroscope sensitivity at 2000dps */ 320 | 321 | /** Bandwidth settings */ 322 | /* Accel Bandwidth */ 323 | #define BMX160_ACCEL_BW_OSR4_AVG1 0x00 324 | #define BMX160_ACCEL_BW_OSR2_AVG2 0x01 325 | #define BMX160_ACCEL_BW_NORMAL_AVG4 0x02 326 | #define BMX160_ACCEL_BW_RES_AVG8 0x03 327 | #define BMX160_ACCEL_BW_RES_AVG16 0x04 328 | #define BMX160_ACCEL_BW_RES_AVG32 0x05 329 | #define BMX160_ACCEL_BW_RES_AVG64 0x06 330 | #define BMX160_ACCEL_BW_RES_AVG128 0x07 331 | 332 | #define BMX160_GYRO_BW_OSR4_MODE 0x00 333 | #define BMX160_GYRO_BW_OSR2_MODE 0x01 334 | #define BMX160_GYRO_BW_NORMAL_MODE 0x02 335 | 336 | #define BMX160_MAGN_UT_LSB (0.3F) ///< Macro for micro tesla (uT) per LSB (1 LSB = 0.1uT) */ 337 | /* Output Data Rate settings */ 338 | /* Accel Output data rate */ 339 | #define BMX160_ACCEL_ODR_RESERVED 0x00 340 | #define BMX160_ACCEL_ODR_0_78HZ 0x01 341 | #define BMX160_ACCEL_ODR_1_56HZ 0x02 342 | #define BMX160_ACCEL_ODR_3_12HZ 0x03 343 | #define BMX160_ACCEL_ODR_6_25HZ 0x04 344 | #define BMX160_ACCEL_ODR_12_5HZ 0x05 345 | #define BMX160_ACCEL_ODR_25HZ 0x06 346 | #define BMX160_ACCEL_ODR_50HZ 0x07 347 | #define BMX160_ACCEL_ODR_100HZ 0x08 348 | #define BMX160_ACCEL_ODR_200HZ 0x09 349 | #define BMX160_ACCEL_ODR_400HZ 0x0A 350 | #define BMX160_ACCEL_ODR_800HZ 0x0B 351 | #define BMX160_ACCEL_ODR_1600HZ 0x0C 352 | #define BMX160_ACCEL_ODR_RESERVED0 0x0D 353 | #define BMX160_ACCEL_ODR_RESERVED1 0x0E 354 | #define BMX160_ACCEL_ODR_RESERVED2 0x0F 355 | 356 | /* Gyro Output data rate */ 357 | #define BMX160_GYRO_ODR_RESERVED 0x00 358 | #define BMX160_GYRO_ODR_25HZ 0x06 359 | #define BMX160_GYRO_ODR_50HZ 0x07 360 | #define BMX160_GYRO_ODR_100HZ 0x08 361 | #define BMX160_GYRO_ODR_200HZ 0x09 362 | #define BMX160_GYRO_ODR_400HZ 0x0A 363 | #define BMX160_GYRO_ODR_800HZ 0x0B 364 | #define BMX160_GYRO_ODR_1600HZ 0x0C 365 | #define BMX160_GYRO_ODR_3200HZ 0x0D 366 | 367 | /* Magnetometer sensor Output data rate */ 368 | #define BMX160_MAGN_ODR_RESERVED 0x00 369 | #define BMX160_MAGN_ODR_0_78HZ 0x01 370 | #define BMX160_MAGN_ODR_1_56HZ 0x02 371 | #define BMX160_MAGN_ODR_3_12HZ 0x03 372 | #define BMX160_MAGN_ODR_6_25HZ 0x04 373 | #define BMX160_MAGN_ODR_12_5HZ 0x05 374 | #define BMX160_MAGN_ODR_25HZ 0x06 375 | #define BMX160_MAGN_ODR_50HZ 0x07 376 | #define BMX160_MAGN_ODR_100HZ 0x08 377 | #define BMX160_MAGN_ODR_200HZ 0x09 378 | #define BMX160_MAGN_ODR_400HZ 0x0A 379 | #define BMX160_MAGN_ODR_800HZ 0x0B 380 | 381 | /* Maximum limits definition */ 382 | #define BMX160_MAGN_ODR_MAX 14 383 | #define BMX160_MAGN_BW_MAX 2 384 | #define BMX160_MAGN_RANGE_MAX 8 385 | #define BMX160_GYRO_ODR_MAX 13 386 | #define BMX160_GYRO_BW_MAX 2 387 | #define BMX160_GYRO_RANGE_MAX 4 388 | #define BMX160_ACCEL_ODR_MAX 15 389 | #define BMX160_ACCEL_BW_MAX 2 390 | #define BMX160_ACCEL_RANGE_MAX 12 391 | 392 | 393 | 394 | /** FIFO_CONFIG Definitions */ 395 | #define BMX160_FIFO_TIME_ENABLE 0x02 396 | #define BMX160_FIFO_TAG_INT2_ENABLE 0x04 397 | #define BMX160_FIFO_TAG_INT1_ENABLE 0x08 398 | #define BMX160_FIFO_HEAD_ENABLE 0x10 399 | #define BMX160_FIFO_M_ENABLE 0x20 400 | #define BMX160_FIFO_A_ENABLE 0x40 401 | #define BMX160_FIFO_M_A_ENABLE 0x60 402 | #define BMX160_FIFO_G_ENABLE 0x80 403 | #define BMX160_FIFO_M_G_ENABLE 0xA0 404 | #define BMX160_FIFO_G_A_ENABLE 0xC0 405 | #define BMX160_FIFO_M_G_A_ENABLE 0xE0 406 | 407 | 408 | /* Accel, gyro and magn. sensor length and also their combined 409 | * length definitions in FIFO */ 410 | #define BMX160_FIFO_G_LENGTH 6 411 | #define BMX160_FIFO_A_LENGTH 6 412 | #define BMX160_FIFO_M_LENGTH 8 413 | #define BMX160_FIFO_GA_LENGTH 12 414 | #define BMX160_FIFO_MA_LENGTH 14 415 | #define BMX160_FIFO_MG_LENGTH 14 416 | #define BMX160_FIFO_MGA_LENGTH 20 417 | 418 | 419 | /** FIFO Header Data definitions */ 420 | #define BMX160_FIFO_HEAD_SKIP_FRAME 0x40 421 | #define BMX160_FIFO_HEAD_SENSOR_TIME 0x44 422 | #define BMX160_FIFO_HEAD_INPUT_CONFIG 0x48 423 | #define BMX160_FIFO_HEAD_OVER_READ 0x80 424 | #define BMX160_FIFO_HEAD_A 0x84 425 | #define BMX160_FIFO_HEAD_G 0x88 426 | #define BMX160_FIFO_HEAD_G_A 0x8C 427 | #define BMX160_FIFO_HEAD_M 0x90 428 | #define BMX160_FIFO_HEAD_M_A 0x94 429 | #define BMX160_FIFO_HEAD_M_G 0x98 430 | #define BMX160_FIFO_HEAD_M_G_A 0x9C 431 | 432 | 433 | /** FIFO sensor time length definitions */ 434 | #define BMX160_SENSOR_TIME_LENGTH 3) 435 | 436 | 437 | /** FIFO DOWN selection */ 438 | /* Accel fifo down-sampling values*/ 439 | #define BMX160_ACCEL_FIFO_DOWN_ZERO 0x00 440 | #define BMX160_ACCEL_FIFO_DOWN_ONE 0x10 441 | #define BMX160_ACCEL_FIFO_DOWN_TWO 0x20 442 | #define BMX160_ACCEL_FIFO_DOWN_THREE 0x30 443 | #define BMX160_ACCEL_FIFO_DOWN_FOUR 0x40 444 | #define BMX160_ACCEL_FIFO_DOWN_FIVE 0x50 445 | #define BMX160_ACCEL_FIFO_DOWN_SIX 0x60 446 | #define BMX160_ACCEL_FIFO_DOWN_SEVEN 0x70 447 | 448 | /* Gyro fifo down-smapling values*/ 449 | #define BMX160_GYRO_FIFO_DOWN_ZERO 0x00 450 | #define BMX160_GYRO_FIFO_DOWN_ONE 0x01 451 | #define BMX160_GYRO_FIFO_DOWN_TWO 0x02 452 | #define BMX160_GYRO_FIFO_DOWN_THREE 0x03 453 | #define BMX160_GYRO_FIFO_DOWN_FOUR 0x04 454 | #define BMX160_GYRO_FIFO_DOWN_FIVE 0x05 455 | #define BMX160_GYRO_FIFO_DOWN_SIX 0x06 456 | #define BMX160_GYRO_FIFO_DOWN_SEVEN 0x07 457 | 458 | 459 | #define BMX160_ACCEL_FIFO_FILT_EN 0x80 //< Accel Fifo filter enable*/ 460 | 461 | #define BMX160_GYRO_FIFO_FILT_EN 0x08 //< Gyro Fifo filter enable*/ 462 | 463 | /** Definitions to check validity of FIFO frames */ 464 | #define FIFO_CONFIG_MSB_CHECK 0x80 465 | #define FIFO_CONFIG_LSB_CHECK 0x00 466 | 467 | /*! bmx160 accel FOC configurations */ 468 | #define BMX160_FOC_ACCEL_DISABLED 0x00 469 | #define BMX160_FOC_ACCEL_POSITIVE_G 0x01 470 | #define BMX160_FOC_ACCEL_NEGATIVE_G 0x02 471 | #define BMX160_FOC_ACCEL_0G 0x03 472 | 473 | /** Array Parameter DefinItions */ 474 | #define BMX160_SENSOR_TIME_LSB_BYTE 0 475 | #define BMX160_SENSOR_TIME_XLSB_BYTE 1 476 | #define BMX160_SENSOR_TIME_MSB_BYTE 2 477 | 478 | 479 | /** Interface settings */ 480 | #define BMX160_SPI_INTF 1 481 | #define BMX160_I2C_INTF 0 482 | #define BMX160_SPI_RD_MASK 0x80 483 | #define BMX160_SPI_WR_MASK 0x7F 484 | 485 | /* Sensor & time select definition*/ 486 | #define BMX160_MAG_SEL 0x01 487 | #define BMX160_GYRO_SEL 0x02 488 | #define BMX160_ACCEL_SEL 0x03 489 | #define BMX160_TIME_SEL 0x04 490 | 491 | 492 | #define BMX160_SEN_SEL_MASK 0x07 //< Sensor select mask*/ 493 | #define BMX160_ERR_REG_MASK 0x0F //< Error code mask */ 494 | #define BMX160_I2C_ADDR 0x68 //< bmx160 I2C address */ 495 | #define BMX160_MAGN_BMM150_I2C_ADDR 0x10 //< bmx160 secondary IF address */ 496 | 497 | /** bmx160 Length definitions */ 498 | #define BMX160_ONE 1 499 | #define BMX160_TWO 2 500 | #define BMX160_THREE 3 501 | #define BMX160_FOUR 4 502 | #define BMX160_FIVE 5 503 | 504 | 505 | #define BMX160_FIFO_LEVEL_MARGIN 16 //< bmx160 fifo level Margin */ 506 | #define BMX160_FIFO_FLUSH_VALUE 0xB0 //< bmx160 fifo flush Command */ 507 | 508 | /** bmx160 offset values for xyz axes of accel */ 509 | #define BMX160_ACCEL_MIN_OFFSET -128 510 | #define BMX160_ACCEL_MAX_OFFSET 127 511 | 512 | /** bmx160 offset values for xyz axes of gyro */ 513 | #define BMX160_GYRO_MIN_OFFSET -512 514 | #define BMX160_GYRO_MAX_OFFSET 511 515 | 516 | /** bmx160 fifo full interrupt position and mask */ 517 | #define BMX160_FIFO_FULL_INT_POS 5 518 | #define BMX160_FIFO_FULL_INT_MSK 0x20 519 | #define BMX160_FIFO_WTM_INT_POS 6 520 | #define BMX160_FIFO_WTM_INT_MSK 0x40 521 | 522 | #define BMX160_FIFO_FULL_INT_PIN1_POS 5 523 | #define BMX160_FIFO_FULL_INT_PIN1_MSK 0x20 524 | #define BMX160_FIFO_FULL_INT_PIN2_POS 1 525 | #define BMX160_FIFO_FULL_INT_PIN2_MSK 0x02 526 | 527 | #define BMX160_FIFO_WTM_INT_PIN1_POS 6 528 | #define BMX160_FIFO_WTM_INT_PIN1_MSK 0x40 529 | #define BMX160_FIFO_WTM_INT_PIN2_POS 2 530 | #define BMX160_FIFO_WTM_INT_PIN2_MSK 0x04 531 | 532 | #define BMX160_MANUAL_MODE_EN_POS 7 533 | #define BMX160_MANUAL_MODE_EN_MSK 0x80 534 | #define BMX160_MAGN_READ_BURST_POS 0 535 | #define BMX160_MAGN_READ_BURST_MSK 0x03 536 | 537 | #define BMX160_GYRO_SELF_TEST_POS 4 538 | #define BMX160_GYRO_SELF_TEST_MSK 0x10 539 | #define BMX160_GYRO_SELF_TEST_STATUS_POS 1 540 | #define BMX160_GYRO_SELF_TEST_STATUS_MSK 0x02 541 | 542 | #define BMX160_GYRO_FOC_EN_POS 6 543 | #define BMX160_GYRO_FOC_EN_MSK 0x40 544 | 545 | #define BMX160_ACCEL_FOC_X_CONF_POS 4 546 | #define BMX160_ACCEL_FOC_X_CONF_MSK 0x30 547 | 548 | #define BMX160_ACCEL_FOC_Y_CONF_POS 2 549 | #define BMX160_ACCEL_FOC_Y_CONF_MSK 0x0C 550 | 551 | #define BMX160_ACCEL_FOC_Z_CONF_MSK 0x03 552 | 553 | #define BMX160_FOC_STATUS_POS 3 554 | #define BMX160_FOC_STATUS_MSK 0x08 555 | 556 | #define BMX160_GYRO_OFFSET_X_MSK 0x03 557 | 558 | #define BMX160_GYRO_OFFSET_Y_POS 2 559 | #define BMX160_GYRO_OFFSET_Y_MSK 0x0C 560 | 561 | #define BMX160_GYRO_OFFSET_Z_POS 4 562 | #define BMX160_GYRO_OFFSET_Z_MSK 0x30 563 | 564 | #define BMX160_GYRO_OFFSET_EN_POS 7 565 | #define BMX160_GYRO_OFFSET_EN_MSK 0x80 566 | 567 | #define BMX160_ACCEL_OFFSET_EN_POS 6 568 | #define BMX160_ACCEL_OFFSET_EN_MSK 0x40 569 | 570 | 571 | #define BMX160_GYRO_OFFSET_POS 8 572 | #define BMX160_GYRO_OFFSET_MSK 0x0300 573 | 574 | #define BMX160_NVM_UPDATE_POS 1 575 | #define BMX160_NVM_UPDATE_MSK 0x02 576 | 577 | #define BMX160_NVM_STATUS_POS 4 578 | #define BMX160_NVM_STATUS_MSK 0x10 579 | 580 | /* BIT SLICE GET AND SET FUNCTIONS */ 581 | #define BMX160_GET_BITS(regvar, bitname)\ 582 | ((regvar & bitname##_MSK) >> bitname##_POS) 583 | #define BMX160_SET_BITS(regvar, bitname, val)\ 584 | ((regvar & ~bitname##_MSK) | \ 585 | ((val<> 8) 599 | 600 | /** 601 | * @struct sBmx160FifoFrame_t 602 | * @brief This structure holds the information for usage of FIFO by the user. 603 | */ 604 | typedef struct { 605 | uint8_t *data; /**< Data buffer of user defined length is to be mapped here */ 606 | uint16_t length; /**< While calling the API "BMX160_get_fifo_data" , length stores number of bytes in FIFO to be read (specified by user as input) and after execution of the API ,number of FIFO data bytes available is provided as an output to user */ 607 | uint8_t fifoTimeEnable; /**< FIFO time enable */ 608 | uint8_t fifoHeaderEnable; /**< Enabling of the FIFO header to stream in header mode */ 609 | uint8_t fifoDataEnable; /**< Streaming of the Accelerometer, Gyroscope sensor data or both in FIFO */ 610 | uint16_t accelByteStartIdx;/**< Will be equal to length when no more frames are there to parse */ 611 | uint16_t gyroByteStartIdx; /**< Will be equal to length when no more frames are there to parse */ 612 | uint16_t magnByteStartIdx; /**< Will be equal to length when no more frames are there to parse */ 613 | uint32_t sensorTime; /**< Value of FIFO sensor time time */ 614 | uint8_t skippedFrameCount; /**< Value of Skipped frame counts */ 615 | }sBmx160FifoFrame_t; 616 | 617 | /** 618 | * @enum eBmx160AnySigMotionActiveInterruptState_t 619 | * @brief bmx160 active state of any & sig motion interrupt. 620 | */ 621 | typedef enum { 622 | eBmx160BothAnySigMotionDisabled = -1, /**< Both any & sig motion are disabled */ 623 | eBmx160AnyMotionEnabled, /**< Any-motion selected */ 624 | eBmx160SigMotionEnabled /**< Sig-motion selected */ 625 | }eBmx160AnySigMotionActiveInterruptState_t; 626 | 627 | 628 | /** 629 | * @struct sBmx160Cfg_t 630 | * @brief bmx160 sensor configuration structure 631 | */ 632 | typedef struct { 633 | uint8_t power; /**< power mode */ 634 | uint8_t odr; /**< output data rate */ 635 | uint8_t range; /**< range */ 636 | uint8_t bw; /**< bandwidth */ 637 | }sBmx160Cfg_t; 638 | 639 | 640 | 641 | /* type definitions */ 642 | typedef int8_t (*bmx160ComFptrT)(uint8_t dev_addr, uint8_t reg_addr, uint8_t *data, uint16_t len); 643 | typedef void (*bmx160DelayFptrT)(uint32_t period); 644 | 645 | /** 646 | * @struct sBmx160Dev_t 647 | */ 648 | typedef struct { 649 | uint8_t chipId; /**< Chip Id */ 650 | uint8_t id; /**< Device Id */ 651 | uint8_t interface; /**< 0 - I2C , 1 - SPI Interface */ 652 | eBmx160AnySigMotionActiveInterruptState_t any_sig_sel; /**< Hold active interrupts status for any and sig motion 0 - Any-motion enable, 1 - Sig-motion enable, -1 neither any-motion nor sig-motion selected */ 653 | sBmx160Cfg_t magnCfg; /**< Structure to configure Magnetometer sensor */ 654 | sBmx160Cfg_t prevMagnCfg; /**< Structure to hold previous/old magn config parameters.This is used at driver level to prevent overwriting of same data, hence user does not change it in the code */ 655 | sBmx160Cfg_t accelCfg; /**< Structure to configure Accel sensor */ 656 | sBmx160Cfg_t prevAccelCfg; /**< Structure to hold previous/old accel config parameters.This is used at driver level to prevent overwriting of same data, hence user does not change it in the code */ 657 | sBmx160Cfg_t gyroCfg; /**< Structure to configure Gyro sensor */ 658 | sBmx160Cfg_t prevGyroCfg; /**< Structure to hold previous/old gyro config parameters. This is used at driver level to prevent overwriting of same data, hence user does not change it in the code */ 659 | sBmx160FifoFrame_t *fifo; /**< FIFO related configurations */ 660 | bmx160ComFptrT read; /**< Read function pointer */ 661 | bmx160ComFptrT write; /**< Write function pointer */ 662 | bmx160DelayFptrT delayMs; /**< Delay function pointer */ 663 | }sBmx160Dev_t; 664 | 665 | /** 666 | * @struct sBmx160SensorData_t 667 | * @brief bmx160 sensor data structure which comprises of accel data 668 | */ 669 | typedef struct { 670 | float x; /**< X-axis sensor data */ 671 | float y; /**< Y-axis sensor data */ 672 | float z; /**< Z-axis sensor data */ 673 | uint32_t sensortime; /**< sensor time */ 674 | }sBmx160SensorData_t; 675 | 676 | /** 677 | * @enum eBmx160IntChannel_t 678 | * @brief Interrupt channel 679 | */ 680 | typedef enum { 681 | BMX160_INT_CHANNEL_NONE, /**< Un-map both channels */ 682 | BMX160_INT_CHANNEL_1, /**< interrupt Channel 1 */ 683 | BMX160_INT_CHANNEL_2, /**< interrupt Channel 2 */ 684 | BMX160_INT_CHANNEL_BOTH /**< Map both channels */ 685 | }eBmx160IntChannel_t; 686 | 687 | /** 688 | * @enum eBmx160IntTypes_t 689 | * @brief Select Interrupt 690 | */ 691 | typedef enum { 692 | BMX160_ACC_ANY_MOTION_INT, /**< Slope/Any-motion interrupt */ 693 | BMX160_ACC_SIG_MOTION_INT, /**< Significant motion interrupt */ 694 | BMX160_STEP_DETECT_INT, /**< Step detector interrupt */ 695 | BMX160_ACC_DOUBLE_TAP_INT, /**< double tap interrupt */ 696 | BMX160_ACC_SINGLE_TAP_INT, /**< single tap interrupt */ 697 | BMX160_ACC_ORIENT_INT, /**< orientation interrupt */ 698 | BMX160_ACC_FLAT_INT, /**< flat interrupt */ 699 | BMX160_ACC_HIGH_G_INT, /**< high-g interrupt */ 700 | BMX160_ACC_LOW_G_INT, /**< low-g interrupt */ 701 | BMX160_ACC_SLOW_NO_MOTION_INT, /**< slow/no-motion interrupt */ 702 | BMX160_ACC_GYRO_DATA_RDY_INT, /**< data ready interrupt */ 703 | BMX160_ACC_GYRO_FIFO_FULL_INT, /**< fifo full interrupt */ 704 | BMX160_ACC_GYRO_FIFO_WATERMARK_INT /**< fifo watermark interrupt */ 705 | }eBmx160IntTypes_t; 706 | 707 | /** 708 | * @struct sBmx160IntPinSettg_t 709 | * @brief Structure configuring Interrupt pins 710 | */ 711 | typedef struct { 712 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 713 | uint16_t outputEn :1; /**< To enable either INT1 or INT2 pin as output. 0- output disabled ,1- output enabled */ 714 | uint16_t outputMode :1; /**< 0 - push-pull 1- open drain,only valid if outputEn is set 1 */ 715 | uint16_t outputType :1; /**< 0 - active low , 1 - active high level.if outputEn is 1,this applies to interrupts,else PMU_trigger */ 716 | uint16_t edgeCtrl :1; /**< 0 - level trigger , 1 - edge trigger */ 717 | uint16_t inputEn :1; /**< To enable either INT1 or INT2 pin as input. 0 - input disabled ,1 - input enabled */ 718 | uint16_t latchDur :4; /**< latch duration*/ 719 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 720 | uint16_t latchDur : 4; /**< latch duration*/ 721 | uint16_t inputEn : 1; /**< Latched,non-latched or temporary interrupt modes */ 722 | uint16_t edgeCtrl : 1; /**< 1 - edge trigger, 0 - level trigger */ 723 | uint16_t outputType : 1; /**< 0 - active low , 1 - active high level. if outputEn is 1,this applies to interrupts,else PMU_trigger */ 724 | uint16_t outputMode : 1; /**< 0 - push-pull , 1 - open drain,only valid if outputEn is set 1 */ 725 | uint16_t outputEn : 1; /**< To enable either INT1 or INT2 pin as output. 0 - output disabled , 1 - output enabled */ 726 | #endif 727 | }sBmx160IntPinSettg_t; 728 | 729 | /** 730 | * @struct sBmx160AccTapIntCfg_t 731 | * @brief Tap interrupt structure 732 | */ 733 | typedef struct { 734 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 735 | uint16_t tapThr :5; /**< tap threshold */ 736 | uint16_t tapShock :1; /**< tap shock */ 737 | uint16_t tapQuiet :1; /**< tap quiet */ 738 | uint16_t tapDur :3; /**< tap duration */ 739 | uint16_t tapDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 740 | uint16_t tapEn :1; /**< tap enable, 1 - enable, 0 - disable */ 741 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 742 | uint16_t tapEn :1; /**< tap enable, 1 - enable, 0 - disable */ 743 | uint16_t tapDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 744 | uint16_t tapDur : 3; /**< tap duration */ 745 | uint16_t tapQuiet : 1; /**< tap quiet */ 746 | uint16_t tapShock : 1; /**< tap shock */ 747 | uint16_t tapThr : 5; /**< tap threshold */ 748 | #endif 749 | }sBmx160AccTapIntCfg_t; 750 | 751 | /** 752 | * @struct sBmx160AccAnyMotIntCfg_t 753 | * @brief Slope interrupt structure 754 | */ 755 | typedef struct { 756 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 757 | uint8_t anymotionEn :1; /**< 1 any-motion enable, 0 - any-motion disable */ 758 | uint8_t anymotionX :1; /**< slope interrupt x, 1 - enable, 0 - disable */ 759 | uint8_t anymotionY :1; /**< slope interrupt y, 1 - enable, 0 - disable */ 760 | uint8_t anymotionZ :1; /**< slope interrupt z, 1 - enable, 0 - disable */ 761 | uint8_t anymotionDur :2; /**< slope duration */ 762 | uint8_t anymotionDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 763 | uint8_t anymotionThr; /**< slope threshold */ 764 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 765 | uint8_t anymotionThr; /**< slope threshold */ 766 | uint8_t anymotionDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 767 | uint8_t anymotionDur : 2; /**< slope duration */ 768 | uint8_t anymotionZ : 1; /**< slope interrupt z, 1 - enable, 0 - disable */ 769 | uint8_t anymotionY : 1; /**< slope interrupt y, 1 - enable, 0 - disable */ 770 | uint8_t anymotionX : 1; /**< slope interrupt x, 1 - enable, 0 - disable */ 771 | uint8_t anymotionEn :1; /**< 1 any-motion enable, 0 - any-motion disable */ 772 | #endif 773 | }sBmx160AccAnyMotIntCfg_t; 774 | 775 | /** 776 | * @struct sBmx160AccSigMotIntCfg_t 777 | * @brief Significant motion interrupt structure 778 | */ 779 | typedef struct { 780 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 781 | uint8_t sigMotSkip :2; /**< skip time of sig-motion interrupt */ 782 | uint8_t sigMotProof :2; /**< proof time of sig-motion interrupt */ 783 | uint8_t sigDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 784 | uint8_t sigEn :1; /**< 1 - enable sig, 0 - disable sig & enable anymotion */ 785 | uint8_t sigMotThres; /**< sig-motion threshold */ 786 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 787 | uint8_t sigMotThres; /**< sig-motion threshold */ 788 | uint8_t sigEn :1; /**< 1 - enable sig, 0 - disable sig & enable anymotion */ 789 | uint8_t sigDataSrc :1; /**< data source 0- filter & 1 pre-filter*/ 790 | uint8_t sigMotProof : 2;/**< proof time of sig-motion interrupt */ 791 | uint8_t sigMotSkip : 2; /**< skip time of sig-motion interrupt */ 792 | #endif 793 | }sBmx160AccSigMotIntCfg_t; 794 | 795 | /** 796 | * @struct sBmx160AccStepDetectIntCfg_t 797 | * @brief Step detector interrupt structure 798 | */ 799 | typedef struct { 800 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 801 | uint16_t stepDetectorEn :1; /**< 1- step detector enable, 0- step detector disable */ 802 | uint16_t minThreshold :2; /**< minimum threshold */ 803 | uint16_t steptimeMin :3; /**< minimal detectable step time */ 804 | uint16_t stepDetectorMode :2; /**< enable step counter mode setting */ 805 | uint16_t stepMinBuf :3; /**< minimum step buffer size*/ 806 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 807 | uint16_t stepMinBuf :3; /**< minimum step buffer size*/ 808 | uint16_t stepDetectorMode : 2; /**< enable step counter mode setting */ 809 | uint16_t steptimeMin : 3; /**< minimal detectable step time */ 810 | uint16_t minThreshold : 2; /**< minimum threshold */ 811 | uint16_t stepDetectorEn :1; /**< 1- step detector enable, 0- step detector disable */ 812 | #endif 813 | }sBmx160AccStepDetectIntCfg_t; 814 | 815 | /** 816 | * @struct sBmx160AccNoMotionIntCfg_t 817 | * @brief No motion interrupt structure 818 | */ 819 | typedef struct { 820 | #if __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ 821 | uint16_t noMotionX :1; /**< no motion interrupt x */ 822 | uint16_t noMotionY :1; /**< no motion interrupt y */ 823 | uint16_t noMotionZ :1; /**< no motion interrupt z */ 824 | uint16_t noMotionDur :6; /**< no motion duration */ 825 | uint16_t noMotionSel :1; /**< no motion sel , 1 - enable no-motion ,0- enable slow-motion */ 826 | uint16_t noMotionSrc :1; /**< data source 0- filter & 1 pre-filter*/ 827 | uint8_t noMotionThres; /**< no motion threshold */ 828 | #elif __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__ 829 | uint8_t noMotionThres; /**< no motion threshold */ 830 | uint16_t noMotionSrc :1; /**< data source 0- filter & 1 pre-filter*/ 831 | uint16_t noMotionSel : 1; /**< no motion sel , 1 - enable no-motion ,0- enable slow-motion */ 832 | uint16_t noMotionDur : 6; /**< no motion duration */ 833 | uint16_t noMotionZ :1; /** 6 | The BMX160 contains 16 bit digtial,triaxial accelerometer 16 bit digital, triaxial gyroscope and geomagnetic sensor.
7 | This example is for BMX160 sensor and it oprated via Arduino I2C. 8 | 9 | ![](./resources/images/SEN0373.png) 10 | 11 | ## Product Link(https://www.dfrobot.com/product-2141.html) 12 | 13 | SKU:SEN0373 14 | 15 | ## Table of Contents 16 | 17 | * [Summary](#summary) 18 | * [Installation](#installation) 19 | * [Methods](#methods) 20 | * [Compatibility](#compatibility) 21 | * [History](#history) 22 | * [Credits](#credits) 23 | 24 | ## Summary 25 | 26 | Provide an Arduino library to control the bmx160 to get magnetometer accelerometer, gyroscope and step counter, via I2C communication. 27 | 28 | ## Installation 29 | 30 | There are two ways to use the library: 31 | 1. Open the Arduino IDE, search for "DFRobot_BMX160" in Tools --> Manager Libraries on the status bar, and install the library. 32 | 2. First download the library file, paste it into the \Arduino\libraries directory, then open the examples folder and run the demo in that folder. 33 | 34 | ## Methods 35 | 36 | ```C++ 37 | /** 38 | * @fn begin 39 | * @brief set the i2c addr and init the i2c. 40 | * @return returns the initialization status 41 | * @retval true Initialization succeeded 42 | * @retval false Initialization failed 43 | */ 44 | bool begin(); 45 | 46 | /** 47 | * @fn setGyroRange 48 | * @brief set gyroscope angular rate range and resolution. 49 | * @param bits 50 | * @n eGyroRange_2000DPS Gyroscope sensitivity at 2000dps 51 | * @n eGyroRange_1000DPS Gyroscope sensitivity at 1000dps 52 | * @n eGyroRange_500DPS Gyroscope sensitivity at 500dps 53 | * @n eGyroRange_250DPS Gyroscope sensitivity at 250dps 54 | * @n eGyroRange_125DPS Gyroscope sensitivity at 125dps 55 | */ 56 | void setGyroRange(eGyroRange_t bits); 57 | 58 | /** 59 | * @fn setAccelRange 60 | * @brief allow the selection of the accelerometer g-range. 61 | * @param bits 62 | * @n eAccelRange_2G Macro for mg per LSB at +/- 2g sensitivity (1 LSB = 0.000061035mg) 63 | * @n eAccelRange_4G Macro for mg per LSB at +/- 4g sensitivity (1 LSB = 0.000122070mg) 64 | * @n eAccelRange_8G Macro for mg per LSB at +/- 8g sensitivity (1 LSB = 0.000244141mg) 65 | * @n eAccelRange_16G Macro for mg per LSB at +/- 16g sensitivity (1 LSB = 0.000488281mg) 66 | */ 67 | void setAccelRange(eAccelRange_t bits); 68 | 69 | /** 70 | * @fn getAllData 71 | * @brief get the magn, gyro and accel data 72 | * @param magn to store the magn data 73 | * @param gyro to store the gyro data 74 | * @param accel to store the accel data 75 | */ 76 | void getAllData( sBmx160SensorData_t *magn, sBmx160SensorData_t *gyro, sBmx160SensorData_t *accel); 77 | 78 | /** 79 | * @fn softReset 80 | * @brief reset bmx160 hardware 81 | * @return returns the reset status 82 | * @retval true reset succeeded 83 | * @retval false reset failed 84 | */ 85 | bool softReset(); 86 | 87 | /** 88 | * @fn setLowPower 89 | * @brief disabled the the magn, gyro sensor to reduce power consumption 90 | */ 91 | void setLowPower(); 92 | 93 | /** 94 | * @fn wakeUp 95 | * @brief enabled the the magn, gyro sensor 96 | */ 97 | void wakeUp(); 98 | ``` 99 | 100 | ## Compatibility 101 | 102 | | Board | Work Well | Work Wrong | Untested | Remarks | 103 | | ------------- | :-------: | :--------: | :------: | ------- | 104 | | Arduino uno | √ | | | | 105 | | Mega2560 | √ | | | | 106 | | Leonardo | √ | | | | 107 | | ESP32 | √ | | | | 108 | | micro:bit | √ | | | | 109 | | FireBeetle M0 | √ | | | | 110 | 111 | 112 | ## History 113 | 114 | - 2021/10/20 - Version 1.0.1 released. 115 | - 2019/06/25 - Version 1.0.0 released. 116 | 117 | ## Credits 118 | 119 | Written by Fary(feng.yang@dfrobot.com), 2021. (Welcome to our [website](https://www.dfrobot.com/)) 120 | 121 | 122 | 123 | 124 | 125 | -------------------------------------------------------------------------------- /README_CN.md: -------------------------------------------------------------------------------- 1 | # DFRobot_BMX160 2 | - [English Version](./README.md) 3 | 4 | BMX160是一款高度集成的低功率9轴传感器,可在每个空间方向提供精确的加速度、角速度(陀螺)和地磁测量 5 | BMX160九轴传感器集成三个传感器:16位陀螺仪、16位加速度、地磁传感器 6 | 这个库是针对BMX160传感器,它通过Arduino I2C操作。 7 | 8 | ![](./resources/images/SEN0373.png) 9 | 10 | 11 | ## 产品链接(https://www.dfrobot.com.cn/goods-2947.html) 12 | 13 | SKU:SEN0373 14 | 15 | ## 目录 16 | 17 | * [概述](#概述) 18 | * [库安装](#库安装) 19 | * [方法](#方法) 20 | * [兼容性](#兼容性) 21 | * [历史](#历史) 22 | * [创作者](#创作者) 23 | 24 | ## 概述 25 | 26 | 提供一个Arduino库,通过I2C通信控制bmx160以获取磁强计加速计、陀螺仪和步进计数器。 27 | 28 | ## 库安装 29 | 30 | 这里提供两种使用本库的方法: 31 | 1. 打开Arduino IDE,在状态栏中的Tools--->Manager Libraries 搜索"DFRobot_VEML6075"并安装本库. 32 | 2. 首先下载库文件,将其粘贴到\Arduino\libraries目录中,然后打开examples文件夹并在该文件夹中运行演示. 33 | 34 | 35 | ## 方法 36 | 37 | ```C++ 38 | /** 39 | * @fn begin 40 | * @brief 初始化iic 41 | * @return 返回初始化结果 42 | * @retval true 初始化成功 43 | * @retval false 初始化失败 44 | */ 45 | bool begin(); 46 | 47 | /** 48 | * @fn setGyroRange 49 | * @brief 设置陀螺仪角速率范围和分辨率。 50 | * @param bits 51 | * @n eGyroRange_2000DPS 2000dps的陀螺仪灵敏度 52 | * @n eGyroRange_1000DPS 1000dps的陀螺仪灵敏度 53 | * @n eGyroRange_500DPS 500dps的陀螺仪灵敏度 54 | * @n eGyroRange_250DPS 250dps的陀螺仪灵敏度 55 | * @n eGyroRange_125DPS 125dps的陀螺仪灵敏度 56 | */ 57 | void setGyroRange(eGyroRange_t bits); 58 | 59 | /** 60 | * @fn setAccelRange 61 | * @brief 选择加速计g范围。 62 | * @param bits 63 | * @n eAccelRange_2G (1 LSB = 0.000061035mg) 64 | * @n eAccelRange_4G (1 LSB = 0.000122070mg) 65 | * @n eAccelRange_8G (1 LSB = 0.000244141mg) 66 | * @n eAccelRange_16G (1 LSB = 0.000488281mg) 67 | */ 68 | void setAccelRange(eAccelRange_t bits); 69 | 70 | /** 71 | * @fn getAllData 72 | * @brief 获取陀螺仪、加速计、地磁计数据 73 | * @param magn 存储地磁计数据 74 | * @param gyro 存储陀螺仪数据 75 | * @param accel 存储加速计数据 76 | */ 77 | void getAllData( sBmx160SensorData_t *magn, sBmx160SensorData_t *gyro, sBmx160SensorData_t *accel); 78 | 79 | /** 80 | * @fn softReset 81 | * @brief 重启传感器 82 | * @return 重启结果 83 | * @retval true 设置重启成功 84 | * @retval false 设置重启失败 85 | */ 86 | bool softReset(); 87 | 88 | /** 89 | * @fn setLowPower 90 | * @brief 禁用地磁计、陀螺仪传感器以降低功耗 91 | */ 92 | void setLowPower(); 93 | 94 | /** 95 | * @fn wakeUp 96 | * @brief 使能地磁计、陀螺仪传感器 97 | */ 98 | void wakeUp(); 99 | ``` 100 | 101 | ## 兼容性 102 | 103 | | 主板 | 通过 | 未通过 | 未测试 | 备注 | 104 | | ------------- | :--: | :----: | :----: | ---- | 105 | | Arduino uno | √ | | | | 106 | | Mega2560 | √ | | | | 107 | | Leonardo | √ | | | | 108 | | ESP32 | √ | | | | 109 | | micro:bit | √ | | | | 110 | | FireBeetle M0 | √ | | | | 111 | 112 | 113 | ## 历史 114 | 115 | - 2021/10/20 - 1.0.1 版本 116 | - 2019/06/25 - 1.0.0 版本 117 | 118 | ## 创作者 119 | 120 | Written by yangfeng(feng.yang@dfrobot.com), 2021. (Welcome to our [website](https://www.dfrobot.com/)) 121 | -------------------------------------------------------------------------------- /examples/readAccelData/readAccelData.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file readAccelData.ino 3 | * @brief Through the example, you can get the sensor data by using getAllData: 4 | * @n get accelerometer data of sensor. 5 | * @n With the rotation of the sensor, data changes are visible. 6 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | * @license The MIT License (MIT) 8 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | * @maintainer [Fary](feng.yang@dfrobot.com) 10 | * @version V1.0 11 | * @date 2021-10-20 12 | * @url https://github.com/DFRobot/DFRobot_BMX160 13 | */ 14 | #include 15 | 16 | DFRobot_BMX160 bmx160; 17 | void setup(){ 18 | Serial.begin(115200); 19 | delay(100); 20 | 21 | //init the hardware bmx160 22 | if (bmx160.begin() != true){ 23 | Serial.println("init false"); 24 | while(1); 25 | } 26 | 27 | /** 28 | * enum{eAccelRange_2G, 29 | * eAccelRange_4G, 30 | * eAccelRange_8G, 31 | * eAccelRange_16G 32 | * }eAccelRange_t; 33 | */ 34 | //bmx160.setAccelRange(eAccelRange_4G); 35 | delay(100); 36 | } 37 | 38 | void loop(){ 39 | sBmx160SensorData_t Oaccel; 40 | 41 | /* Get a new sensor event */ 42 | bmx160.getAllData(NULL, NULL, &Oaccel); 43 | 44 | /* Display the accelerometer results (accelerometer data is in m/s^2) */ 45 | Serial.print("Accel "); 46 | Serial.print("X: "); Serial.print(Oaccel.x ); Serial.print(" "); 47 | Serial.print("Y: "); Serial.print(Oaccel.y ); Serial.print(" "); 48 | Serial.print("Z: "); Serial.print(Oaccel.z ); Serial.print(" "); 49 | Serial.println("m/s^2"); 50 | 51 | Serial.println(""); 52 | 53 | delay(500); 54 | } 55 | -------------------------------------------------------------------------------- /examples/readAllData/readAllData.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file readAllData.ino 3 | * @brief Through the example, you can get the sensor data by using getSensorData: 4 | * @n get all data of magnetometer, gyroscope, accelerometer. 5 | * @n With the rotation of the sensor, data changes are visible. 6 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | * @license The MIT License (MIT) 8 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | * @maintainer [Fary](feng.yang@dfrobot.com) 10 | * @version V1.0 11 | * @date 2021-10-20 12 | * @url https://github.com/DFRobot/DFRobot_BMX160 13 | */ 14 | #include 15 | 16 | DFRobot_BMX160 bmx160; 17 | void setup(){ 18 | Serial.begin(115200); 19 | delay(100); 20 | 21 | //init the hardware bmx160 22 | if (bmx160.begin() != true){ 23 | Serial.println("init false"); 24 | while(1); 25 | } 26 | //bmx160.setLowPower(); //disable the gyroscope and accelerometer sensor 27 | //bmx160.wakeUp(); //enable the gyroscope and accelerometer sensor 28 | //bmx160.softReset(); //reset the sensor 29 | 30 | /** 31 | * enum{eGyroRange_2000DPS, 32 | * eGyroRange_1000DPS, 33 | * eGyroRange_500DPS, 34 | * eGyroRange_250DPS, 35 | * eGyroRange_125DPS 36 | * }eGyroRange_t; 37 | **/ 38 | //bmx160.setGyroRange(eGyroRange_500DPS); 39 | 40 | /** 41 | * enum{eAccelRange_2G, 42 | * eAccelRange_4G, 43 | * eAccelRange_8G, 44 | * eAccelRange_16G 45 | * }eAccelRange_t; 46 | */ 47 | //bmx160.setAccelRange(eAccelRange_4G); 48 | delay(100); 49 | } 50 | 51 | void loop(){ 52 | sBmx160SensorData_t Omagn, Ogyro, Oaccel; 53 | 54 | /* Get a new sensor event */ 55 | bmx160.getAllData(&Omagn, &Ogyro, &Oaccel); 56 | 57 | /* Display the magnetometer results (magn is magnetometer in uTesla) */ 58 | Serial.print("M "); 59 | Serial.print("X: "); Serial.print(Omagn.x); Serial.print(" "); 60 | Serial.print("Y: "); Serial.print(Omagn.y); Serial.print(" "); 61 | Serial.print("Z: "); Serial.print(Omagn.z); Serial.print(" "); 62 | Serial.println("uT"); 63 | 64 | /* Display the gyroscope results (gyroscope data is in g) */ 65 | Serial.print("G "); 66 | Serial.print("X: "); Serial.print(Ogyro.x); Serial.print(" "); 67 | Serial.print("Y: "); Serial.print(Ogyro.y); Serial.print(" "); 68 | Serial.print("Z: "); Serial.print(Ogyro.z); Serial.print(" "); 69 | Serial.println("g"); 70 | 71 | /* Display the accelerometer results (accelerometer data is in m/s^2) */ 72 | Serial.print("A "); 73 | Serial.print("X: "); Serial.print(Oaccel.x ); Serial.print(" "); 74 | Serial.print("Y: "); Serial.print(Oaccel.y ); Serial.print(" "); 75 | Serial.print("Z: "); Serial.print(Oaccel.z ); Serial.print(" "); 76 | Serial.println("m/s^2"); 77 | 78 | Serial.println(""); 79 | 80 | delay(500); 81 | } 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | -------------------------------------------------------------------------------- /examples/readGyroData/readGyroData.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file readGyroData.ino 3 | * @brief Through the example, you can get the sensor data by using getAllData: 4 | * @n get gyroscope data of sensor. 5 | * @n With the rotation of the sensor, data changes are visible. 6 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | * @license The MIT License (MIT) 8 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | * @maintainer [Fary](feng.yang@dfrobot.com) 10 | * @version V1.0 11 | * @date 2021-10-20 12 | * @url https://github.com/DFRobot/DFRobot_BMX160 13 | */ 14 | #include 15 | 16 | DFRobot_BMX160 bmx160; 17 | void setup(){ 18 | Serial.begin(115200); 19 | delay(100); 20 | 21 | //init the hardware bmx160 22 | if (bmx160.begin() != true){ 23 | Serial.println("init false"); 24 | while(1); 25 | } 26 | 27 | /** 28 | * enum{eGyroRange_2000DPS, 29 | * eGyroRange_1000DPS, 30 | * eGyroRange_500DPS, 31 | * eGyroRange_250DPS, 32 | * eGyroRange_125DPS 33 | * }eGyroRange_t; 34 | */ 35 | //bmx160.setGyroRange(eGyroRange_500DPS); 36 | 37 | delay(100); 38 | } 39 | 40 | void loop(){ 41 | sBmx160SensorData_t Ogyro; 42 | 43 | /* Get a new sensor event */ 44 | bmx160.getAllData(NULL, &Ogyro, NULL); 45 | 46 | 47 | /* Display the gyroscope results (gyroscope data is in g) */ 48 | Serial.print("G "); 49 | Serial.print("X: "); Serial.print(Ogyro.x); Serial.print(" "); 50 | Serial.print("Y: "); Serial.print(Ogyro.y); Serial.print(" "); 51 | Serial.print("Z: "); Serial.print(Ogyro.z); Serial.print(" "); 52 | Serial.println("g"); 53 | 54 | Serial.println(""); 55 | 56 | delay(500); 57 | } 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | -------------------------------------------------------------------------------- /examples/readMagnData/readMagnData.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file readMagnData.ino 3 | * @brief Through the example, you can get the sensor data by using getSensorData: 4 | * @n get magnetometer data of sensor. 5 | * @n With the rotation of the sensor, data changes are visible. 6 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | * @license The MIT License (MIT) 8 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | * @maintainer [Fary](feng.yang@dfrobot.com) 10 | * @version V1.0 11 | * @date 2021-10-20 12 | * @url https://github.com/DFRobot/DFRobot_BMX160 13 | */ 14 | #include 15 | 16 | DFRobot_BMX160 bmx160; 17 | void setup(){ 18 | Serial.begin(115200); 19 | delay(100); 20 | 21 | //init the hardware bmx160 22 | if (bmx160.begin() != true){ 23 | Serial.println("init false"); 24 | while(1); 25 | } 26 | delay(100); 27 | } 28 | 29 | void loop(){ 30 | sBmx160SensorData_t Omagn; 31 | 32 | /* Get a new sensor event */ 33 | bmx160.getAllData(&Omagn, NULL, NULL); 34 | 35 | /* Display the magnetometer results (magn is magnetometer in uTesla) */ 36 | Serial.print("Magn "); 37 | Serial.print("X: "); Serial.print(Omagn.x); Serial.print(" "); 38 | Serial.print("Y: "); Serial.print(Omagn.y); Serial.print(" "); 39 | Serial.print("Z: "); Serial.print(Omagn.z); Serial.print(" "); 40 | Serial.println("uT"); 41 | 42 | Serial.println(""); 43 | 44 | delay(500); 45 | } 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /examples/setLowPower/setLowPower.ino: -------------------------------------------------------------------------------- 1 | /*! 2 | * @file setLowPower.ino 3 | * @brief Through the example disable or enable the gyroscope and accelerometer sensor. 4 | * @n With the rotation of the sensor, data changes are visible. 5 | * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 6 | * @license The MIT License (MIT) 7 | * @author [luoyufeng] (yufeng.luo@dfrobot.com) 8 | * @maintainer [Fary](feng.yang@dfrobot.com) 9 | * @version V1.0 10 | * @date 2021-10-20 11 | * @url https://github.com/DFRobot/DFRobot_BMX160 12 | */ 13 | #include 14 | 15 | DFRobot_BMX160 bmx160; 16 | void setup(){ 17 | Serial.begin(115200); 18 | delay(100); 19 | 20 | //init the hardware bmx160 21 | if (bmx160.begin() != true){ 22 | Serial.println("init false"); 23 | while(1); 24 | } 25 | bmx160.setLowPower(); //disable the gyroscope and accelerometer sensor 26 | //bmx160.wakeUp(); //enable the gyroscope and accelerometer sensor 27 | //bmx160.softReset(); //reset the sensor 28 | 29 | delay(100); 30 | } 31 | 32 | void loop(){ 33 | 34 | 35 | delay(500); 36 | } 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /keywords.txt: -------------------------------------------------------------------------------- 1 | ####################################### 2 | # Syntax Coloring DFRobot_BMX160 3 | ####################################### 4 | 5 | ####################################### 6 | # Datatypes (KEYWORD1) 7 | ####################################### 8 | 9 | DFRobot_BMX160 KEYWORD1 10 | 11 | ####################################### 12 | # Methods and Functions (KEYWORD2) 13 | ####################################### 14 | 15 | begin KEYWORD2 16 | setGyroRange KEYWORD2 17 | setAccelRange KEYWORD2 18 | getAllData KEYWORD2 19 | softReset KEYWORD2 20 | setLowPower KEYWORD2 21 | wakeUp KEYWORD2 22 | 23 | ####################################### 24 | # Constants (LITERAL1) 25 | ####################################### 26 | 27 | eGyroRange_2000DPS LITERAL1 28 | eGyroRange_1000DPS LITERAL1 29 | eGyroRange_500DPS LITERAL1 30 | eGyroRange_250DPS LITERAL1 31 | eGyroRange_125DPS LITERAL1 32 | eAccelRange_2G LITERAL1 33 | eAccelRange_4G LITERAL1 34 | eAccelRange_8G LITERAL1 35 | eAccelRange_16G LITERAL1 -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=DFRobot_BMX160 2 | version=1.0.1 3 | author=DFRobot 4 | maintainer=Fary DFRobot 5 | sentence=DFRobot_BMX160 is the Sensor library of DFRobot 6 | paragraph=The BMX160 contains 16 bit digtial,triaxial accelerometer 16 bit digital, triaxial gyroscope and geomagnetic sensor. 7 | category=Sensors 8 | url=https://github.com/DFRobot/DFRobot_BMX160 9 | architectures=* 10 | -------------------------------------------------------------------------------- /python/raspberrypi/DFRobot_BMX160.py: -------------------------------------------------------------------------------- 1 | '''! 2 | @file DFRobot_BMX160.py 3 | @brief define DFRobot_BMX160 class infrastructure, the implementation of basic methods 4 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 5 | @license The MIT License (MIT) 6 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 7 | @maintainer [Fary](feng.yang@dfrobot.com) 8 | @version V1.0 9 | @date 2021-10-20 10 | @url https://github.com/DFRobot/DFRobot_BMX160 11 | ''' 12 | import sys 13 | sys.path.append('../') 14 | import smbus 15 | import time 16 | 17 | class BMX160: 18 | 19 | _BMX160_CHIP_ID_ADDR = (0x00) 20 | _BMX160_ERROR_REG_ADDR = (0x02) 21 | _BMX160_MAG_DATA_ADDR = (0x04) 22 | _BMX160_GYRO_DATA_ADDR = (0x0C) 23 | _BMX160_ACCEL_DATA_ADDR = (0x12) 24 | _BMX160_STATUS_ADDR = (0x1B) 25 | _BMX160_INT_STATUS_ADDR = (0x1C) 26 | _BMX160_FIFO_LENGTH_ADDR = (0x22) 27 | _BMX160_FIFO_DATA_ADDR = (0x24) 28 | _BMX160_ACCEL_CONFIG_ADDR = (0x40) 29 | _BMX160_ACCEL_RANGE_ADDR = (0x41) 30 | _BMX160_GYRO_CONFIG_ADDR = (0x42) 31 | _BMX160_GYRO_RANGE_ADDR = (0x43) 32 | _BMX160_MAGN_CONFIG_ADDR = (0x44) 33 | _BMX160_FIFO_DOWN_ADDR = (0x45) 34 | _BMX160_FIFO_CONFIG_0_ADDR = (0x46) 35 | _BMX160_FIFO_CONFIG_1_ADDR = (0x47) 36 | _BMX160_MAGN_RANGE_ADDR = (0x4B) 37 | _BMX160_MAGN_IF_0_ADDR = (0x4C) 38 | _BMX160_MAGN_IF_1_ADDR = (0x4D) 39 | _BMX160_MAGN_IF_2_ADDR = (0x4E) 40 | _BMX160_MAGN_IF_3_ADDR = (0x4F) 41 | _BMX160_INT_ENABLE_0_ADDR = (0x50) 42 | _BMX160_INT_ENABLE_1_ADDR = (0x51) 43 | _BMX160_INT_ENABLE_2_ADDR = (0x52) 44 | _BMX160_INT_OUT_CTRL_ADDR = (0x53) 45 | _BMX160_INT_LATCH_ADDR = (0x54) 46 | _BMX160_INT_MAP_0_ADDR = (0x55) 47 | _BMX160_INT_MAP_1_ADDR = (0x56) 48 | _BMX160_INT_MAP_2_ADDR = (0x57) 49 | _BMX160_INT_DATA_0_ADDR = (0x58) 50 | _BMX160_INT_DATA_1_ADDR = (0x59) 51 | _BMX160_INT_LOWHIGH_0_ADDR = (0x5A) 52 | _BMX160_INT_LOWHIGH_1_ADDR = (0x5B) 53 | _BMX160_INT_LOWHIGH_2_ADDR = (0x5C) 54 | _BMX160_INT_LOWHIGH_3_ADDR = (0x5D) 55 | _BMX160_INT_LOWHIGH_4_ADDR = (0x5E) 56 | _BMX160_INT_MOTION_0_ADDR = (0x5F) 57 | _BMX160_INT_MOTION_1_ADDR = (0x60) 58 | _BMX160_INT_MOTION_2_ADDR = (0x61) 59 | _BMX160_INT_MOTION_3_ADDR = (0x62) 60 | _BMX160_INT_TAP_0_ADDR = (0x63) 61 | _BMX160_INT_TAP_1_ADDR = (0x64) 62 | _BMX160_INT_ORIENT_0_ADDR = (0x65) 63 | _BMX160_INT_ORIENT_1_ADDR = (0x66) 64 | _BMX160_INT_FLAT_0_ADDR = (0x67) 65 | _BMX160_INT_FLAT_1_ADDR = (0x68) 66 | _BMX160_FOC_CONF_ADDR = (0x69) 67 | _BMX160_CONF_ADDR = (0x6A) 68 | _BMX160_IF_CONF_ADDR = (0x6B) 69 | _BMX160_SELF_TEST_ADDR = (0x6D) 70 | _BMX160_OFFSET_ADDR = (0x71) 71 | _BMX160_OFFSET_CONF_ADDR = (0x77) 72 | _BMX160_INT_STEP_CNT_0_ADDR = (0x78) 73 | _BMX160_INT_STEP_CONFIG_0_ADDR = (0x7A) 74 | _BMX160_INT_STEP_CONFIG_1_ADDR = (0x7B) 75 | _BMX160_COMMAND_REG_ADDR = (0x7E) 76 | 77 | BMX160_SOFT_RESET_CMD = (0xb6) 78 | BMX160_MAGN_UT_LSB = (0.3) 79 | _BMX160_ACCEL_MG_LSB_2G = (0.000061035) 80 | _BMX160_ACCEL_MG_LSB_4G = (0.000122070) 81 | _BMX160_ACCEL_MG_LSB_8G = (0.000244141) 82 | _BMX160_ACCEL_MG_LSB_16G = (0.000488281) 83 | 84 | _BMX160_GYRO_SENSITIVITY_125DPS = (0.0038110) 85 | _BMX160_GYRO_SENSITIVITY_250DPS = (0.0076220) 86 | _BMX160_GYRO_SENSITIVITY_500DPS = (0.0152439) 87 | _BMX160_GYRO_SENSITIVITY_1000DPS = (0.0304878) 88 | _BMX160_GYRO_SENSITIVITY_2000DPS = (0.0609756) 89 | 90 | GyroRange_125DPS = (0x00) 91 | GyroRange_250DPS = (0x01) 92 | GyroRange_500DPS = (0x02) 93 | GyroRange_1000DPS = (0x03) 94 | GyroRange_2000DPS = (0x04) 95 | 96 | AccelRange_2G = (0x00) 97 | AccelRange_4G = (0x01) 98 | AccelRange_8G = (0x02) 99 | AccelRange_16G = (0x03) 100 | 101 | accelRange = _BMX160_ACCEL_MG_LSB_2G 102 | gyroRange = _BMX160_GYRO_SENSITIVITY_250DPS 103 | 104 | def __init__(self, bus): 105 | self.i2cbus = smbus.SMBus(bus) 106 | self.i2c_addr = 0x68 107 | time.sleep(0.16) 108 | 109 | def begin(self): 110 | '''! 111 | @brief initialization the i2c. 112 | @return returns the initialization status 113 | @retval True Initialization succeeded 114 | @retval False Initialization failed 115 | ''' 116 | if not self.scan(): 117 | return False 118 | else: 119 | self.soft_reset() 120 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x11) 121 | time.sleep(0.05) 122 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x15) 123 | time.sleep(0.1) 124 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x19) 125 | time.sleep(0.01) 126 | self.set_magn_conf() 127 | return True 128 | 129 | def set_low_power(self): 130 | '''! 131 | @brief disabled the the magn, gyro sensor to reduce power consumption 132 | ''' 133 | self.soft_reset() 134 | time.sleep(0.1) 135 | self.set_magn_conf() 136 | time.sleep(0.1) 137 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x12) 138 | time.sleep(0.1) 139 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x17) 140 | time.sleep(0.1) 141 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x1B) 142 | time.sleep(0.1) 143 | 144 | def wake_up(self): 145 | '''! 146 | @brief enabled the the magn, gyro sensor 147 | ''' 148 | self.soft_reset() 149 | time.sleep(0.1) 150 | self.set_magn_conf() 151 | time.sleep(0.1) 152 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x11) 153 | time.sleep(0.1) 154 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x15) 155 | time.sleep(0.1) 156 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, 0x19) 157 | time.sleep(0.1) 158 | 159 | def soft_reset(self): 160 | '''! 161 | @brief reset bmx160 hardware 162 | @return returns the reset status 163 | @retval True reset succeeded 164 | @retval False reset failed 165 | ''' 166 | data = self.BMX160_SOFT_RESET_CMD 167 | self.write_bmx_reg(self._BMX160_COMMAND_REG_ADDR, data) 168 | time.sleep(0.015) 169 | #self.defaultParamSettg() 170 | return True 171 | 172 | def set_magn_conf(self): 173 | '''! 174 | @brief set magnetometer Config 175 | ''' 176 | self.write_bmx_reg(self._BMX160_MAGN_IF_0_ADDR, 0x80) 177 | time.sleep(0.05) 178 | self.write_bmx_reg(self._BMX160_MAGN_IF_3_ADDR, 0x01) 179 | self.write_bmx_reg(self._BMX160_MAGN_IF_2_ADDR, 0x4B) 180 | self.write_bmx_reg(self._BMX160_MAGN_IF_3_ADDR, 0x04) 181 | self.write_bmx_reg(self._BMX160_MAGN_IF_2_ADDR, 0x51) 182 | self.write_bmx_reg(self._BMX160_MAGN_IF_3_ADDR, 0x0E) 183 | self.write_bmx_reg(self._BMX160_MAGN_IF_2_ADDR, 0x52) 184 | 185 | self.write_bmx_reg(self._BMX160_MAGN_IF_3_ADDR, 0x02) 186 | self.write_bmx_reg(self._BMX160_MAGN_IF_2_ADDR, 0x4C) 187 | self.write_bmx_reg(self._BMX160_MAGN_IF_1_ADDR, 0x42) 188 | self.write_bmx_reg(self._BMX160_MAGN_CONFIG_ADDR, 0x08) 189 | self.write_bmx_reg(self._BMX160_MAGN_IF_0_ADDR, 0x03) 190 | time.sleep(0.05) 191 | 192 | def set_gyro_range(self, bits): 193 | '''! 194 | @brief set gyroscope angular rate range and resolution. 195 | @param bits 196 | @n GyroRange_125DPS Gyroscope sensitivity at 125dps 197 | @n GyroRange_250DPS Gyroscope sensitivity at 250dps 198 | @n GyroRange_500DPS Gyroscope sensitivity at 500dps 199 | @n GyroRange_1000DPS Gyroscope sensitivity at 1000dps 200 | @n GyroRange_2000DPS Gyroscope sensitivity at 2000dps 201 | ''' 202 | if bits == 0: 203 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_125DPS 204 | elif bits == 1: 205 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_250DPS 206 | elif bits == 2: 207 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_500DPS 208 | elif bits == 3: 209 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_1000DPS 210 | elif bits == 4: 211 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_2000DPS 212 | else: 213 | self.gyroRange = self._BMX160_GYRO_SENSITIVITY_250DPS 214 | 215 | def set_accel_range(self, bits): 216 | '''! 217 | @brief allow the selection of the accelerometer g-range. 218 | @param bits 219 | @n AccelRange_2G Macro for mg per LSB at +/- 2g sensitivity (1 LSB = 0.000061035mg) 220 | @n AccelRange_4G Macro for mg per LSB at +/- 4g sensitivity (1 LSB = 0.000122070mg) 221 | @n AccelRange_8G Macro for mg per LSB at +/- 8g sensitivity (1 LSB = 0.000244141mg) 222 | @n AccelRange_16G Macro for mg per LSB at +/- 16g sensitivity (1 LSB = 0.000488281mg) 223 | ''' 224 | if bits == 0: 225 | self.accelRange = self._BMX160_ACCEL_MG_LSB_2G 226 | elif bits == 1: 227 | self.accelRange = self._BMX160_ACCEL_MG_LSB_4G 228 | elif bits == 2: 229 | self.accelRange = self._BMX160_ACCEL_MG_LSB_8G 230 | elif bits == 3: 231 | self.accelRange = self._BMX160_ACCEL_MG_LSB_16G 232 | else: 233 | self.accelRange = self._BMX160_ACCEL_MG_LSB_2G 234 | 235 | def get_all_data(self): 236 | '''! 237 | @brief get the magn, gyro and accel data 238 | @return all data 239 | ''' 240 | data = self.read_bmx_reg(self._BMX160_MAG_DATA_ADDR) 241 | if (data[1] & 0x80): 242 | magnx = - 0x10000 + ((data[1] << 8) | (data[0])) 243 | else: 244 | magnx = (data[1] << 8) | (data[0]) 245 | if (data[3] & 0x80): 246 | magny = - 0x10000 + ((data[3] << 8) | (data[2])) 247 | else: 248 | magny = (data[3] << 8) | (data[2]) 249 | if (data[5] & 0x80): 250 | magnz = - 0x10000 + ((data[5] << 8) | (data[4])) 251 | else: 252 | magnz = (data[5] << 8) | (data[4]) 253 | 254 | if (data[9] & 0x80): 255 | gyrox = - 0x10000 + ((data[9] << 8) | (data[8])) 256 | else: 257 | gyrox = (data[9] << 8) | (data[8]) 258 | if (data[11] & 0x80): 259 | gyroy = - 0x10000 + ((data[11] << 8) | (data[10])) 260 | else: 261 | gyroy = (data[11] << 8) | (data[10]) 262 | if (data[13] & 0x80): 263 | gyroz = - 0x10000 + ((data[13] << 8) | (data[12])) 264 | else: 265 | gyroz = (data[13] << 8) | (data[12]) 266 | 267 | if (data[15] & 0x80): 268 | accelx = - 0x10000 + ((data[15] << 8) | (data[14])) 269 | else: 270 | accelx = (data[15] << 8) | (data[14]) 271 | if (data[17] & 0x80): 272 | accely = - 0x10000 + ((data[17] << 8) | (data[16])) 273 | else: 274 | accely = (data[17] << 8) | (data[16]) 275 | if (data[19] & 0x80): 276 | accelz = - 0x10000 + ((data[19] << 8) | (data[18])) 277 | else: 278 | accelz = (data[19] << 8) | (data[18]) 279 | 280 | magnx *= self.BMX160_MAGN_UT_LSB 281 | magny *= self.BMX160_MAGN_UT_LSB 282 | magnz *= self.BMX160_MAGN_UT_LSB 283 | 284 | gyrox *= self.gyroRange 285 | gyroy *= self.gyroRange 286 | gyroz *= self.gyroRange 287 | 288 | accelx *= self.accelRange * 9.8 289 | accely *= self.accelRange * 9.8 290 | accelz *= self.accelRange * 9.8 291 | out_put = [] 292 | out_put.append(magnx) 293 | out_put.append(magny) 294 | out_put.append(magnz) 295 | out_put.append(gyrox) 296 | out_put.append(gyroy) 297 | out_put.append(gyroz) 298 | out_put.append(accelx) 299 | out_put.append(accely) 300 | out_put.append(accelz) 301 | return out_put 302 | 303 | def write_bmx_reg(self, register, value): 304 | '''! 305 | @brief Write data to the BMX register 306 | @param register register 307 | @param value Data written to the BMX register 308 | @return return the actually written length 309 | ''' 310 | self.i2cbus.write_byte_data(self.i2c_addr, register, value) 311 | 312 | def read_bmx_reg(self, register): 313 | '''! 314 | @brief Read BMX register data 315 | @param register register 316 | @return data 317 | ''' 318 | return self.i2cbus.read_i2c_block_data(self.i2c_addr, register) 319 | 320 | def scan(self): 321 | '''! 322 | @brief iic scan function 323 | @return scan result 324 | @retval True sensor exist 325 | @retval False There is no sensor 326 | ''' 327 | try: 328 | self.i2cbus.read_byte(self.i2c_addr) 329 | return True 330 | except: 331 | print("I2C init fail") 332 | return False 333 | -------------------------------------------------------------------------------- /python/raspberrypi/README.md: -------------------------------------------------------------------------------- 1 | # DFRobot_BMX160 2 | 3 | - [中文版](./README_CN.md) 4 | 5 | The BMX160 is a highly integrated, low power 9-axis sensor that provides precise acceleration and angular rate (gyroscopic) and geomagnetic measurement in each spatial direction.
6 | The BMX160 contains 16 bit digtial,triaxial accelerometer 16 bit digital, triaxial gyroscope and geomagnetic sensor.
7 | This example is for BMX160 sensor and it oprated via Arduino I2C. 8 | 9 | ![](../../resources/images/SEN0373.png) 10 | 11 | ## Product Link(https://www.dfrobot.com/product-2141.html) 12 | 13 | SKU:SEN0373 14 | 15 | ## Table of Contents 16 | 17 | * [Summary](#summary) 18 | * [Installation](#installation) 19 | * [Methods](#methods) 20 | * [Compatibility](#compatibility) 21 | * [History](#history) 22 | * [Credits](#credits) 23 | 24 | 25 | ## Summary 26 | Provide an raspberrypi library to control the bmx160 to get magnetometer, accelerometer, gyroscope and step counter, via I2C communication. 27 | 28 | 29 | ## Installation 30 | 31 | This Sensor should work with BMX160 on RaspberryPi.
32 | Run the program: 33 | ``` 34 | $> python read_all_data.py 35 | 36 | ``` 37 | 38 | ## Methods 39 | 40 | ```Python 41 | 42 | def begin(self): 43 | '''! 44 | @brief initialization the i2c. 45 | @return returns the initialization status 46 | @retval True Initialization succeeded 47 | @retval False Initialization failed 48 | ''' 49 | 50 | def set_low_power(self): 51 | '''! 52 | @brief disabled the the magn, gyro sensor to reduce power consumption 53 | ''' 54 | 55 | def wake_up(self): 56 | '''! 57 | @brief enabled the the magn, gyro sensor 58 | ''' 59 | 60 | def soft_reset(self): 61 | '''! 62 | @brief reset bmx160 hardware 63 | @return returns the reset status 64 | @retval True reset succeeded 65 | @retval False reset failed 66 | ''' 67 | 68 | def set_gyro_range(self, bits): 69 | '''! 70 | @brief set gyroscope angular rate range and resolution. 71 | @param bits 72 | @n GyroRange_125DPS Gyroscope sensitivity at 125dps 73 | @n GyroRange_250DPS Gyroscope sensitivity at 250dps 74 | @n GyroRange_500DPS Gyroscope sensitivity at 500dps 75 | @n GyroRange_1000DPS Gyroscope sensitivity at 1000dps 76 | @n GyroRange_2000DPS Gyroscope sensitivity at 2000dps 77 | ''' 78 | 79 | def set_accel_range(self, bits): 80 | '''! 81 | @brief allow the selection of the accelerometer g-range. 82 | @param bits 83 | @n AccelRange_2G Macro for mg per LSB at +/- 2g sensitivity (1 LSB = 0.000061035mg) 84 | @n AccelRange_4G Macro for mg per LSB at +/- 4g sensitivity (1 LSB = 0.000122070mg) 85 | @n AccelRange_8G Macro for mg per LSB at +/- 8g sensitivity (1 LSB = 0.000244141mg) 86 | @n AccelRange_16G Macro for mg per LSB at +/- 16g sensitivity (1 LSB = 0.000488281mg) 87 | ''' 88 | 89 | def get_all_data(self): 90 | '''! 91 | @brief get the magn, gyro and accel data 92 | @return all data 93 | ''' 94 | 95 | ``` 96 | ## Compatibility 97 | 98 | * RaspberryPi Version 99 | 100 | | Board | Work Well | Work Wrong | Untested | Remarks | 101 | | ------------ | :-------: | :--------: | :------: | ------- | 102 | | RaspberryPi2 | | | √ | | 103 | | RaspberryPi3 | √ | | | | 104 | | RaspberryPi4 | | | √ | | 105 | 106 | * Python Version 107 | 108 | | Python | Work Well | Work Wrong | Untested | Remarks | 109 | | ------- | :-------: | :--------: | :------: | ------- | 110 | | Python2 | √ | | | | 111 | | Python3 | √ | | | | 112 | 113 | ## History 114 | 115 | - 2021/10/20 - Version 1.0.1 released. 116 | - 2019/06/25 - Version 1.0.0 released. 117 | 118 | ## Credits 119 | 120 | 121 | Written by Fary(feng.yang@dfrobot.com), 2021. (Welcome to our [website](https://www.dfrobot.com/)) 122 | -------------------------------------------------------------------------------- /python/raspberrypi/README_CN.md: -------------------------------------------------------------------------------- 1 | # DFRobot_BMX160 2 | - [English Version](./README.md) 3 | 4 | BMX160是一款高度集成的低功率9轴传感器,可在每个空间方向提供精确的加速度、角速度(陀螺)和地磁测量 5 | BMX160九轴传感器集成三个传感器:16位陀螺仪、16位加速度、地磁传感器 6 | 这个库是针对BMX160传感器,它通过Arduino I2C操作。 7 | 8 | 9 | ![](../../resources/images/SEN0373.png) 10 | 11 | 12 | ## 产品链接(https://www.dfrobot.com.cn/goods-2947.html) 13 | 14 | SKU:SEN0373 15 | 16 | ## 目录 17 | 18 | * [概述](#概述) 19 | * [库安装](#库安装) 20 | * [方法](#方法) 21 | * [兼容性](#兼容性) 22 | * [历史](#历史) 23 | * [创作者](#创作者) 24 | 25 | ## 概述 26 | 27 | 提供一个树莓派python库,通过I2C通信控制bmx160以获取磁强计加速计、陀螺仪和步进计数器。 28 | 29 | ## 库安装 30 | 31 | 使用此库前,请首先下载库文件,将其粘贴到树莓派的自定义目录中,然后打开examples文件夹并在该文件夹中运行演示。 32 | 33 | ## 方法 34 | 35 | ```python 36 | 37 | def begin(self): 38 | '''! 39 | @brief 初始化iic 40 | @return 返回初始化结果 41 | @retval True 初始化成功 42 | @retval False 初始化失败 43 | ''' 44 | 45 | def set_low_power(self): 46 | '''! 47 | @brief 禁用地磁计、陀螺仪传感器以降低功耗 48 | ''' 49 | 50 | def wake_up(self): 51 | '''! 52 | @brief 使能地磁计、陀螺仪传感器 53 | ''' 54 | 55 | def soft_reset(self): 56 | '''! 57 | @brief 重启传感器 58 | @return 重启结果 59 | @retval True 设置重启成功 60 | @retval False 设置重启失败 61 | ''' 62 | 63 | def set_gyro_range(self, bits): 64 | '''! 65 | @brief 设置陀螺仪角速率范围和分辨率。 66 | @param bits 67 | @n GyroRange_125DPS 125dps的陀螺仪灵敏度 68 | @n GyroRange_250DPS 250dps的陀螺仪灵敏度 69 | @n GyroRange_500DPS 500dps的陀螺仪灵敏度 70 | @n GyroRange_1000DPS 1000dps的陀螺仪灵敏度 71 | @n GyroRange_2000DPS 2000dps的陀螺仪灵敏度 72 | ''' 73 | 74 | def set_accel_range(self, bits): 75 | '''! 76 | @brief 选择加速计g范围。 77 | @param bits 78 | @n AccelRange_2G (1 LSB = 0.000061035mg) 79 | @n AccelRange_4G (1 LSB = 0.000122070mg) 80 | @n AccelRange_8G (1 LSB = 0.000244141mg) 81 | @n AccelRange_16G (1 LSB = 0.000488281mg) 82 | ''' 83 | 84 | def get_all_data(self): 85 | '''! 86 | @brief 获取陀螺仪、加速计、地磁计数据 87 | @return 数据 88 | ''' 89 | ``` 90 | 91 | ## 兼容性 92 | 93 | * RaspberryPi Version 94 | 95 | | Board | Work Well | Work Wrong | Untested | Remarks | 96 | | ------------ | :-------: | :--------: | :------: | ------- | 97 | | RaspberryPi2 | | | √ | | 98 | | RaspberryPi3 | √ | | | | 99 | | RaspberryPi4 | | | √ | | 100 | 101 | * Python 版本 102 | 103 | | Python | Work Well | Work Wrong | Untested | Remarks | 104 | | ------- | :-------: | :--------: | :------: | ------- | 105 | | Python2 | √ | | | | 106 | | Python3 | √ | | | | 107 | 108 | 109 | ## 历史 110 | 111 | - 2021/10/20 - Version 1.0.1 released. 112 | - 2019/06/25 - Version 1.0.0 released. 113 | 114 | 115 | ## 创作者 116 | 117 | Written by yangfeng(feng.yang@dfrobot.com), 2021. (Welcome to our [website](https://www.dfrobot.com/)) 118 | 119 | -------------------------------------------------------------------------------- /python/raspberrypi/examples/read_accel_data/read_accel_data.py: -------------------------------------------------------------------------------- 1 | '''! 2 | @file read_accel_data.py 3 | @brief Through the example, you can get the sensor data by using getAllData: 4 | @n get accelerometer data of sensor. 5 | @n With the rotation of the sensor, data changes are visible. 6 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | @license The MIT License (MIT) 8 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | @maintainer [Fary](feng.yang@dfrobot.com) 10 | @version V1.0 11 | @date 2021-10-20 12 | @url https://github.com/DFRobot/DFRobot_BMX160 13 | ''' 14 | import sys 15 | sys.path.append('../../') 16 | import time 17 | from DFRobot_BMX160 import BMX160 18 | 19 | bmx = BMX160(1) 20 | 21 | #begin return True if succeed, otherwise return False 22 | while not bmx.begin(): 23 | time.sleep(2) 24 | 25 | ''' 26 | AccelRange_2G 27 | AccelRange_4G 28 | AccelRange_8G 29 | AccelRange_16G 30 | ''' 31 | bmx.set_accel_range(bmx.AccelRange_4G) 32 | time.sleep(0.1) 33 | 34 | 35 | def main(): 36 | while True: 37 | data= bmx.get_all_data() 38 | time.sleep(1) 39 | print("accel x: {0:.2f} m/s^2, y: {1:.2f} m/s^2, z: {2:.2f} m/s^2".format(data[6],data[7],data[8])) 40 | print(" ") 41 | 42 | if __name__ == "__main__": 43 | main() -------------------------------------------------------------------------------- /python/raspberrypi/examples/read_all_data/read_all_data.py: -------------------------------------------------------------------------------- 1 | '''! 2 | @file read_all_data.py 3 | @brief Through the example, you can get the sensor data by using getSensorData: 4 | @n get all data of magnetometer, gyroscope, accelerometer. 5 | @n With the rotation of the sensor, data changes are visible. 6 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | @license The MIT License (MIT) 8 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | @maintainer [Fary](feng.yang@dfrobot.com) 10 | @version V1.0 11 | @date 2021-10-20 12 | @url https://github.com/DFRobot/DFRobot_BMX160 13 | ''' 14 | import sys 15 | sys.path.append('../../') 16 | import time 17 | from DFRobot_BMX160 import BMX160 18 | 19 | bmx = BMX160(1) 20 | 21 | #begin return True if succeed, otherwise return False 22 | while not bmx.begin(): 23 | time.sleep(2) 24 | 25 | def main(): 26 | while True: 27 | data= bmx.get_all_data() 28 | time.sleep(1) 29 | print("magn: x: {0:.2f} uT, y: {1:.2f} uT, z: {2:.2f} uT".format(data[0],data[1],data[2])) 30 | print("gyro x: {0:.2f} g, y: {1:.2f} g, z: {2:.2f} g".format(data[3],data[4],data[5])) 31 | print("accel x: {0:.2f} m/s^2, y: {1:.2f} m/s^2, z: {2:.2f} m/s^2".format(data[6],data[7],data[8])) 32 | print(" ") 33 | 34 | if __name__ == "__main__": 35 | main() -------------------------------------------------------------------------------- /python/raspberrypi/examples/read_gyro_data/read_gyro_data.py: -------------------------------------------------------------------------------- 1 | '''! 2 | @file read_gyro_data.py 3 | @brief Through the example, you can get the sensor data by using getAllData: 4 | @n get gyroscope data of sensor. 5 | @n With the rotation of the sensor, data changes are visible. 6 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | @license The MIT License (MIT) 8 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | @maintainer [Fary](feng.yang@dfrobot.com) 10 | @version V1.0 11 | @date 2021-10-20 12 | @url https://github.com/DFRobot/DFRobot_BMX160 13 | ''' 14 | import sys 15 | sys.path.append('../../') 16 | import time 17 | from DFRobot_BMX160 import BMX160 18 | 19 | bmx = BMX160(1) 20 | 21 | #begin return True if succeed, otherwise return False 22 | while not bmx.begin(): 23 | time.sleep(2) 24 | 25 | ''' 26 | GyroRange_2000DPS 27 | GyroRange_1000DPS 28 | GyroRange_500DPS 29 | GyroRange_250DPS 30 | GyroRange_125DPS 31 | ''' 32 | bmx.set_gyro_range(bmx.GyroRange_500DPS) 33 | 34 | time.sleep(0.1) 35 | 36 | 37 | def main(): 38 | while True: 39 | data= bmx.get_all_data() 40 | time.sleep(1) 41 | print("gyro x: {0:.2f} g, y: {1:.2f} g, z: {2:.2f} g".format(data[3],data[4],data[5])) 42 | print(" ") 43 | 44 | if __name__ == "__main__": 45 | main() -------------------------------------------------------------------------------- /python/raspberrypi/examples/read_magn_data/read_magn_data.py: -------------------------------------------------------------------------------- 1 | '''! 2 | @file read_magn_data.py 3 | @brief Through the example, you can get the sensor data by using getSensorData: 4 | @n get magnetometer data of sensor. 5 | @n With the rotation of the sensor, data changes are visible. 6 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 7 | @license The MIT License (MIT) 8 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 9 | @maintainer [Fary](feng.yang@dfrobot.com) 10 | @version V1.0 11 | @date 2021-10-20 12 | @url https://github.com/DFRobot/DFRobot_BMX160 13 | ''' 14 | import sys 15 | sys.path.append('../../') 16 | import time 17 | from DFRobot_BMX160 import BMX160 18 | 19 | bmx = BMX160(1) 20 | 21 | #begin return True if succeed, otherwise return False 22 | while not bmx.begin(): 23 | time.sleep(2) 24 | 25 | 26 | def main(): 27 | while True: 28 | data= bmx.get_all_data() 29 | time.sleep(1) 30 | print("magn: x: {0:.2f} uT, y: {1:.2f} uT, z: {2:.2f} uT".format(data[0],data[1],data[2])) 31 | print(" ") 32 | 33 | if __name__ == "__main__": 34 | main() -------------------------------------------------------------------------------- /python/raspberrypi/examples/set_low_power/set_low_power.py: -------------------------------------------------------------------------------- 1 | ''' 2 | @file set_low_power.py 3 | @brief Through the example disable or enable the gyroscope and accelerometer sensor. 4 | @n With the rotation of the sensor, data changes are visible. 5 | @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com) 6 | @license The MIT License (MIT) 7 | @author [luoyufeng] (yufeng.luo@dfrobot.com) 8 | @maintainer [Fary](feng.yang@dfrobot.com) 9 | @version V1.0 10 | @date 2021-10-20 11 | @url https://github.com/DFRobot/DFRobot_BMX160 12 | ''' 13 | import sys 14 | sys.path.append('../../') 15 | import time 16 | from DFRobot_BMX160 import BMX160 17 | 18 | bmx = BMX160(1) 19 | 20 | #begin return True if succeed, otherwise return False 21 | while not bmx.begin(): 22 | time.sleep(2) 23 | ''' 24 | Revise the following two paramters according to actula reading of the INA219 and the multimeter 25 | for linearly calibration 26 | ''' 27 | bmx.set_low_power(); #disable the gyro and accel sensor 28 | #bmx.wake_up(); #enable the gyro and accel sensor 29 | #bmx.soft_reset(); #reset the sensor 30 | 31 | time.sleep(0.1) 32 | 33 | 34 | def main(): 35 | while True: 36 | time.sleep(1) 37 | 38 | if __name__ == "__main__": 39 | main() -------------------------------------------------------------------------------- /resources/images/SEN0373.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/DFRobot/DFRobot_BMX160/ed616cff2c8c54e1e3e867fec7ee438e9b06ffa0/resources/images/SEN0373.png --------------------------------------------------------------------------------