Go Down

Topic: Arduino + MPU6050 + HMC5883L (Read 188 times) previous topic - next topic

TPol

Dear All,

I am asking your help and guidance because after searching the internet I was not satisfied with what I found. (Probably my searching skills are not good enough)

I would like to connect both a gyroscope sensor and a magnetometer to an arduino(uno, nano, micro, mega, I have at hand). Final goal is to get out two data: azimuth and elevation.  Azimuth from the magnetometer and elevation from the gyroscope one of the axis. Rest of the data I am not interested.

I already have these boards at home - now of course I see that there are single boards that can do that like MPU-9255 but I don't have that.

Problem is when I started reading about how to connect them to the arduino both boards want to connect to the same pins SDA (A4), SCL (A5) and I don't have the experience how to solve this. I found two different wirings (one is incomplete) but they are different.
https://forum.arduino.cc/index.php?topic=457129.15
and
https://camo.githubusercontent.com/708e8d3eb17afe97128fadb9d66590aa7b605678/687474703a2f2f64656c706869722e636f6d2f61726475696e6f2f494d475f343336322e6a7067

Can you help me with the wirings and how to access the values?

I found a lot of information on how to connect and access data from a gyroscope or a magnetometer but when they are both present I didn't find much information.

Thank you

Robert

jremington

#1
Jan 17, 2020, 06:03 pm Last Edit: Jan 17, 2020, 06:05 pm by jremington
Quote
both boards want to connect to the same pins SDA (A4), SCL (A5)
Correct. The I2C connections are intended to support several devices in parallel, if they all have different device addresses.   Tutorial here

In your case, they do, so combine the codes sensibly and it should work.

TPol

#2
Jan 17, 2020, 07:18 pm Last Edit: Jan 17, 2020, 07:34 pm by TPol
O, I see.
This makes my job easier. :)

One question tho, should I use pull up resistors? Normally I think not but I read it somewhere and made me unsure.

Thank you for your quick answer!

Edit: I ask before reading the tutorial. Ignor my question.

zhomeslice

Dear All,

I am asking your help and guidance because after searching the internet I was not satisfied with what I found. (Probably my searching skills are not good enough)

I would like to connect both a gyroscope sensor and a magnetometer to an arduino(uno, nano, micro, mega, I have at hand). Final goal is to get out two data: azimuth and elevation.  Azimuth from the magnetometer and elevation from the gyroscope one of the axis. Rest of the data I am not interested.

I already have these boards at home - now of course I see that there are single boards that can do that like MPU-9255 but I don't have that.

Problem is when I started reading about how to connect them to the arduino both boards want to connect to the same pins SDA (A4), SCL (A5) and I don't have the experience how to solve this. I found two different wirings (one is incomplete) but they are different.
https://forum.arduino.cc/index.php?topic=457129.15
and
https://camo.githubusercontent.com/708e8d3eb17afe97128fadb9d66590aa7b605678/687474703a2f2f64656c706869722e636f6d2f61726475696e6f2f494d475f343336322e6a7067

Can you help me with the wirings and how to access the values?

I found a lot of information on how to connect and access data from a gyroscope or a magnetometer but when they are both present I didn't find much information.

Thank you

Robert
Your MPU6050 and the HMC5883l can be attached to the same i2c bus they both will have pullup resistors on their breakouts if you desire to add more devices to the bus you may want to unsolder some of the pullups resistors from the additional breakout boards especially if other devices have those resistors attached to a 5V source.
To merge the two into a calibrated reading that always points north is another story one of which I am definitely interested in discovering.
Heres what I have to this point
Where everything at from the manufacturer
https://www.invensense.com/developers/login/
There are downloads available that have the source code that we have developed our libraries from. 
Mine is https://github.com/ZHomeSlice/Simple_MPU6050
Jeffs is https://github.com/jrowberg/i2cdevlib/tree/master/Arduino/MPU6050
The 9 Degrees of freedom uses the pre-compiled library found int the developer's downloads section V6.12 for Motion Processing is named libmplmpu.lib This is different than the eMPL (Embedded Motion Processing Library) that we use in our code which only provides merged data from the Gyro and Accelerometer The Magnetometer is missing that is until we can discover how to implement the libmplmpu.lib into our code.
Thanks for joining the challenge  :)
Z
HC

GolamMostafa

