After spending the whole afternoon tempting to figure out how to connect the magnetometer to uc via the MPU6050, it finally worked and gave me readings of the magnetometer.
All credit to sly_tom_cat, for his suggestion is the most important thing in the whole procedure. Having been through all the tiring and frustration,
despair emotions today, I can't wait to share this to all, who may need it, but without having a satisfying answer up to this moment. Hope you're gonna make it by the time you finish these steps. 
- First, let import the 2 helpful libraries written by Jeff Rowberg from these sources to your library folder ( Simply save them by a code editor, and copy the whole folders containing those files into your Sketchbook location. Open the IDE > Files > Preferences, here you may find the link to that location)
MPU6050 library:
HMC5883L library:
- Open the source code MPU6050.cpp, you may find the 3 functions:
setI2CMasterModeEnabled(false);
setI2CBypassEnabled(true) ;
setSleepEnabled(false);
Those are to enable the MPU6050 I2c bypass mode. I list them in the same order as those 3 steps Sly_tom_cat mentioned above.
There are three steps required to activate the bypass mode of MPU 5060:
- set I2C Master enable bit (I2C_MST_EN, bit 5) in user control register (USER_CTRL , 0x6A) to 0 (on MPU5060 power up it is already equeal zero).
- set I2C Bypass enable bit (I2C_BYPASS_EN,bit 2) in INT Pin / Bypass Enable Configuration register (INT_PIN_CFG,0x37) to 1.
- Turn off sleep mode by reseting SLEEP bit (bit 6) of the power management register #1 (PWR_MGMT_1, 0x6B).
I included the arguments as "true" or "false". Those are the same as "setting" or " clearing" a bit respectively. Briefly saying, those 3 lines work as the key to unlock the door in the MPU, which allows your micro controller to access the magnetometer. After calling those functions in your code, you have all the freedom to access the HMC5883 as I told. That means, any function from the HMC5883L library you just downloaded would probably work from now on!
- You don't have to wait much longer, just a few small steps.
After working so hard on this, I lost all of patience to write the testing code myself. Simply use the available examples provided within those 2 libraries. Let open the IDE: Files> Examples> MPU6050_raw and type all the above functions inside void setup(){ }.
Note: they must be called after initiating I2C bus, below Wire.begin();
void setup() {
Wire.begin();
accelgyro.setI2CMasterModeEnabled(false);
accelgyro.setI2CBypassEnabled(true) ;
accelgyro.setSleepEnabled(false);
Serial.begin(38400);
Then open Files>Examples>HMC5883_raw and copy some lines of code to your currently working MPU6050_raw sketch to acquire and display the mag readings. Combine them all and the final sketch's gonna look like this:
#include "Wire.h"
#include "I2Cdev.h"
#include "MPU6050.h"
#include "HMC5883L.h"
MPU6050 accelgyro;
HMC5883L mag;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int16_t mx, my, mz;
#define LED_PIN 13
bool blinkState = false;
void setup() {
Wire.begin();
accelgyro.setI2CMasterModeEnabled(false);
accelgyro.setI2CBypassEnabled(true) ;
accelgyro.setSleepEnabled(false);
Serial.begin(38400);
// initialize device
Serial.println("Initializing I2C devices...");
accelgyro.initialize();
mag.initialize();
Serial.println(mag.testConnection() ? "HMC5883L connection successful" : "HMC5883L connection failed");
// verify connection
Serial.println("Testing device connections...");
Serial.println(accelgyro.testConnection() ? "MPU6050 connection successful" : "MPU6050 connection failed");
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
void loop() {
accelgyro.getMotion6(&ax, &ay, &az, &gx, &gy, &gz);
mag.getHeading(&mx, &my, &mz);
// display tab-separated accel/gyro x/y/z values
Serial.print("a/g:\t");
Serial.print(ax); Serial.print("\t");
Serial.print(ay); Serial.print("\t");
Serial.print(az); Serial.print("\t");
Serial.print(gx); Serial.print("\t");
Serial.print(gy); Serial.print("\t");
Serial.print(gz);Serial.print("\t");
Serial.print("mag:\t");
Serial.print(mx); Serial.print("\t");
Serial.print(my); Serial.print("\t");
Serial.print(mz); Serial.print("\t");
// To calculate heading in degrees. 0 degree indicates North
float heading = atan2(my, mx);
if(heading < 0)
heading += 2 * M_PI;
Serial.print("heading:\t");
Serial.println(heading * 180/M_PI);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}
now, let compile, then upload and open your serial monitor to get your mag readings 