mirror of
https://github.com/k3ng/k3ng_rotator_controller.git
synced 2025-01-28 15:13:53 +00:00
050aa62ab9
Added FEATURE_AZ_POSITION_MECHASOLUTION_QMC5883 - QMC5883 digital compass support using Mechasolution library at https://github.com/keepworking/Mecha_QMC5883L Modified MechaQMC5883.cpp to get rid of compiler warning about ::read
54 lines
1.2 KiB
C++
Executable File
54 lines
1.2 KiB
C++
Executable File
#include <Wire.h> //I2C Arduino Library
|
|
|
|
#define addr 0x0D //I2C Address for The HMC5883
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(9600);
|
|
Wire.begin();
|
|
|
|
|
|
Wire.beginTransmission(addr); //start talking
|
|
Wire.write(0x0B); // Tell the HMC5883 to Continuously Measure
|
|
Wire.write(0x01); // Set the Register
|
|
Wire.endTransmission();
|
|
Wire.beginTransmission(addr); //start talking
|
|
Wire.write(0x09); // Tell the HMC5883 to Continuously Measure
|
|
Wire.write(0x1D); // Set the Register
|
|
Wire.endTransmission();
|
|
}
|
|
|
|
void loop() {
|
|
|
|
int x, y, z; //triple axis data
|
|
|
|
//Tell the HMC what regist to begin writing data into
|
|
|
|
|
|
Wire.beginTransmission(addr);
|
|
Wire.write(0x00); //start with register 3.
|
|
Wire.endTransmission();
|
|
|
|
//Read the data.. 2 bytes for each axis.. 6 total bytes
|
|
Wire.requestFrom(addr, 6);
|
|
if (6 <= Wire.available()) {
|
|
x = Wire.read(); //MSB x
|
|
x |= Wire.read() << 8; //LSB x
|
|
z = Wire.read(); //MSB z
|
|
z |= Wire.read() << 8; //LSB z
|
|
y = Wire.read(); //MSB y
|
|
y |= Wire.read() << 8; //LSB y
|
|
}
|
|
|
|
// Show Values
|
|
Serial.print("X Value: ");
|
|
Serial.println(x);
|
|
Serial.print("Y Value: ");
|
|
Serial.println(y);
|
|
Serial.print("Z Value: ");
|
|
Serial.println(z);
|
|
Serial.println();
|
|
|
|
delay(500);
|
|
}
|