I2C Compass GY-271

For Flowcode users to discuss projects, flowcharts, and any other issues related to Flowcode 4.
To post in this forum you must have a registered copy of Flowcode 4 or higher. To sign up for this forum topic please use the "Online Resources" link in the Flowcode Help Menu.

Moderator: Benj

Post Reply
Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am
Contact:

I2C Compass GY-271

Post 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
Jeppe
Don't say oups!? Say Interesting!

User avatar
Benj
Matrix Staff
Posts: 15312
Joined: Mon Oct 16, 2006 10:48 am
Location: Matrix TS Ltd
Has thanked: 4803 times
Been thanked: 4314 times
Contact:

Re: I2C Compass GY-271

Post 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.

Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am
Contact:

Re: I2C Compass GY-271

Post 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?
Attachments
I2Ctest.fcf_arm
(11 KiB) Downloaded 395 times
Jeppe
Don't say oups!? Say Interesting!

User avatar
JohnCrow
Valued Contributor
Valued Contributor
Posts: 1367
Joined: Wed Sep 19, 2007 1:21 pm
Location: Lincolnshire
Has thanked: 364 times
Been thanked: 716 times
Contact:

Re: I2C Compass GY-271

Post 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
1 in 10 people understand binary, the other one doesn't !

Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am
Contact:

Re: I2C Compass GY-271

Post 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
Jeppe
Don't say oups!? Say Interesting!

Odox00
Flowcode v5 User
Posts: 24
Joined: Thu Aug 25, 2011 11:15 am
Contact:

Re: I2C Compass GY-271

Post 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
Jeppe
Don't say oups!? Say Interesting!

User avatar
Mantas
Posts: 221
Joined: Tue May 15, 2012 10:32 pm
Location: Klaipeda, Lithuania - North sea, UK
Has thanked: 57 times
Been thanked: 27 times
Contact:

Re: I2C Compass GY-271

Post 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 424 times
master_write_i2c.fcm
(3.74 KiB) Downloaded 395 times
mag3110_get_mag.fcm
(4.48 KiB) Downloaded 411 times

BR,
Mantas
Science is my true religion.

Post Reply