Program takes the raw data from the HMC5883L digital compass sensor and calculates the heading angle. Writes the heading angle to the terminal every 1 second.

Dependencies:   HMC5883L ledControl2 mbed

Committer:
BaserK
Date:
Wed Aug 05 13:02:08 2015 +0000
Revision:
0:86feb6f44eae
Program takes the raw data from the HMC5883L digital compass sensor and calculates the heading angle. Writes the heading angle to the terminal every 1 second

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:86feb6f44eae 1 /* Calculating Heading (Yaw Angle) from HMC5883L
BaserK 0:86feb6f44eae 2 *
BaserK 0:86feb6f44eae 3 * @author: Baser Kandehir
BaserK 0:86feb6f44eae 4 * @date: August 5, 2015
BaserK 0:86feb6f44eae 5 * @license: MIT license
BaserK 0:86feb6f44eae 6 *
BaserK 0:86feb6f44eae 7 * Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr
BaserK 0:86feb6f44eae 8 *
BaserK 0:86feb6f44eae 9 * Permission is hereby granted, free of charge, to any person obtaining a copy
BaserK 0:86feb6f44eae 10 * of this software and associated documentation files (the "Software"), to deal
BaserK 0:86feb6f44eae 11 * in the Software without restriction, including without limitation the rights
BaserK 0:86feb6f44eae 12 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
BaserK 0:86feb6f44eae 13 * copies of the Software, and to permit persons to whom the Software is
BaserK 0:86feb6f44eae 14 * furnished to do so, subject to the following conditions:
BaserK 0:86feb6f44eae 15 *
BaserK 0:86feb6f44eae 16 * The above copyright notice and this permission notice shall be included in
BaserK 0:86feb6f44eae 17 * all copies or substantial portions of the Software.
BaserK 0:86feb6f44eae 18 *
BaserK 0:86feb6f44eae 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
BaserK 0:86feb6f44eae 20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
BaserK 0:86feb6f44eae 21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
BaserK 0:86feb6f44eae 22 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
BaserK 0:86feb6f44eae 23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
BaserK 0:86feb6f44eae 24 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
BaserK 0:86feb6f44eae 25 * THE SOFTWARE.
BaserK 0:86feb6f44eae 26 *
BaserK 0:86feb6f44eae 27 * @description of the program: Program takes the raw data from the HMC5883L
BaserK 0:86feb6f44eae 28 * digital compass sensor and calculates the heading angle. Writes the heading
BaserK 0:86feb6f44eae 29 * angle to the terminal every 1 second.
BaserK 0:86feb6f44eae 30 *
BaserK 0:86feb6f44eae 31 * @connections:
BaserK 0:86feb6f44eae 32 *--------------------------------------------------------------
BaserK 0:86feb6f44eae 33 * |LPC1768| |Peripherals|
BaserK 0:86feb6f44eae 34 * Pin 9 ---------> SDA of HMC5883L
BaserK 0:86feb6f44eae 35 * Pin 10 --------> SCL of HMC5883L
BaserK 0:86feb6f44eae 36 * GND -----------> GND of HMC5883L
BaserK 0:86feb6f44eae 37 * VOUT (3.3 V) --> VCC of HMC5883L
BaserK 0:86feb6f44eae 38 *---------------------------------------------------------------
BaserK 0:86feb6f44eae 39 *--------------------------------------------------------------
BaserK 0:86feb6f44eae 40 * |NUCLEO F411RE| |Peripherals|
BaserK 0:86feb6f44eae 41 * D14 -----------> SDA of HMC5883L
BaserK 0:86feb6f44eae 42 * D15 -----------> SCL of HMC5883L
BaserK 0:86feb6f44eae 43 * GND -----------> GND of HMC5883L
BaserK 0:86feb6f44eae 44 * VOUT (3.3 V) --> VCC of HMC5883L
BaserK 0:86feb6f44eae 45 *---------------------------------------------------------------
BaserK 0:86feb6f44eae 46 *
BaserK 0:86feb6f44eae 47 */
BaserK 0:86feb6f44eae 48
BaserK 0:86feb6f44eae 49 #include "mbed.h"
BaserK 0:86feb6f44eae 50 #include "HMC5883L.h"
BaserK 0:86feb6f44eae 51 #include "ledControl.h"
BaserK 0:86feb6f44eae 52
BaserK 0:86feb6f44eae 53 Serial pc(USBTX,USBRX); // default baud rate: 9600
BaserK 0:86feb6f44eae 54 HMC5883L hmc5883l;
BaserK 0:86feb6f44eae 55
BaserK 0:86feb6f44eae 56 double Heading;
BaserK 0:86feb6f44eae 57
BaserK 0:86feb6f44eae 58 int main(void)
BaserK 0:86feb6f44eae 59 {
BaserK 0:86feb6f44eae 60 hmc5883l.init();
BaserK 0:86feb6f44eae 61 while(1)
BaserK 0:86feb6f44eae 62 {
BaserK 0:86feb6f44eae 63 Heading = hmc5883l.getHeading();
BaserK 0:86feb6f44eae 64
BaserK 0:86feb6f44eae 65 pc.printf(" _______________\r\n");
BaserK 0:86feb6f44eae 66 pc.printf("| Heading: %.1f \r\n", Heading);
BaserK 0:86feb6f44eae 67 pc.printf("|_______________\r\n\r\n");
BaserK 0:86feb6f44eae 68
BaserK 0:86feb6f44eae 69 wait(1);
BaserK 0:86feb6f44eae 70 }
BaserK 0:86feb6f44eae 71 }