arduino上使用QMC输出
通过IIC输出三轴磁力原始数据
通过MechaQMC5883库输出yaw角
我找了不少关于QMC磁力计的文章,发现不管是商家给的程序还是博客的其他文章,都是基于stm32的,而QMC在arduino上的应用却没多少,于是就一边看着数据文档,一边在arduino上实现QMC。
这里用的是arduino nano,
引脚连接:
nano -> QMC
5V -> VCC
A5 -> SCL
A4 -> SDA
GND -> GND
首先在例程中找到I2C_scanner,打开,连接QMC,上传。
如果没有这个例程,这里给出:
// --------------------------------------
// i2c_scanner
//
// Version 1
// This program (or code that looks like it)
// can be found in many places.
// For example on the Arduino.cc forum.
// The original author is not know.
// Version 2, Juni 2012, Using Arduino 1.0.1
// Adapted to be as simple as possible by Arduino.cc user Krodal
// Version 3, Feb 26 2013
// V3 by louarnold
// Version 4, March 3, 2013, Using Arduino 1.0.3
// by Arduino.cc user Krodal.
// Changes by louarnold removed.
// Scanning addresses changed from 0...127 to 1...119,
// according to the i2c scanner by Nick Gammon
// https://www.gammon.com.au/forum/?id=10896
// Version 5, March 28, 2013
// As version 4, but address scans now to 127.
// A sensor seems to use address 120.
// Version 6, November 27, 2015.
// Added waiting for the Leonardo serial communication.
//
//
// This sketch tests the standard 7-bit addresses
// Devices with higher bit address might not be seen properly.
//
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
while (!Serial); // Leonardo: wait for serial monitor
Serial.println("\nI2C Scanner");
}
void loop() {
int nDevices = 0;
Serial.println("Scanning...");
for (byte address = 1