08-01-2020 12:36 AM - edited 08-01-2020 12:37 AM
Hi
I am using the BMI160 shuttle board with Arduino Uno over SPI. Also, I am using the Driver developed by Hanyazou https://github.com/hanyazou/BMI160-Arduino. The connection is okay but the gyro results are incorrect (random data). Also, the device id is returned 7F which means somewhere in the code or connection is wrong. Can you please help me resolve the issue?
Please see the code below (The code is the example in the Hanyazou GitHub).
#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;
}
And this is the connection photo.
Your help is truly appreciated!
Thanks
Saber
Solved! Go to Solution.
08-05-2020 02:22 AM - edited 08-05-2020 02:27 AM
Hi SaberKazemi1992,
I just downloaded github, and tested with Arudino UNO.
And I successfully worked fine. Please follow this step.
< Hardware setting >
- Please check the attached file.
< Software setting >
I just copied and run your code, but different thing was I copied all library in arduino running so that I included as below.
#include "BMI160.h"
#include "BMI160Gen.h"
#include "CurieIMU.h"
Please let me know if you still get an error.
Thanks,
08-11-2020 08:04 PM
Thanks, Mihwan for the detailed information and especially the photo!
It worked perfectly fine!
In the past, I exactly followed the same pin configuration as you provided and never doubted the GND for 3.3V. This time I used the other pin for GND and the problem solved!!. It is weird for me as the two GNDs should be connected to each other.
By the way, it is working fine. Thanks and I appreciate your time!
Saber