|

楼主 |
发表于 2021-12-15 19:35
|
显示全部楼层
参考代码
- #include <BMI160.h>
- #include <BMI160Gen.h>
- #include <CurieIMU.h>
- //const int i2c_addr = 0x69;
- void setup() {
- Serial.begin(9600); // initialize Serial communication
- while (!Serial); // wait for the serial port to open
- // initialize device
- Serial.println("Initializing IMU device...");
- BMI160.begin(BMI160GenClass::SPI_MODE, /* SS pin# = */10);
- //BMI160.begin(BMI160GenClass::I2C_MODE);
- uint8_t dev_id = BMI160.getDeviceID();
- Serial.print("DEVICE ID: ");
- Serial.println(dev_id, HEX);
- // Set the accelerometer range to 250 degrees/second
- BMI160.setGyroRange(125);
- Serial.println("Initializing IMU device...done.");
- }
- void loop() {
- int gx, gy, gz; // raw gyro values
- // read raw gyro measurements from device
- BMI160.readGyro(gx,gy,gz);
- // display tab-separated gyro x/y/z values
- Serial.print("g:\t");
- Serial.print(gx);
- Serial.print("\t");
- Serial.print(gy);
- Serial.print("\t");
- Serial.print(gz);
- Serial.println();
- delay(1);
- }
- 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;
- }
复制代码
|
|