GY-273/HMC5883L 3-Axis Digital Compass Module (HCMODU0036)

Modules for various types of sensors including accelerometers. gyro's, IR motion, etc
Post Reply
admin
Site Admin
Posts: 866
Joined: Sun Aug 05, 2012 4:02 pm

GY-273/HMC5883L 3-Axis Digital Compass Module (HCMODU0036)

Post by admin » Thu Oct 24, 2013 1:07 pm

[IMAGE TBA]

Description:

The GY-273 module is based on the Honeywell HMC5883L IC for low-field magnetic sensing with a digital interface for applications such as lowcost compassing and magnetometry. The HMC5883L includes state-of-theart, high-resolution HMC118X series magneto-resistive sensors plus an ASIC containing amplification, automatic degaussing strap drivers, offset cancellation,
and a 12-bit ADC that enables 1° to 2° compass heading accuracy. The I2C serial bus allows for easy interface.

You can purchase this module here.

The HMC5883L utilizes Honeywell’s Anisotropic Magnetoresistive (AMR) technology that provides advantages over other
magnetic sensor technologies. These anisotropic, directional sensors feature precision in-axis sensitivity and linearity.
These sensors’ solid-state construction with very low cross-axis sensitivity is designed to measure both the direction and
the magnitude of Earth’s magnetic fields, from milli-gauss to 8 gauss. Honeywell’s Magnetic Sensors are among the most
sensitive and reliable low-field sensors in the industry.


Specification:

HMC5883L module (three-axis magnetic field module)
Model: GY-273
IC: HMC5883L
Module Power supply : 3-5v
Communication: IIC communication protocol
Measuring range: ± 1.3-8 gauss
Size: 13.9 * 18.5


Example Arduino Sketch:

Code: Select all

/* FILE:    ARD_HMC5803L_GY273_Example
   DATE:    23/10/13
   VERSION: 0.1

This is an example of how to use the Hobby Components GY-273 module (HCMODU0036) which 
uses a Honeywell HMC5883L 3-Axis Digital Compass IC. The IC uses an I2C interface to 
communicate which is compatible with the standard Arduino Wire library.

This example demonstrates how to initialise and read the module in single shot 
measurement mode. It will continually trigger single measurements and output the 
results for the 3 axis to the serial port.


CONNECTIONS:

MODULE    ARDUINO
VCC       3.3V
GND       GND
SCL       A5
SDA       A4
DRDY      N/A


You may copy, alter and reuse this code in any way you like, but please leave
reference to HobbyComponents.com in your comments if you redistribute this code.
This software may not be used for the purpose of promoting or selling products 
that directly compete with Hobby Components Ltd's own range of products.

THIS SOFTWARE IS PROVIDED "AS IS". HOBBY COMPONENTS MAKES NO WARRANTIES, WHETHER
EXPRESS, IMPLIED OR STATUTORY, INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ACCURACY OR LACK OF NEGLIGENCE.
HOBBY COMPONENTS SHALL NOT, IN ANY CIRCUMSTANCES, BE LIABLE FOR ANY DAMAGES,
INCLUDING, BUT NOT LIMITED TO, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES FOR ANY
REASON WHATSOEVER. */

/* Include the standard Wire library */
#include <Wire.h>

/* The I2C address of the module */
#define HMC5803L_Address 0x1E

/* Register address for the X Y and Z data */
#define X 3
#define Y 7
#define Z 5

void setup() 
{
  Serial.begin(9600);
  /* Initialise the Wire library */
  Wire.begin();
  
  /* Initialise the module */ 
  Init_HMC5803L();
}

void loop() 
{
  /* Read each sensor axis data and output to the serial port */
  Serial.print(HMC5803L_Read(X));
  Serial.print(" ");
  Serial.print(HMC5803L_Read(Y));
  Serial.print(" ");
  Serial.println(HMC5803L_Read(Z));
  
  /* Wait a little before reading again */
  delay(200);
}


/* This function will initialise the module and only needs to be run once
   after the module is first powered up or reset */
void Init_HMC5803L(void)
{
  /* Set the module to 8x averaging and 15Hz measurement rate */
  Wire.beginTransmission(HMC5803L_Address);
  Wire.write(0x00);
  Wire.write(0x70);
          
  /* Set a gain of 5 */
  Wire.write(0x01);
  Wire.write(0xA0);
  Wire.endTransmission();
}


/* This function will read once from one of the 3 axis data registers
and return the 16 bit signed result. */
int HMC5803L_Read(byte Axis)
{
  int Result;
  
  /* Initiate a single measurement */
  Wire.beginTransmission(HMC5803L_Address);
  Wire.write(0x02);
  Wire.write(0x01);
  Wire.endTransmission();
  delay(6);
  
  /* Move modules the resiger pointer to one of the axis data registers */
  Wire.beginTransmission(HMC5803L_Address);
  Wire.write(Axis);
  Wire.endTransmission();
   
  /* Read the data from registers (there are two 8 bit registers for each axis) */  
  Wire.requestFrom(HMC5803L_Address, 2);
  Result = Wire.read() << 8;
  Result |= Wire.read();

  return Result;
}


FAQ:

Is it safe to connect this to the I2C pins on my 5V Arduino?

The I2C pins on the HMC5883L IC itself aren't 5V tolerant. However because of the way I2C works it's not the Arduino that drives the pins high. The module itself does this by pulling the pins high to 3.3V via two 4K7 Ohm resistor. So even on a 5V Arduino these pins shouldn't go above 3.3V.




Datasheet:
HMC5883L-FDS.pdf
You do not have the required permissions to view the files attached to this post.

Billduck
Posts: 1
Joined: Sun Jan 11, 2015 5:23 pm

Re: GY-273/HMC5883L 3-Axis Digital Compass Module (HCMODU00

Post by Billduck » Sun Jan 11, 2015 5:36 pm

Hello administrator. Thanks for posting this code. I am trying to x'fer this code to Flowcode ver 6 from Martix Multimedia. I'm not such a good Arduino code writer. Where would I find the content of wire.h?
Thanks in advance, Bill S

andrew
Site Admin
Posts: 1374
Joined: Sun Aug 05, 2012 4:15 pm

Re: GY-273/HMC5883L 3-Axis Digital Compass Module (HCMODU00

Post by andrew » Mon Jan 12, 2015 10:46 am

The wire library comes as part of the Arduino IDE. Just download the ziped version of the IDE the Arduino website (arduino.cc). Unzip it to your C: drive and you will find it in the following path: C:\arduino\libraries\WireWire.h
Comments made by this poster do not necessarily reflect the views of Hobby Components Ltd.

Post Reply

Return to “Sensors”