资源简介
本来买了一个HMC5883结果是QMC5883,这俩用法完全不同,把坑填上之后分享给其他用了qmc5883的朋友
代码片段和文件信息
/*
HMC5883L.cpp - Class file for the HMC5883L Triple Axis Digital Compass Arduino Library.
Version: 1.1.0
(c) 2014 Korneliusz Jarzebski
www.jarzebski.pl
This program is free software: you can redistribute it and/or modify
it under the terms of the version 3 GNU General Public License as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not see .
*/
#if ARDUINO >= 100
#include “Arduino.h“
#else
#include “WProgram.h“
#endif
#include
#include “HMC5883L.h“
bool HMC5883L::begin()
{
Wire.begin();
if ((fastRegister8(HMC5883L_REG_IDENT_A) != 0x48)
|| (fastRegister8(HMC5883L_REG_IDENT_B) != 0x34)
|| (fastRegister8(HMC5883L_REG_IDENT_C) != 0x33))
{
return false;
}
setRange(HMC5883L_RANGE_1_3GA);
setMeasurementMode(HMC5883L_CONTINOUS);
setDataRate(HMC5883L_DATARATE_15HZ);
setSamples(HMC5883L_SAMPLES_1);
mgPerDigit = 0.92f;
return true;
}
Vector HMC5883L::readRaw(void)
{
v.XAxis = readRegister16(HMC5883L_REG_OUT_X_M) - xOffset;
v.YAxis = readRegister16(HMC5883L_REG_OUT_Y_M) - yOffset;
v.ZAxis = readRegister16(HMC5883L_REG_OUT_Z_M);
return v;
}
Vector HMC5883L::readNormalize(void)
{
v.XAxis = ((float)readRegister16(HMC5883L_REG_OUT_X_M) - xOffset) * mgPerDigit;
v.YAxis = ((float)readRegister16(HMC5883L_REG_OUT_Y_M) - yOffset) * mgPerDigit;
v.ZAxis = (float)readRegister16(HMC5883L_REG_OUT_Z_M) * mgPerDigit;
return v;
}
void HMC5883L::setOffset(int xo int yo)
{
xOffset = xo;
yOffset = yo;
}
void HMC5883L::setRange(hmc5883l_range_t range)
{
switch(range)
{
case HMC5883L_RANGE_0_88GA:
mgPerDigit = 0.073f;
break;
case HMC5883L_RANGE_1_3GA:
mgPerDigit = 0.92f;
break;
case HMC5883L_RANGE_1_9GA:
mgPerDigit = 1.22f;
break;
case HMC5883L_RANGE_2_5GA:
mgPerDigit = 1.52f;
break;
case HMC5883L_RANGE_4GA:
mgPerDigit = 2.27f;
break;
case HMC5883L_RANGE_4_7GA:
mgPerDigit = 2.56f;
break;
case HMC5883L_RANGE_5_6GA:
mgPerDigit = 3.03f;
break;
case HMC5883L_RANGE_8_1GA:
mgPerDigit = 4.35f;
break;
default:
break;
}
writeRegister8(HMC5883L_REG_CONFIG_B range << 5);
}
hmc5883l_range_t HMC5883L::getRange(void)
{
return (hmc5883l_range_t)((readRegister8(HMC5883L_REG_CONFIG_B) >> 5));
}
void HMC5883L::setMeasurementMode(hmc5883l_mode_t mode)
{
uint8_t value;
value = readRegister8(HMC5883L_REG_MODE);
value &= 0b11111100;
value |= mode;
writeRegister8(HMC5883L_REG_MODE value);
}
hmc5883l_mode_t HMC5883L::getMeasurementMode(void)
{
uint8_t value;
value = readRegister8(HM
- 上一篇:李庆扬数值分析第五版课件
- 下一篇:仿今日头条视频显示效果
相关资源
- OLED-STM32F4-IIC
- MCP2515驱动-STM32-keil project
- 基于STM32一氧化碳无线报警报器
- stm32红外遥控和定时闹钟显示程序
- AD7192-STM32.rar
- 串口记录仪
- stm32f103的4字节转float和float转4字节代
- 基于MQ2烟雾传感器的STM32F103程序
- BH1750(GY30)光照传感器STM32代码
- 基于407写的VL53l0X程序
- STM32L151串口、IO输入、输出例程
- HX711-stm32f407
- STM32使用uip协议栈实现TCP数据传输源码
- 基于stm32智能壁障小车程序源码+原理
- 风力摆控制系统stm32源码+ad原理图20
- SPI版0.96寸OLED显示屏资料(SSD1306)
- STM32内部DAC(PA4)输出
- 基于STM32CubeIDE的光栅尺测试程序
- stm32F103ZET6 PCB+原理图
- STM32F103C8T6外部中断.rar
- 基于stm32f103zet6的0.96寸的OLED显示屏源
- stm32 modbus代码
- ds3231时钟stm32文件包
- stm32下通过fsmc驱动fpga通讯的例程
- stm32f4 ad波形采集用da接示波器
- STM32 超声波测距例程
- stm32+MLX90614测温代码.rar
- STM32实现GPRS与服务器数据传输 相关源
- stm32超声波读取数据串口输出数据
- LDC1000 STM32
评论
共有 条评论