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
I2C Compass GY-271
Moderator: Benj
- 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
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.
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.
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Re: I2C Compass GY-271
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?
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 406 times
Jeppe
Don't say oups!? Say Interesting!
Don't say oups!? Say Interesting!
- JohnCrow
- Valued Contributor
- Posts: 1367
- Joined: Wed Sep 19, 2007 1:21 pm
- Location: Lincolnshire
- Has thanked: 364 times
- Been thanked: 716 times
Re: I2C Compass GY-271
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
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 !
Re: I2C Compass GY-271
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
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!
Don't say oups!? Say Interesting!
Re: I2C Compass GY-271
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...
I would be pleased if anybody could give me a helping hand.
Tanks

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

I would be pleased if anybody could give me a helping hand.
Tanks
Jeppe
Don't say oups!? Say Interesting!
Don't say oups!? Say Interesting!
- 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
Re: I2C Compass GY-271
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.
BR,
Mantas
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.
BR,
Mantas
Science is my true religion.