Go Down

Topic: MPU-6050 on I2C freezes arduino (Read 64 times) previous topic - next topic


Hi everyone,
I don't know if I'm on the right section but I hope so. I have been building a custom steering wheel to play racing simulation games on my pc using my Arduino Mega 2560 and the MegaJoy library. Due to complications I needed to move my steering axis on another board (an Arduino UNO R3) and it works by taking the analog value of a potentiometer (on pin A0) and the acceleration on the Y axis with a MPU-6050 (on the dedicated SDA and SCL of the UNO), mapping them in a 0-1024 range. The problem comes when i start using I2C on the UNO. Using it on the mega gave no problems on the reading itself, but when i move the SDA and SCL pins on the UNO the code freezes and never recovers back. The whole code is really long (always enough memory available tho) and I'm not gonna post it because nobody would even read it, but the problem comes even with the most basic test code:

Code: [Select]
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;
void setup(){
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
void loop(){
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.requestFrom(MPU,14,true);  // request a total of 14 registers
  AcX=Wire.read()<<8|Wire.read();  // 0x3B (ACCEL_XOUT_H) & 0x3C (ACCEL_XOUT_L)     
  AcY=Wire.read()<<8|Wire.read();  // 0x3D (ACCEL_YOUT_H) & 0x3E (ACCEL_YOUT_L)
  AcZ=Wire.read()<<8|Wire.read();  // 0x3F (ACCEL_ZOUT_H) & 0x40 (ACCEL_ZOUT_L)
  Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)
  GyX=Wire.read()<<8|Wire.read();  // 0x43 (GYRO_XOUT_H) & 0x44 (GYRO_XOUT_L)
  GyY=Wire.read()<<8|Wire.read();  // 0x45 (GYRO_YOUT_H) & 0x46 (GYRO_YOUT_L)
  GyZ=Wire.read()<<8|Wire.read();  // 0x47 (GYRO_ZOUT_H) & 0x48 (GYRO_ZOUT_L)
  Serial.print("Accelerometer: ");
  Serial.print("X = "); Serial.print(AcX);
  Serial.print(" | Y = "); Serial.print(AcY);
  Serial.print(" | Z = "); Serial.println(AcZ);
  //equation for temperature in degrees C from datasheet
  Serial.print("Temperature: "); Serial.print(Tmp/340.00+36.53); Serial.println(" C ");
  Serial.print("Gyroscope: ");
  Serial.print("X = "); Serial.print(GyX);
  Serial.print(" | Y = "); Serial.print(GyY);
  Serial.print(" | Z = "); Serial.println(GyZ);
  Serial.println(" ");

After a few seconds and some measurements (from 10 to even 700) it suddenly freezes. I've tried using a watchdog but it kicks in too slowly for my project (you can notice easily a stop on the data stream and while racing this isn't good because you can't control the car, so i need a better solution.

Thanks in advance to who will answer.

(Sorry if my english is not the best :P)


Please provide a link to the schematic of the board you're using and post a wiring diagram.

What pullups do you have in place for the I2C lines? Do you use a level converter to convert the 3V3 of the MPU-6050 to the 5V of the Arduino or do you simply pull them to 3V3?

You can patch the Wire library to better handle clumsy hardware/wiring but with a correct hardware setup this isn't necessary.

Go Up

Please enter a valid email to subscribe

Confirm your email address

We need to confirm your email address.
To complete the subscription, please click the link in the email we just sent you.

Thank you for subscribing!

via Egeo 16
Torino, 10131