Wednesday, April 20, 2016

Triple-axis magnetometer - HMC5883L breakout Quickstart Guide

Short Description:
This Honeywell's HMC5883L, a breakout board for a 3-axis magnetometer. There are a wide range of uses magnetometers. The most common side affect of using a digital compass chip, or use them as a ferrous (magnetic) metal detection included.




Triple-axis magnetometer - HMC5883L breakout Quickstart Guide
Triple Axis Magnetometer Breakout - HMC5883L
Requirements:
This breakout board can be fitted to a number of microcontroller, as long as they have an i2c interface. However, following this guide you will find helpful:
  • arduino Uno
  • breadboard
  • Soldering iron
  • Solder
  • Male header or other connection methods
  • (Optional) needle nose pliers
  • (Optional) Third Hand
How it works:
Go hand-in-hand magnetic field and current. When current flows through a wire, a magnetic field is created. This is the basic principle behind electromagnetic. It is also used to measure the magnetic field with a magnetometer policy. The sensor in the direction of Earth's magnetic field affects the flow of electrons, and the change in the measurement and calculation of a compass heading, or other useful information can be extracted.

How to use it:
So if you use these chips with your Arduino is ready to start? Well, lucky for you, we have everything you need to get your project rolling.

Hardware:
First, we have some breakout boards solder on the header so it will fit into a breadboard. Welding for advice, this tutorial is helpful.

Breakout Board HMC5883 sensor and all filtering capacitors are required. Two unmanned pad in case you (you Arduino / ATmega328 is no need for them to use), pull-up resistors are required.

HMC5883 is easy to communicate with, and all done through a i2c interface. We will go into this in more detail momentarily. All you need to know for now is how the wire. A4 to A5 of the SDA and SCL lines connected to the line. 3.3V to Vcc and GND are also connected to GND. 
Triple Axis Magnetometer Breakout - HMC5883L
Triple Axis Magnetometer Breakout - HMC5883L
Software:
If you have not done so already, please download and install Arduino IDE.

Firmware:
The language speaks of a kind of funky HMC5883L serial i2c. A clock (SCL) for one and one for data (SDA) - i2c communication requires only two wires. You are probably aware that the two pins used for something else (except maybe another i2c device, you want to get cute) should be avoided. Do not try to use the analog input as they!
Triple Axis Magnetometer Breakout - HMC5883L
Triple Axis Magnetometer Breakout - HMC5883L
For example, we have the Arduino code, HMC5883.pde, continuous use i2c axis magnetometer to search for each of the data from the magnetometer. If you need help uploading your Arduino sketch is from, then there are plenty of helpful information on their sites.

Let's take a look at the first part of the code:
#include <Wire.h> //I2C Arduino Library
#define address 0x1E //0011110b, I2C 7bit address of HMC5883
void setup(){
  //Initialize Serial and I2C communications
  Serial.begin(9600);
  Wire.begin();
  
  //Put the HMC5883 IC into the correct operating mode
  Wire.beginTransmission(address); //open communication with HMC5883
  Wire.send(0x02); //select mode register
  Wire.send(0x00); //continuous measurement mode
  Wire.endTransmission();
}
Code that setup () function is run once in the beginning. It is the beginning of serial communication at 9600 baud. We use serial communication to send information back to the computer for each axis. I2c also is initialized. We then HMC5883L a "write" operation. The 'write' operation mode continuous operation objective is to adjust the value of the register configuration HMC5883L tell it. Our continuing to search for the information in this axis. By default, the single-chip once it is read from the read mode means that it will idle to save power. Once lazy, we can read it in writing before it is turned on again. In addition to the registration contains all the information about the datasheet and other useful information. Of course, we always encourage people to RTFM ... Just look at the datasheet ...

Moving on, here's where we request and receive data:
void loop(){
  
  int x,y,z; //triple axis data
  //Tell the HMC5883L where to begin reading data
  Wire.beginTransmission(address);
  Wire.send(0x03); //select register 3, X MSB register
  Wire.endTransmission();
  
 //Read data from each axis, 2 registers per axis
 
  Wire.requestFrom(address, 6);
  if(6<=Wire.available()){
    x = Wire.receive()<<8; //X msb
    x |= Wire.receive(); //X lsb
    z = Wire.receive()<<8; //Z msb
    z |= Wire.receive(); //Z lsb
    y = Wire.receive()<<8; //Y msb
    y |= Wire.receive(); //Y lsb
  }
  
  //Print out values of each axis
  Serial.print("x: ");
  Serial.print(x);
  Serial.print(" y: ");
  Serial.print(y);
  Serial.print(" z: ");
  Serial.println(z);
  
  delay(250);
}
Loop () function will run over and over again as long as the board has power. Every time, we have to write a quick read data for the axis where we want to start. 3. Registration will be selected and the X-axis is the most significant bytes. We're asked to read one after another 6 bytes. Automatic increase in the number of chips that we are reading from the book itself, so we have to register before each election, we will not fall from it. X, Y and Z axis data is then sent back to the computer in order. You Arduino development environment, as shown below: Serial Monitor can use this value.

Triple Axis Magnetometer Breakout - HMC5883L
Triple Axis Magnetometer Breakout - HMC5883L
All you need now to use this information in your next project will be a creative idea. Always feel free to share with us, it just might end up Sparkfun's homepage!
Resources:
  • Designed
  • HMC5883L datasheet
  • arduino code
  • Example C Code (ATmega328)
  • Digital compass How-To Videos
Conclusion:
Enjoy your new magnetometer! If you have any problems, feel free to contact technical support Take support@sparkfun.com SparkFun

No comments:

Post a Comment