bolderflight / invensense-imu

Arduino and CMake library for communicating with the InvenSense MPU-6500, MPU-9250 and MPU-9255 nine-axis IMUs.
MIT License
498 stars 211 forks source link

MPU9255 Data is wrong and recommend some improvements #9

Closed williamesp2015 closed 3 years ago

williamesp2015 commented 6 years ago

This is great source for MPU9255 but I found error and unstability of sensor data in readsensor() when I printed raw data: // display the data Serial.print(_axcounts); Serial.print(" \t"); Serial.print(_aycounts); Serial.print(" \t"); Serial.print(_azcounts); Serial.print(" \t"); Serial.print(_gxcounts); Serial.print(" \t"); Serial.print(_gycounts); Serial.print(" \t"); Serial.print(_gzcounts); Serial.print(" \t"); Serial.print(_hxcounts); Serial.print(" \t"); Serial.print(_hycounts); Serial.print(" \t"); Serial.print(_hzcounts); Serial.print(" \t"); Serial.println(_tcounts); raw data printed like this: 30827 -59 -32145 32763 48 -22 27 10 32730 -31909 30825 32703 618 -5 -32702 32747 27 10 32730 859 30825 32703 618 -5 -32702 32747 27 10 32730 859 30813 -61 -32168 32767 54 -16 27 10 32730 856 30813 -61 -32168 32767 54 -16 27 10 32730 856 30836 -57 -32152 -1 -4 -4 27 10 32730 858 30836 -57 -32152 -1 -4 -4 27 10 32730 858

I also recommend custom SPI definition using: int MPU9250::begin(uint8_t CLKPIN,uint8_t SOPIN,uint8_t SIPIN,uint8_t _csPIN) // setting CS pin to output pinMode(_csPin,OUTPUT); // setting CS pin high digitalWrite(_csPin,HIGH); // setting SPI SO pin to output pinMode(SOPIN,OUTPUT); // setting SPI SI pin to input pinMode(SIPIN,INPUT); // setting SPI CLK pin to input pinMode(CLKPIN,INPUT); // begin SPI communication // _spi->begin(); _spi->begin(CLKPIN,SOPIN,SIPIN,_csPIN);////SPI.begin(int8_t sck=SCK, int8_t miso=MISO, int8_t mosi=MOSI, int8_t ss=-1);

flybrianfly commented 6 years ago

Can you please attach or send the code you are using for the counts data?

For the SPI methods, you can use the SPI.setMISO, SPI.setMOSI, and SPI.setSCK commands, like this:

MPU9250 IMU(SPI,10);
int status;

void setup() {
  // serial to display data
  Serial.begin(115200);
  while(!Serial) {}

  SPI.setMOSI(7);
  SPI.setMISO(8);
  SPI.setSCK(14);

  // 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) {}
  }
}
williamesp2015 commented 6 years ago

Thanks. I am using ESP32 development board with ESP32-Arduino using PlatformIo and it has not SPI.setMOSI.... so I mannually configured SPI pins then start SPI (SPI.begin(_SCK,_MISO, _MOSI, ss);). I have doubt about my GY-9255 MPU-9255 Sensor Module (http://www.electrodragon.com/product/9dof-mpu-9255-3d-acceleromagnetogyroscope-breakout/). Anyone had experience with this board? I have another problem using Arduino-generic brach when I want to start MPU9255 interrupt: ///////////MPU9255 // start communication with IMU and // set the accelerometer and gyro ranges. // ACCELEROMETER 2G 4G 8G 16G // GYRO 250DPS 500DPS 1000DPS 2000DPS beginStatus = IMU.begin(ACCEL_RANGE_4G,GYRO_RANGE_250DPS);

if(beginStatus < 0) { delay(1000); Serial.println("IMU initialization unsuccessful"); Serial.println("Check IMU wiring or try cycling power"); while(1){}; }

// set up the IMU DLPF, data output rate, // and interrupt. DLPF set to 41 Hz, // data output rate set to 100 Hz, and // MPU-9250 generated interrupt attached // to Teensy pin 2 setFiltStatus = IMU.setFilt(DLPF_BANDWIDTH_41HZ,9); if(setFiltStatus < 0) { delay(1000); Serial.println("Filter initialization unsuccessful"); while(1){}; } pinMode(INT_PIN,INPUT); attachInterrupt(INT_PIN,getIMU,RISING); ESP32 restarts once starts Interrupt. I also added IMU.enableInt(true); before last line but had no different outcome.

Ananfruit commented 3 years ago

Can you share the code when you calibrate your accel and gyro, please? Thanks in advance!