#4
Jan 18, 2020, 08:54 am Last Edit: Jan 18, 2020, 08:58 am by GolamMostafa
If you have followed this connection diagram (Fig-1), then the I2C addresses of:
MPU6050 is:    0x69
HMC8883L is:  0x68

You need to edit the MPU6050.h Library to set the address of the device at 0x69.

Fig-1:

This is the Library I use for MPU6050.

zhomeslice

#5
Jan 19, 2020, 02:02 am Last Edit: Jan 19, 2020, 02:04 am by zhomeslice
If you have followed this connection diagram (Fig-1), then the I2C addresses of:
MPU6050 is:    0x69
HMC8883L is:  0x68

You need to edit the MPU6050.h Library to set the address of the device at 0x69.

Fig-1:

This is the Library I use for MPU6050.
Isn't the address of the HMC8883L  0x1E  or 30 ?

Also, note that passing the i2c data through the MPU6050 isn't necessary. Use it if you want the MPU6050 to gather it for you. But It does nothing with the data besides getting it. and there is no advantage for you if you use the i2c bus anyway to get the data. The embedded DMP firmware we inject into the MPU6050 has no available registers or way to use the magnetometer data! I have investigated this in-depth.
You could just as easily have the MPU6050 and the HMC8883L tied on the same i2c bus without any drawbacks. I would recommend moving the XCL wire to the SCL and the XDA wire to the SDA. the 2 4.7k resistors tied to the 3.3 supplies on the mpu6050 and the HMC8883L fall within the max current limits of the i2c connections. Also, this would eliminate you from having to change registers in the MPU6050 to pass the i2c communications through it.

If you wish to use this schematic


Quote
4.14 Register 55 - INT Pin / Bypass Enable Configuration INT_PIN_CFG
I2C_BYPASS_EN When this bit is equal to 1 and I2C_MST_EN (Register 106 bit[5]) is equal to 0, the host application processor will be able to directly access the auxiliary I 2C bus of the MPU-60X0. When this bit is equal to 0, the host application processor will not be able to directly access the auxiliary I2C bus of th
or you could ask the MPU6050 to get the data for you and store it.

Quote
4.8 Registers 37 to 39 - I 2C Slave 0 Control I2C_SLV0_ADDR, I2C_SLV0_REG, and I2C_SLV0_CTRL

I2C_SLV0,1,2,3 and I2C_SLV4 are used to send and receive data from the Secondary i2c bus. and store it in the


4.20 Registers 73 to 96 - External Sensor Data EXT_SENS_DATA_00 through EXT_SENS_DATA_23
Description: These registers store data read from external sensors by the Slave 0, 1, 2, and 3 on the auxiliary I2C interface. Data read by Slave 4 is stored in I2C_SLV4_DI (Register 53). External sensor data is written to these registers at the Sample Rate as defined in Register 25. This access rate can be reduced by using the Slave Delay Enable registers (Register 103). External sensor data registers, along with the gyroscope measurement registers, accelerometer measurement registers, and temperature measurement registers, are composed of two sets of registers: an internal register set and a user-facing read register set. The data within the external sensors' internal register set is always updated at the Sample Rate (or the reduced access rate) whenever the serial interface is idle. This guarantees that a burst read of sensor registers will read measurements from the same sampling instant. Note that if burst reads are not used, the user is responsible for ensuring a set of single byte reads correspond to a single sampling instant by checking the Data Ready interrupt. Data is placed in these external sensor data registers according to I2C_SLV0_CTRL, I2C_SLV1_CTRL, I2C_SLV2_CTRL, and I2C_SLV3_CTRL (Registers 39, 42, 45, and 48). When more than zero bytes are read (I2C_SLVx_LEN > 0) from an enabled slave (I2C_SLVx_EN = 1), the slave is read at the Sample Rate (as defined in Register 25) or delayed rate (if specified in Register 52 and 103). During each Sample cycle, slave reads are performed in order of Slave number. If all slaves are enabled with more than zero bytes to be read, the order will be Slave 0, followed by Slave 1, Slave 2, and Slave 3.
Z
HC

GolamMostafa

#6
Jan 19, 2020, 04:02 pm Last Edit: Jan 19, 2020, 04:04 pm by GolamMostafa
You are right. The 7-bit I2C address for HMC5883L sensor is: 0x1E (0x3C ---> 0011110(0) ---> 0011110 = 1E).


Go Up