Page 1 of 1

I2C Compass GY-271

Posted: Tue Jun 04, 2013 8:43 am
by Odox00
I struggle with getting my compass module GY-271, based on HMC5883L work. This is my first attempt to communicate via I2C but without success.
Is there anyone here on the forum who has a working code for this module or know more than me how to code I2C?
I use the "40 pin ARM 7 ECIO", but if someone have code for PIC or any other MCU I think it could help me.
I would be very grateful for any help to solve this so I can continue my project with an autonomous sailboat.

Here is the data sheet for HMC5883L http://www51.honeywell.com/aero/common/ ... ass_IC.pdf

Thanks!

Jesper

Re: I2C Compass GY-271

Posted: Tue Jun 04, 2013 9:05 am
by Benj
Hello Jesper,

On page 18 of the datasheet is a guide to the interface.

To do the instructions for line 1 you would do this.

I2C Start
Send 0x3C - device address - write mode
Send 0x00 - internal address
Send 0x70
I2C Stop

Here is an example of line 5.

I2C Start
Send 0x36 - device address - read mode
Send 0x06 - internal address
Receive - data byte 0
Receive - data byte 1
Receive - data byte 2
....
Receive - data byte n
I2C Stop

Hope this helps.

Re: I2C Compass GY-271

Posted: Tue Jun 04, 2013 1:48 pm
by Odox00
Thanks for your info Ben.
I have tried to make a code of your recommendations but without success. Is the attached code anything near how an I2C communication should look like?

Re: I2C Compass GY-271

Posted: Tue Jun 04, 2013 6:22 pm
by JohnCrow
Hi Jesper

This is a compass flowchart I produced a while ago
Its not the same module as yours but it is stil I2C.
Hopefully it might give you some pointers

http://www.matrixmultimedia.com/mmforum ... t=+compass

Re: I2C Compass GY-271

Posted: Wed Jun 05, 2013 11:38 pm
by Odox00
Thanks John
Sorry but I did not get it to work. I changed the values I could think had any similarity between the two modules. But no... Maybe I have to buy the same module as yours. A bit more expensive but has the tilt compensation.

In Bens suggestion I'm not sure how to code the:

Receive - data byte 0
Receive - data byte 1
Receive - data byte 2


Jesper

Re: I2C Compass GY-271

Posted: Mon Jun 24, 2013 2:29 pm
by Odox00
Hi I'm still struggling with my compass... :(
Could someone give me a hint how to do the:

Receive - data byte 0
Receive - data byte 1
Receive - data byte 2

coding?

I looked at the examples of I2C but I was not any smarter... :oops:

I would be pleased if anybody could give me a helping hand.

Tanks

Re: I2C Compass GY-271

Posted: Wed Jul 10, 2013 7:32 pm
by Mantas
Hi,

One thing you should check is the pull-up resistors, that should be 47k as far as as I remember for communication speeds up to 400kHz. Otherwise system will not work.

Edit: also sometimes if you are not using external interrupts, you need to do polling for reading the data. I'm also attaching universal macros for i2c, so use macro import function to use them in your project. Also attaching MAG3110 3 axis magnetometer sensor which can also be used as compass coupled with 3 axis acc. Remember that the data you get from such sensors is 2's complement, and you need to convert it to integers to be able to use it properly.
master_read_i2c.fcm
(5.36 KiB) Downloaded 427 times
master_write_i2c.fcm
(3.74 KiB) Downloaded 397 times
mag3110_get_mag.fcm
(4.48 KiB) Downloaded 416 times

BR,
Mantas