Andruino Pro Mini and MPU-6050

Hey there!

I just started with Arduino, so probably the solution for my problem is quite simple, but unfortunatelly I cannot find it -.-

I'm using Arduino Pro Mini (5V, 16MHz) with Atmega 328 board and try to read raw data from MPU-6050. I use USBasp programmator. I connected the MPU SCL to Arduino's PIN 5 (SLC), and SDA to Arduino's PIN 4 (SDA). XDA, XCL and INT I left not connected, the same with AD0 (in programme I use address 0x68). Of course VCC and GND are connected as well :stuck_out_tongue:

Since I'm not an expert (yet ^^) I started with some ready made projects I've found on playground.arduino.cc (this one to be exact http://playground.arduino.cc/Main/MPU-6050#short). I edited a programme a bit, since I don't wanna put the data to Serial Monitor, but 16x2 LCD Display (JHD 162A).

#include <Wire.h>
const int MPU=0x68;  // I2C address of the MPU-6050
int16_t AcX,AcY,AcZ,Tmp,GyX,GyY,GyZ;

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 3, 2); // (RS, E, D4, D5, D6, D7)

void setup()
{  
  Wire.begin();
  Wire.beginTransmission(MPU);
  Wire.write(0x6B);  // PWR_MGMT_1 register
  Wire.write(0);     // set to zero (wakes up the MPU-6050)
  Wire.endTransmission(true);
}

void loop()
{
  Wire.beginTransmission(MPU);
  Wire.write(0x3B);  // starting with register 0x3B (ACCEL_XOUT_H)
  Wire.endTransmission(false);
  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)
  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)
  
  lcd.begin(16, 2);  
  lcd.setCursor(1,1);
  lcd.print(AcX);
  lcd.setCursor(1,0);
  lcd.print(GyX);
  
  delay(500);
  
}

The display is just putting "-1" value to both AcX and GyX, moving the board around doesn't change a thing.

I also checked the other code from same website (Arduino Playground - MPU-6050). I just added

#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 7, 6, 3, 2); // (RS, E, D4, D5, D6, D7)

at the beggining, and

lcd.begin(16, 2);
lcd.setCursor(1,1);
lcd.print(accel_t_gyro.value.y_accel);

in line 760 to just check the data reading. There was a little progression, the LCD is showing some changing values, however they seem to just randomly change, rotating the board doesnt make any difference as well). The values sometimes change between f.ex. 512 and 212 every second, then after some time change to over 30000, then drop drastically.

The communication with LCD is fine, I can put there other data as well, and they behave normally. F.ex. homemade touch sensor used with ADC works perfectly fine.

Does anyone have any idea what could be the problem?

You are making it hard by not using a serial monitor.
With an Arduino Uno this would be easier to solve.

Can you test the display if you really can print any integer value from -32000 to 32000 ?

When you copied the short test sketch, you didn't copy the code line with the temperature.

Tmp=Wire.read()<<8|Wire.read();  // 0x41 (TEMP_OUT_H) & 0x42 (TEMP_OUT_L)

You have to read it, since that register is in between the acceleration and gyro registers.

Can you run the i2c_scanner ? Arduino Playground - I2cScanner
When nothing is connected to pin 0 (RX) and pin 1 (TX) you don't have to remove all the Serial output functions. Just keep them in the sketch, that's no problem. Add the lcd.print() below every Serial.print() function.

When the i2c_scanner is working, let it run for a while to see if it is stable. There should not be a single error.

Some MPU-6050 modules have a 3.3V voltage regulator on the board, those should have 5V to VCC. Other don't have that and must be powered with 3.3V or else the MPU-6050 gets broken. Can you make a photo of your wiring ?

I would love to use Serial Monitor, but unfortunatelly it looks like my PC doesn't find Arduino connected :confused: The "Serial port" in "Tool" menu is grayed, so I cannot use it. I tried to find the solution, unfortunatelly nothing so far :confused:

I've put "-32000" and "32000", works perfectly fine with LCD.

I copied the sketch again and just added LCD printing functions, didn't change a thing.

I've run I2C Scanner, but since I cannot use Serial Monitor, I used LCD to display the results. I put

lcd.begin(16, 2);
lcd.setCursor(1,1);
lcd.print("address");
lcd.setCursor(1,0);
lcd.print(address);
delay(250);

in line 55 and

lcd.setCursor(5,1);
lcd.print("found");

after line 58.

LCD prints 1-127 numbers, doesn't print "found" so I guess it doesn't see the device. I tried with LED on 13th PIN, the same. I tried 4k7 pull-up resistors from SDA and SCL to 5V, nothing changed.

My MPU6050 has built-in 3V3 voltage regulator, so I power it with 5V.

Photos (I unplugged the USBasp output wires to make it more clear view):
Arduino and MPU-6050
The horizontal power line next to MPU-6050 is 5V, GND next to LCD.

Thanks for the photos, but it is not easy to follow the wires. Is one of the two I2C also connected to the display pins ?

You can simplify the i2c scanner by only displaying the found address. There is just one I2C device anyway. If the i2c scanner is not working, it has no use to continue with a sketch for the MPU-6050. All the i2c scanner does, is check the ACKnowledge signal to an address. The MPU-6050 does that when it sees the address 0x68 or 0x69 on the I2C bus.

For the serial monitor, you need a usb-serial adapter. The Arduino Pro Mini doesn't have that included on the board, but you can buy a seperate usb-serial adapter.

There is indeed a 3.3V voltage regulator on the MPU-6050 board, so you can use 5V to VCC. But please don't use pullup resistors to 5V. The MPU-6050 can not have 5V to its SDA and SCL pins. There are already 10k pullup resistors to 3.3V on that MPU-6050 board.

Can you check the wiring once more to the MPU-6050 module. Do you have another breadboard ? Please use a seperate breadboard for the MPU-6050 module.

Ok, I moved the MPU-6050 to another breadboard, hope that now the wiring can be seen more clearly.

No, the I2C wires are connected only to the MPU-6050 SDA and SCL; the LCD wires are connected to 2,3,6 and 7 PINS, that's why it might have seem confusing.

Allright, my bad with the pullup resistors. My friend got this idea, and since it works with his project, I thought it might be solution to mine as well. He uses different Gyro/Accel board though, but he also has pullup resistors there he said (nevermind actually, maybe I mixed up things ;x )

The I2C bus is not at the digital pins, but at the analog pins. Pin A4 = SDA and pin A5 = SCL.
I think that are the two pins in the middle of the board near the red led.

I feel like and idiot now... I reconnected SDA and SCL, and the run the I2C scanner again. Now of course the Arduino is correctly finding the 0x68 address of MPU-6050!

Thank you so much Peter for your help!
I was really frustrated :stuck_out_tongue:

I will work on the rest of my project tommorow, now is time to finally get some sleep :wink: Hope there won't be more problems.

I'm glad you have it working :slight_smile:
You don't have to feel like that, Arduino is about learning along the way, and we are here to help.