George1988
Member
Hello,
I am trying to read data coming out of an MPU9250 imu. I download Brian R Taylor library but it doesn't seem to work in my case. Whenever I run the code below I get the following:
IMU initialization unsuccessful
Check IMU wiring or try cycling power
Status -1
So I assumed that something is wrong with the library and I checked the following with an oscilloscope. ss pin of the IMU was High instead of Low to enable slave. I also checked the SCK clock signal and MISO chanel there are both always high I am not receiving any kind of square wave signal. However, if I use SPI library to generate a SCK signal and make SS pin low. It seems that I am receiving data out of MISO (checked with an oscilloscope). So I guess hardware is fine.
The IMU MISO= PIN 12
MOSI=11
SSIMU=10
SCK=13
I am sharing SCK bus and MISO with other slave devices and this is why I added some additional lines to the example of Brian R Taylor that you can see in the link below:
https://github.com/bolderflight/MPU9250/blob/master/examples/Basic_SPI/Basic_SPI.ino
Any ideas?
I am trying to read data coming out of an MPU9250 imu. I download Brian R Taylor library but it doesn't seem to work in my case. Whenever I run the code below I get the following:
IMU initialization unsuccessful
Check IMU wiring or try cycling power
Status -1
So I assumed that something is wrong with the library and I checked the following with an oscilloscope. ss pin of the IMU was High instead of Low to enable slave. I also checked the SCK clock signal and MISO chanel there are both always high I am not receiving any kind of square wave signal. However, if I use SPI library to generate a SCK signal and make SS pin low. It seems that I am receiving data out of MISO (checked with an oscilloscope). So I guess hardware is fine.
The IMU MISO= PIN 12
MOSI=11
SSIMU=10
SCK=13
I am sharing SCK bus and MISO with other slave devices and this is why I added some additional lines to the example of Brian R Taylor that you can see in the link below:
https://github.com/bolderflight/MPU9250/blob/master/examples/Basic_SPI/Basic_SPI.ino
Any ideas?
Code:
#include "MPU9250.h"
const int ssimu = 10; // slave selection enable is low
const int sshand = 24;
const int ssfork = 25;
const int pwrencoders = 26; // making high enable power to encoders
// an MPU9250 object with the MPU-9250 sensor on SPI bus 0 and chip select pin 10
MPU9250 IMU(SPI,10);
int status;
void setup() {
pinMode (ssimu,OUTPUT); // setting HIGH slave selection pin to disable IMU
pinMode (sshand, OUTPUT);
pinMode (ssfork, OUTPUT);
pinMode (pwrencoders, OUTPUT);
pinMode (ssimu, OUTPUT);
// serial to display data
Serial.begin(115200);
while(!Serial) {}
// start communication with IMU
status = IMU.begin();
if (status < 0) {
Serial.println("IMU initialization unsuccessful");
Serial.println("Check IMU wiring or try cycling power");
Serial.print("Status: ");
Serial.println(status);
while(1) {}
}
}
void loop() {
digitalWrite(sshand,HIGH); // setting LOW slave selection pin to enable handlebar encoder
digitalWrite(pwrencoders,LOW); // setting HIGH PA10 pin of external pcb connected to pin 26 of teensie to enable power to my encoders
digitalWrite(ssfork,HIGH); // setting HIGH slave selection pin to disable fork encoder
digitalWrite(ssimu,LOW); // setting HIGH slave selection pin to disable IMU
// read the sensor
IMU.readSensor();
// display the data
Serial.print(IMU.getAccelX_mss(),6);
Serial.print("\t");
Serial.print(IMU.getAccelY_mss(),6);
Serial.print("\t");
Serial.print(IMU.getAccelZ_mss(),6);
Serial.print("\t");
Serial.print(IMU.getGyroX_rads(),6);
Serial.print("\t");
Serial.print(IMU.getGyroY_rads(),6);
Serial.print("\t");
Serial.print(IMU.getGyroZ_rads(),6);
Serial.print("\t");
Serial.print(IMU.getMagX_uT(),6);
Serial.print("\t");
Serial.print(IMU.getMagY_uT(),6);
Serial.print("\t");
Serial.print(IMU.getMagZ_uT(),6);
Serial.print("\t");
Serial.println(IMU.getTemperature_C(),6);
delay(100);
}