Today my MPU6050 finally arrived, however it isn't functioning as expected. it has been plugged in correctly to my Arduino Nano, it seems to be getting power as the LED is green, however the program isn't functioning, it isn't printing any data and I don't believe it's even receiving any. I think my code to be correct but it may be flawed in some way, I'm not confident in my capabilities as of the moment. Something I noticed with it is that when I remove the MPU6050 the code still runs without any present error even though it is programmed to print an error message if there is a problem with the IMU, leading me to believe that it isn't connecting to it. Note that I have not yet soldered the IMU to the pins and it is simply sitting on them as of the moment, could that effect it?
:Troubleshooting Hints: 1. Are you using this 5V Supply 5V logic breakout board (Fig-1) with pins soldered? If pins are not soldered, solder them and then go to Step-2.
Figure-1:
2. Connect AD0-pin to GND to assign I2C address at 0x68 and then upload the following sketch to see the presence of the sensor in the I2C Bus.
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
//---------------------------------
Wire.beginTransmission(0x68);
byte busStatus = Wire.endTransmission();
if(busStatus !=0 )
{
Serial.print("Sensor is not found on I2C Bus!");
while(1); //wait for ever
}
Serial.println("Sensor is found on I2C Bus.");
}
void loop()
{
}
3. If Step-2 works, then upload the following sketch to see that the built-in temperture sensor of MPU6050 is responding.
#include<Wire.h>
#define MPUaddr 0x68
void setup()
{
Serial.begin(9600);
Wire.begin();
}
void loop()
{
Wire.beginTransmission(MPUaddr); //Start communication with the MPU-6050.
Wire.write(0x6B); //We want to write to the PWR_MGMT_1 register (6B hex).
Wire.write(0x00); //enable temp sensor //Set the register bits as 00000000 to activate the gyro.
Wire.endTransmission();
//----pointing temp sensor-----------------
Wire.beginTransmission(MPUaddr); //Start communication with the MPU-6050.
Wire.write(0x41); //pointing Temp_Out_High Reg //Set the register bits as 00000000 to activate the gyro.
Wire.endTransmission();
Wire.requestFrom(MPUaddr, 2); //two-byte temp data //End the transmission with the gyro.
byte x1 = Wire.read();
byte x2 = Wire.read();
int x = (int)(x1<<8)|(int)x2;
//------compute temp from x-----
float mpuTemp = (float)(x/340.0 + 36.53); //formula from data sheets
Serial.print("Temp = ");
Serial.print(mpuTemp, 2); //2-digit after decimal point
Serial.println(" degC");
delay(1000);
}
4. Upload the following Library based sketch to check the response of the temperature element of MPU6050 sensor.
Ok so the VCC pin is connected to 5V, SCL is connected to A5 and SDL is connected to A4. The code is derived from the the code used by Nicholas Rehm on youtube for a vtol F35 stabilization computer, I simply modified it slightly as it didn't require the madgwick filter and such.
I've tried the example code for 3 of the MPU6050 libraries, the Adafruit library, Basic MPU6050 and the library I used, Arduino Mpu6050 master.
The basic example for the Adafruit library prints an error message when run "Error compiling for Arduino", the Basic Mpu6050 library just doesn't do anything and the library that I was using, the Arduino Mpu6050 master, the example for that fails with the message 'class MPU6050' has no member named 'begin'.
Sorry for the incredibly late reply but I have finally gotten the IMU soldered and I've ran your code, it suggested that there is still no sensor detected on the I2c bus, I tried the code in step 3 however that ran with a constant temperature of 36.5 degrees Celsius if I remember correctly, which was wildly inaccurate for the conditions in the room I'm testing it in. The code in step 4 printed the area message 'class MPU6050' has no member named 'readTemperature'; did you mean 'getTemperature'? so I have no clue what to do from here.
Sir you are certainly correct, my apologies. the full error message read 'fatal error: Adafruit_Sensor.h: No such file or directory #include <Adafruit_Sensor.h>
^~~~~~~~~~~~~~~~~~~
compilation terminated.
exit status 1
Error compiling for board Arduino Nano.'
Please, post the picture of your MPU6050 Breakout Board Module. After that I will forward to you diagnostic sketch; where, the we will be able to see message if the Sensor has been detected at address 0x68 or not.
Where have you connected the AD0-pin of the module? It should be connected at GND-pin to select I2C address at 0x68 and at 5V to select address 0x69. Reemmeber that the MPU6050.h Library has keyed the address 0x68.
sorry if the quality of the photo is horrible, I can probably get a better image if needed. note that mere minutes ago I used an I2c scanner sketch and it didn't detect the IMU.
1. Connect AD0-pin of the sensor at GND pin of NANO. 2. Upload the following sketch in your NANO and report what message you have got in the Serial Monitor.
#include<Wire.h>
void setup()
{
Serial.begin(9600);
Wire.begin();
Wire.beginTransmission(0x68);
byte busStatus = Wire.endTransmission();
if(busStatus != 0)
{
Serial.print("Senor is not found on I2C Bus!");
while(1); //wait for ever
}
Serial.println("Sensor is found on the I2C Bus.");
}
void loop()
{
}
The wiring in the latest photo looks OK but the soldering of the pins on the sensor looks a bit scruffy and needs checking. It would also be a good idea to check continuity of all four connections between the Nano and the sensor to eliminate possible problems with the jumpers, which are quite common, and the breadboard, which are also not unknown. Is there an LED on the sensor board and if so, does it light up ?
Have you got any female to female jumpers so that the breadboard could be eliminated from the circuit ?
Until an I2C scanner can find the board there is no point in trying to read from the sensor