Jump to content
I2Cdevlib Forums

dennisma

Members
  • Content Count

    7
  • Joined

  • Last visited

  • Days Won

    2
  1. Sorry for multiple posts. There doesn't seem to be a way to remove this however.
  2. I have been experiencing hanging and have been going through the code attempting to resolve it. I noticed in the I2Cdev::readBytes() method that the implementation for Arduino versions > 100 there is a call to Wire.beginTransmission() without a subsequent call to endTransmission(). For Arduino < 100 it is there. You can see this starting on line 280: Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH)); for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = Wire.read(); #ifdef I2CDEV_SERIAL_DEBUG Serial.print(data[count], HEX); if (count + 1 < length) Serial.print(" "); #endif } } Also I've never seen requestFrom called from within a beginTransmission/endTransmission block. Maybe it will cause no problems but this seems to be where I hang often.
  3. I have been experiencing hanging and have been going through the code attempting to resolve it. I noticed in the I2Cdev::readBytes() method that the implementation for Arduino versions > 100 there is a call to Wire.beginTransmission() without a subsequent call to endTransmission(). For Arduino < 100 it is there. You can see this starting on line 280: Wire.beginTransmission(devAddr); Wire.requestFrom(devAddr, (uint8_t)min(length - k, BUFFER_LENGTH)); for (; Wire.available() && (timeout == 0 || millis() - t1 < timeout); count++) { data[count] = Wire.read(); #ifdef I2CDEV_SERIAL_DEBUG Serial.print(data[count], HEX); if (count + 1 < length) Serial.print(" "); #endif } } Also I've never seen requestFrom called from within a beginTransmission/endTransmission block. Maybe it will cause no problems but this seems to be where I hang often.
  4. I only want to read the sensor on certain occasions (say maybe every 4 seconds or so). I can make the code work by simply not getting the data but the FIFO overflows. I can reset the FIFO but that seems ugly and one post said have said FIFO overflows have bad side effects (I've had some occasional hanging). I thought a call to setSleepEnabled(true); and then call setSleepEnabled(false) before grabbing the data would work but that doesn't seem to. Is there a way to accomplish this?
  5. I've used 3.3v I2C devices with Arduinos before just fine until.... you also decide you need a 5v I2c device on the bus as well. Then you have to partition the clock and data lines with a level shifter.
  6. What breakout board are you using? Does it have a pin marked AD0? If so is it connected to either ground or your voltage? It really sounds like your AD0 pin is floating (not connected to ground nor voltage). That would explain why the I2C address randomly changes because the AD0 pin controls the least significant bit of the I2C address. If AD0 is floating it will sometimes be high and sometimes be low thus your address changes. Connect it to ground and see if the address keeps changing when you scan. Also an error 2 sounds like the error coming back from the Wire library. Again you would get that error if it could not find the address (returned from Wire.endTransmission());
  7. Thanks this worked well first time. I made a slight modification to your code. In the loop() where it prints out the offsets I changed it to the following: Serial.println("Your offsets:\t"); Serial.print("mpu.setXGyroOffset("); Serial.print(gx_offset); Serial.println(");"); Serial.print("mpu.setYGyroOffset("); Serial.print(gy_offset); Serial.println(");"); Serial.print("mpu.setZGyroOffset("); Serial.print(gz_offset); Serial.println(");"); Serial.print("mpu.setXAccelOffset("); Serial.print(ax_offset); Serial.println(");"); Serial.print("mpu.setYAccelOffset("); Serial.print(ay_offset); Serial.println(");"); Serial.print("mpu.setZAccelOffset("); Serial.print(az_offset); Serial.println(");"); The output then becomes the following: Sensor readings with offsets: 4 2 16388 0 0 -2 Your offsets: mpu.setXGyroOffset(37); mpu.setYGyroOffset(-44); mpu.setZGyroOffset(26); mpu.setXAccelOffset(-1282); mpu.setYAccelOffset(-727); mpu.setZAccelOffset(1732); That way I can just copy/paste/format the code and I am done. Just a thought.
×
×
  • Create New...