Code Monkey home page Code Monkey logo

Comments (3)

balzss avatar balzss commented on May 28, 2024

Ok, I did some debugging and rewrote the readRegisters function like so:

int MPU9250::readRegisters(uint8_t subAddress, uint8_t count, uint8_t* dest){
  if( _useSPI ){
    // SPI code left out for conciseness
  } else {
    _i2c->beginTransmission(_address); // open the device
    _i2c->write(subAddress); // specify the starting register address
    int resultEndTransmission = _i2c->endTransmission(false);
    if(resultEndTransmission > 0) {
        return -200 - resultEndTransmission;
    }
    _numBytes = _i2c->requestFrom(_address, count); // specify the number of bytes to receive
    if (_numBytes == count) {
      for(uint8_t i = 0; i < count; i++){ 
        dest[i] = _i2c->read();
      }
      return 1;
    } else {
      return -100 - _numBytes;
    }
  }
}

and the readSensor function like so:

int MPU9250::readSensor() {
  _useSPIHS = true; // use the high speed SPI for data readout
  // grab the data from the MPU9250
  int resultReadReg = readRegisters(ACCEL_OUT,21, _buffer);
  if (resultReadReg < 0) {
      return resultReadReg;
  }
 // rest of the function left out for conciseness
}

After the modifications I monitored the readSensor's return value and I got a couple -100 but it always continued flawlessly. However after a couple of minutes I started getting -205 return values which according to the arduino docs shouldn't even be possible because the endTransmission function's return values should range from 0 to 4 (and not 5).

A tried to just disconnect the sensor while running and I got the same error code but after reconnecting it the readings didn't continue.

I can imagine that some of my freezings happen because the cables disconnect for a very short time but there are times when everything is completely still and the freezing still occurs.

I also wanted to connect is via SPI but I couldn't get it working at all.

from invensense-imu.

flybrianfly avatar flybrianfly commented on May 28, 2024

Is this the core that you're using? Are you on the newest version or something older?
https://github.com/espressif/arduino-esp32

I'll need to dig into it in detail to try to figure out what's going on. Seems like maybe something with the endTransmission(false) isn't working 100% reliably. Unfortunately, my schedule is a bit tied up until after March 9th to dig around in detail.

from invensense-imu.

balzss avatar balzss commented on May 28, 2024

Yes I'm using the latest arduino-esp32 core. Reading through this thread it seems like that the problem is in the core itself and we can't do anything with your library to avoid it so I think my (and anyone with this problem) only options are:

  • using SPI instead of I2C
  • using ESP8266 instead of ESP32

I tried my luck again with the SPI version and I was able the initialize the sensor (you have to use the VSPI labeled pins instead of the SPI ones) but the reading was all over the place, like I was generating just random numbers. Do you have any idea why I didn't got usable readings? I'll try to debug it later today. And another question: if the sensor is working correctly through an SPI connection and I temporarily disconnect one of the cables for a short period, will it work flawlessly after that? Or will I have to initialize the sensor again? Thanks for the help!

from invensense-imu.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.