Accessing the compass from the Arduino IDE

The first step in accessing the compass capability from the IDE is to install a library. Finding a library that supports the module is a bit difficult, but one that works well is available at www.emartee.com/product/42254/HMC5883L%203%20Axis%20Digital%20Compass%20Module.

The following are the steps to install the library and run the example:

  1. Select the Arduino Library for HMC5883L link on the previously mentioned page, and it will take you to a set of library selections.
  2. You need to select the HMC5883L / HMC5883L Library For Arduino.rar link at the bottom of this page, and it will download a .rar file that holds the library.
  3. Unzip this file into the libraries directory of your Arduino installation.
  4. Now, bring up the Arduino IDE and select the Examples option under the File menu, and you should be able to select the HMC5883L library example, as shown in the following screenshot:
    Accessing the compass from the Arduino IDE
  5. Once you have selected this example, upload it to your Arduino and open the Serial Monitor. You may have to resize the monitor to get a good look at the results, but you should see something similar to the following screenshot:
    Accessing the compass from the Arduino IDE

The Raw data is the x, y, and z data that is coming directly from the compass and is related directly to the earth's magnetic field. The Scaled values are those that are scaled to reflect true north. The Heading value is expressed in degrees and radians. Now, you can add direction to your project! As you move the device around, you should see the Heading value change. These readings should give you an indication of the heading of your project. This is very useful to help you give direction to your robotic projects. However, you may want to use even more information, such as speed and tilt. Fortunately, there are sensors for this as well.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.145.91.254