5oliuLt0 发表于 2024-4-12 18:29:33

FireBeetle 2 ESP32 C6 Arduino 驱动BMI160 获取陀螺仪值

本帖最后由 5oliuLt0 于 2024-4-12 18:30 编辑

FireBeetle 2 ESP32 C6 拿到手也有一段时间了, 手上有一块带BMI160 的扩展板子,可以验证相关参数;
硬件扩展板子为Infineon CY8CKIT-028-TFT; 板载资源还是比较丰富,包括
1、2.4寸 240*3208080 接口的LCD 屏;
2、BMI160 三轴加速度+三轴陀螺仪;
3、PDM 接口的PDM MIC
4、I2S 接口的Audio CODEC



本次验证BMI160 ;



扩展包为I2C 接口模式;
直接采用BMI160 库文件;
#include <BMI160Gen.h>

const int select_pin = 10;
const int i2c_addr = 0x68;


void setup() {
Serial1.begin(115200); // initialize Serial communication

// initialize device
Serial1.println("Initializing IMU device...");
//BMI160.begin(BMI160GenClass::SPI_MODE, /* SS pin# = */10);
BMI160.begin(BMI160GenClass::I2C_MODE);
uint8_t dev_id = BMI160.getDeviceID();
Serial1.print("DEVICE ID: ");
Serial1.println(dev_id, HEX);

   // Set the accelerometer range to 250 degrees/second
BMI160.setGyroRange(250);
Serial1.println("Initializing IMU device...done.");
}

void loop() {
int gxRaw, gyRaw, gzRaw;         // raw gyro values
float gx, gy, gz;

// read raw gyro measurements from device
BMI160.readGyro(gxRaw, gyRaw, gzRaw);

// convert the raw gyro data to degrees/second
gx = convertRawGyro(gxRaw);
gy = convertRawGyro(gyRaw);
gz = convertRawGyro(gzRaw);

// display tab-separated gyro x/y/z values
Serial1.print("g:\t");
Serial1.print(gx);
Serial1.print("\t");
Serial1.print(gy);
Serial1.print("\t");
Serial1.print(gz);
Serial1.println();

delay(500);
}


float convertRawGyro(int gRaw) {
// since we are using 250 degrees/seconds range
// -250 maps to a raw value of -32768
// +250 maps to a raw value of 32767

float g = (gRaw * 250.0) / 32768.0;

return g;
}



添加代码,编译,下载输出;

页: [1]
查看完整版本: FireBeetle 2 ESP32 C6 Arduino 驱动BMI160 获取陀螺仪值