Library for the HMC5883L with 5 pins

Dependents:   projet_st_connect

Fork of QMC5883L by z jx

Committer:
sarahbest
Date:
Wed Jul 19 07:58:23 2017 +0000
Revision:
3:6aac221b613d
Parent:
HMC5883L.h@1:4c295f793d46
Child:
4:2620ae5391a6
qmc5883 output 4 variables: mag 3,temp.; the temperature is negative, which has something wrong

Who changed what in which revision?

UserRevisionLine numberNew contents of line
BaserK 0:e5f8da308b60 1 /*
BaserK 0:e5f8da308b60 2 * Copyright (c) 2015, Baser Kandehir, baser.kandehir@ieee.metu.edu.tr
BaserK 0:e5f8da308b60 3 *
BaserK 0:e5f8da308b60 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
BaserK 0:e5f8da308b60 5 * of this software and associated documentation files (the "Software"), to deal
BaserK 0:e5f8da308b60 6 * in the Software without restriction, including without limitation the rights
BaserK 0:e5f8da308b60 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
BaserK 0:e5f8da308b60 8 * copies of the Software, and to permit persons to whom the Software is
BaserK 0:e5f8da308b60 9 * furnished to do so, subject to the following conditions:
BaserK 0:e5f8da308b60 10 *
BaserK 0:e5f8da308b60 11 * The above copyright notice and this permission notice shall be included in
BaserK 0:e5f8da308b60 12 * all copies or substantial portions of the Software.
BaserK 0:e5f8da308b60 13 *
BaserK 0:e5f8da308b60 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
BaserK 0:e5f8da308b60 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
BaserK 0:e5f8da308b60 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
BaserK 0:e5f8da308b60 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
BaserK 0:e5f8da308b60 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
BaserK 0:e5f8da308b60 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
BaserK 0:e5f8da308b60 20 * THE SOFTWARE.
BaserK 0:e5f8da308b60 21 *
BaserK 0:e5f8da308b60 22 */
BaserK 0:e5f8da308b60 23
BaserK 0:e5f8da308b60 24 // Some part of the code is adapted from Adafruit HMC5883 library
BaserK 0:e5f8da308b60 25
sarahbest 3:6aac221b613d 26 #ifndef QMC5883L_H
sarahbest 3:6aac221b613d 27 #define QMC5883L_H
BaserK 0:e5f8da308b60 28
BaserK 0:e5f8da308b60 29 #include "mbed.h"
BaserK 0:e5f8da308b60 30 #include "math.h"
BaserK 0:e5f8da308b60 31 #include "ledControl.h"
BaserK 0:e5f8da308b60 32
BaserK 0:e5f8da308b60 33 #define PI 3.14159265359
BaserK 0:e5f8da308b60 34 #define GAUSS_TO_MICROTESLA 100
sarahbest 3:6aac221b613d 35 #define QMC5883L_ADDRESS 0x1A//0x18//
BaserK 0:e5f8da308b60 36
BaserK 0:e5f8da308b60 37 /* Register Definitions */
sarahbest 3:6aac221b613d 38 #define OUT_X_LSB 0x00
sarahbest 3:6aac221b613d 39 #define OUT_X_MSB 0x01
sarahbest 3:6aac221b613d 40 #define OUT_Y_LSB 0x02
sarahbest 3:6aac221b613d 41 #define OUT_Y_MSB 0x03
sarahbest 3:6aac221b613d 42 #define OUT_Z_LSB 0x04
BaserK 0:e5f8da308b60 43 #define OUT_Z_MSB 0x05
sarahbest 3:6aac221b613d 44 #define STATUS 0x06
sarahbest 3:6aac221b613d 45 #define TEMP_LSB 0x07
sarahbest 3:6aac221b613d 46 #define TEMP_MSB 0x08
sarahbest 3:6aac221b613d 47 #define CONTROL_A 0x09
sarahbest 3:6aac221b613d 48 #define CONTROL_B 0x0A
sarahbest 3:6aac221b613d 49 #define SET_RESET 0x0B
sarahbest 3:6aac221b613d 50 #define CHIP_ID 0x0D
BaserK 0:e5f8da308b60 51
sarahbest 3:6aac221b613d 52 extern float mRes;
BaserK 0:e5f8da308b60 53 /* Magnetometer Gain Settings */
sarahbest 3:6aac221b613d 54 enum MagScale
BaserK 0:e5f8da308b60 55 {
sarahbest 3:6aac221b613d 56 MagScale_2G = 0x00, // +/- 2 Ga
sarahbest 3:6aac221b613d 57 MagScale_8G = 0x10, // +/- 8 Ga
BaserK 0:e5f8da308b60 58 };
BaserK 0:e5f8da308b60 59
sarahbest 3:6aac221b613d 60 class QMC5883L
BaserK 0:e5f8da308b60 61 {
BaserK 0:e5f8da308b60 62 public:
sarahbest 3:6aac221b613d 63 void init();
sarahbest 3:6aac221b613d 64 double getHeading();
sarahbest 3:6aac221b613d 65 void readMagData(float* dest);
sarahbest 3:6aac221b613d 66 int16_t getMagXvalue();
sarahbest 3:6aac221b613d 67 int16_t getMagYvalue();
sarahbest 3:6aac221b613d 68 int16_t getMagZvalue();
sarahbest 3:6aac221b613d 69 int16_t getMagTemp();
sarahbest 3:6aac221b613d 70 void ChipID();
BaserK 0:e5f8da308b60 71 private:
sarahbest 3:6aac221b613d 72 float setMagRange(MagScale Mscale);
sarahbest 3:6aac221b613d 73 // uint8_t QMC5883L_ReadByte(uint8_t QMC5883L_reg);
sarahbest 3:6aac221b613d 74 // void QMC5883L_WriteByte(uint8_t QMC5883L_reg, uint8_t QMC5883L_data);
sarahbest 3:6aac221b613d 75 // void readBytes(uint8_t address, uint8_t regAddress, uint8_t byteNum, uint8_t* dest);
BaserK 0:e5f8da308b60 76 };
BaserK 0:e5f8da308b60 77
sarahbest 3:6aac221b613d 78 #endif
sarahbest 3:6aac221b613d 79
sarahbest 3:6aac221b613d 80 extern Serial pc;