프로그램&회로

QMC5883 지자기센서

엠칩 2019. 1. 16. 15:48
반응형

Mechasolution QMC5883L Library

QMC5883L 3축 지자계/컴파스 센서 (QMC5883L 3 Axis Compass Sensor)

센서야 인터넷 검색해서 아무데나 쉽게 구매 가능하고...




https://github.com/mechasolution/Mecha_QMC5883L


한글설명링크

https://goo.gl/trBEr5



======================================================================

라이브러리가 필요 없는 코드


#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);

}


===============================================================================




반응형

'프로그램&회로' 카테고리의 다른 글

STM32 UART  (0) 2019.09.23
Terminal V1.9b 2013  (1) 2019.09.06
라즈베리파이 전원버튼 추가.  (0) 2018.12.17
라즈베리파이 네트워크 설정  (0) 2018.12.14
리눅스 콘솔 단축키 및 명령어  (2) 2018.12.14