ÀÌ ¸Å´º¾óÀº ÁÖ½Äȸ»ç Á¦ÀÌÄÉÀÌÀÌ¿¥¾¾(JK EMC) ¿¡ ÀÇÇؼ­ ¹ø¿ª, ¼öÁ¤, ÀÛ¼º µÇ¾ú°í ¼ÒÀ¯±Ç ¶ÇÇÑ
ÁÖ ½Äȸ»ç Á¦ÀÌÄÉÀÌÀÌ¿¥¾¾(JK EMC)ÀÇ °ÍÀÔ´Ï´Ù. ¼ÒÀ¯±ÇÀÚÀÇ Çã°¡¸¦ ¹ÞÁö ¾Ê°í ¹«´ÜÀ¸·Î ¼öÁ¤, »èÁ¦Çϰųª ¹èÆ÷ ÇÒ ¼ö ¾ø½À´Ï´Ù.

 

 

HMC5883L Geomagnetic ÁöÀÚ±â GY-271 3.3/5V ·¹±Ö·¹ÀÌÅÍ ³»ÀåÇü ¼¾¼­ ¸Þ´º¾ó


  * Update history

- 2016.8.3 : ÇÁ·Î¼¼½Ì ÄÚµå Ãß°¡
- 2016.7.15 : Ãʱâ Release


 
1. HMC5883L ¼¾¼­ ¼Ò°³
2. ¾Æ µÎÀ̳ë¿Í °°ÀÌ »ç¿ëÇϱâ
    2.1 ¼¾¼­ ȸ·Îµµ¹× ¿Ü°û Ä¡¼ö
    2.2 ¾ÆµÎÀ̳ë UNO R3 ¹è¼±µµ
    2.3 ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ ÄÚµå
3. ÇÁ·Î¼¼½ÌÀ» ÀÌ¿ëÇؼ­ 3Â÷¿ø ±×·¡ÇÈ Ç¥½Ã
    3.1 ÇÁ·Î¼¼½Ì ¼³Ä¡ Çϱâ
    3.2 ¾ÆµÎÀ̳ë UNO R3 ¹è¼±µµ
    3.3 ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ ÄÚµå
    3.4 ÇÁ·Î¼¼½Ì ÄÚµå



 

1. HMC5883L ¼¾¼­ ¼Ò°³

HMC5883LÀº Àú°¡ÀÇ ³ªÄ§¹Ý°ú ÀÚ±â·Â ÃøÁ¤°°Àº ³·Àº ÇʵåÀÇ ¸¶±×³×ƽ °¨Áö¸¦ À§ÇÑ ¼¾¼­ÀÌ´Ù. ÀÚ±âÀå¼¾¼­¸¦ ÀÌ¿ëÇÏ¿© ³ªÄ§¹Ýó·³ ¹æÀ§¸¦ ¾Ë ¼ö ÀÖ´Ù. I2C (Inter Integrated Circuit) Åë½Å ÇÁ·ÎÅäÄÝÀ» ÅëÇؼ­ µ¥ÀÌÅ͸¦ ÃßÃâ ÇÒ ¼ö ÀÖ´Ù.

2. ¾ÆµÎÀ̳ë¿Í °°ÀÌ »ç¿ëÇϱâ

2.1 ¼¾¼­ ȸ·Îµµ¹× ¿Ü°û Ä¡¼ö

(1) HMC5883L ¼¾¼­ ȸ·Îµµ
     - HMC5883L PDF ȸ·Îµµ ´Ù¿î·Îµå
     - HMC5883L µ¥ÀÌÅͽÃÆ® ´Ù¿î·Îµå(http://www.jkelec.co.kr)
     - HMC5883L DXF ijµå ÆÄÀÏ ´Ù¿î·Îµå

mpu9250

(2) HMC5883L ¼¾¼­ ¿Ü°û(mm´ÜÀ§) Ä¡¼ö

      atmega128

2.2 ¾ÆµÎÀ̳ë UNO R3 ¹è¼±µµ

(1) ¾ÆµÎÀ̳ë UNO R3¿Í ¿¬°áÇؼ­ °¡¼Óµµ, ÀÚÀÌ·Î ¼¾ÅÍ µ¥ÀÌÅÍ Ãâ·Â Çϱâ
      ¾ÆµÎÀ̳ëÀÇ A5¸¦ ¼¾¼­ÀÇ SCL, A4¸¦ ¼¾¼­ÀÇ SDAÇÉ¿¡ ¿¬°áÀ» ÇÏ¸é µÈ´Ù. º» Á¦Ç°Àº ³»ºÎ¿¡ ȸ·ÎÀûÀ¸·Î 3.3VÀü¿ø ·¹µâ·¹ÀÌÅÍ¿Í I2C ·¹º§½¬ÇÁÅ͸¦ ³»ÀåÇÏ°í À־ 5.0V¿Í 3.3V ¿¡¼­ ¸ðµÎ »ç¿ëÀÌ °¡´É ÇÏ´Ù. STM32, ¶óÁ¸®ÆÄÀÌ µî°ú °°ÀÌ 3.3V Àü¿øÀ» »ç¿ëÇÏ´Â ÇÁ·Î¼¼¼­¿¡¼­ »ç¿ëÇÒ °æ¿ì¿¡´Â VCC ´ë½Å¿¡ 3.3V ÇÉÀ» ÅëÇؼ­ Àü¿øÀ» ¹Ù·Î ¿¬°áÇØ ÁÖ¸é µÈ´Ù.


     - Fritzing ÆÄÀÏ ´Ù¿î·Îµå

mpu9250

 



2.3 ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ ÄÚµå

´Ü¼øÈ÷ ¼¾¼­ÀÇ µ¥ÀÌÅ͸¦ ½Ã¸®¾ó µ¥ÀÌÅÍ·Î Ãâ·ÂÇÏ´Â ¿¹Á¦ ÀÌ´Ù.

(1) ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ ÄÚµå
     - HMC5883L raw µ¥ÀÌÅÍ Ç¥½Ã ½ºÄ³Ä¡ ÆÄÀÏ ´Ù¿î·Îµå

// I2C device class (I2Cdev) demonstration Arduino sketch for HMC5883L class
// 10/7/2011 by Jeff Rowberg <jeff@rowberg.net>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2013-05-04 - Added Heading Calculation in degrees
// 2011-10-07 - initial release
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
// Arduino Wire library is required if I2Cdev I2CDEV_ARDUINO_WIRE implementation
// is used in I2Cdev.h
#include "Wire.h"
// I2Cdev and HMC5883L must be installed as libraries, or else the .cpp/.h files
// for both classes must be in the include path of your project
#include "I2Cdev.h"
#include "HMC5883L.h"
// class default I2C address is 0x1E
// specific I2C addresses may be passed as a parameter here
// this device only supports one I2C address (0x1E)
HMC5883L mag;
int16_t mx, my, mz;
#define LED_PIN 13
bool blinkState = false;
void setup() {
// join I2C bus (I2Cdev library doesn't do this automatically)
Wire.begin();
// initialize serial communication
// (38400 chosen because it works as well at 8MHz as it does at 16MHz, but
// it's really up to you depending on your project)
Serial.begin(9600);
// initialize device
Serial.println("Initializing I2C devices...");
mag.initialize();
// verify connection
Serial.println("Testing device connections...");
Serial.println(mag.testConnection() ? "HMC5883L connection successful" : "HMC5883L connection failed");
// configure Arduino LED for
pinMode(LED_PIN, OUTPUT);
}
void loop() {
// read raw heading measurements from device
mag.getHeading(&mx, &my, &mz);
// display tab-separated gyro x/y/z values
Serial.print("mag:\t");
Serial.print(mx); Serial.print("\t");
Serial.print(my); Serial.print("\t");
Serial.print(mz); Serial.print("\t");
// To calculate heading in degrees. 0 degree indicates North
float heading = atan2(my, mx);
if(heading < 0)
heading += 2 * M_PI;
Serial.print("heading:\t");
Serial.println(heading * 180/M_PI);
// blink LED to indicate activity
blinkState = !blinkState;
digitalWrite(LED_PIN, blinkState);
}

HMC5883LÀÇ Slave Address´Â 0x1E 1°³ÀÇ ¾îµå·¹½º¸¸ °¡Áö°í ÀÖ´Ù.

#define HMC5883L_ADDRESS 0x1E

(2) ½ÇÇà °á°ú 
HMC5883L°úÀÇ I2C Åë½Å »óŸ¦ °Ë»çÇÏ°í 3ÃàÀÇ ÁöÀڱ⠰ªÀ» ¹Ýº¹Çؼ­ º¸¿©ÁØ´Ù.

mpu9250

º» ¸Þ´º¾óÀÇ ¾ÆµÎÀ̳ë ÄÚµå´Â ¾Æ·¡ https://github.com/jrowberg/i2cdevlib ÀÇ ³»¿ëÀ» ÂüÁ¶ÇÏ¿© ÀÛ¼º ÇÏ¿´´Ù.

3. ÇÁ·Î¼¼½ÌÀ» ÀÌ¿ëÇؼ­ 3Â÷¿ø ±×·¡ÇÈ Ç¥½Ã

3.1 ÇÁ·Î¼¼½Ì ¼³Ä¡ Çϱâ

¾ÆµÎÀ̳븦 ÀÌ¿ëÇؼ­ ¼¾¼­¿¡¼­ µ¥ÀÌÅ͸¦ ÃßÃâÇؼ­ ½Ã¸®¾ó µ¥ÀÌÅÍ·Î Ãâ·ÂÀ» Çؼ­ µ¥ÀÌÅÍ °ªÀ» È®ÀÎÀ» ½±°Ô ÇÒ ¼ö ÀÖ¾ú´Ù. ±×·¸´Ù¸é ÅؽºÆ® µ¥ÀÌÅÍ°¡ ¾Æ´Ï¶ó Á¶±Ý´õ ½Ã°¢ÀûÀΠǥÇö ¹æ¹ýÀÌ ¾øÀ»±î? ±×°Íµµ ¾ÆÁÖ ½±°Ô.. 
ÇÁ·Î¼¼½ÌÀ» ÀÌ¿ëÇÏ¸é ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ Äڵ带 ÀÔ·ÂÇϵíÀÌ ¾ÆÁÖ ½±°Ô ½Ã°¢ÀûÀΠǥÇöÀÌ °¡´ÉÇÏ´Ù. ¿ì¼± ÇÁ·Î¼¼½Ì °³¹ß ȯ°æÀ» ¼³Ä¡Çϴ°ͺÎÅÍ Çغ¸ÀÚ.

(1) ÇÁ·Î¼¼½Ì ¼³Ä¡
      - ÇÁ·Î¼¼½Ì °³¹ßȯ°æ ¼³Ä¡ Çϱâ(»õâ)
ÇÁ·Î¼¼½ÌÄÚµå´Â HMC5883L ¸ðµâ¿¡¼­ Ãâ·ÂÇÏ´Â µ¥ÀÌÅ͸¦ ½Ã¸®¾ó(RS232) Åë½ÅÀ» ÅëÇؼ­ ÀÔ·ÂÀ» ¹Þ¾Æ µ¥ÀÌÅ͸¦ ó¸® Çϵµ·Ï µÇ¾î ÀÖ´Ù. ÀÌÁ¦ ¾ÆµÎÀ̳ë¿Í HMC5883L ¸ðµâÀ» ÀÌ¿ëÇؼ­ ÇÁ·Î¼¼½Ì¿¡¼­ ó¸® Çϱâ À§ÇÑ µ¥ÀÌÅÍ Ãâ·ÂÀ» Çغ¸ÀÚ.

3.2 ¾ÆµÎÀ̳ë UNO R3 ¹è¼±µµ

¹è¼±µµ´Â ÀÌÀü ¿¹Á¦¿Í µ¿ÀÏÇÏ´Ù.

mpu6050

3.3 ¾ÆµÎÀÌ³ë ½ºÄÉÄ¡ ÄÚµå

(1) ¾ÆµÎÀ̳ë ÇÁ·Î¼¼½Ì ÄÚµå
ÇÁ·Î¼¼½Ì Äڵ忡¼­ ÇÑ°¡Áö ÁÖÀÇ ÇؾßÇÒ »çÇ×Àº ó¸® ¼Óµµ¸¦ ºü¸£°Ô Çϱâ À§Çؼ­ ½Ã¸®Åë Åë½ÅÀÇ ¼Óµµ¸¦ 115200bps ·Î ¼³Á¤À» ÇÏ¿´´Ù. ±×·¸±â ¶§¹®¿¡ ¾ÆµÎÀ̳ëÀÇ ½Ã¸®¾ó ¸ð´ÏÅÍâ¿¡¼­µµ µ¿ÀÏÇÑ Åë½Å¼Óµµ¸¦ ¸ÂÃß¾î ÁÖ¾î¾ß ÇÑ´Ù.

     - HMC5883L ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ½ºÄ³Ä¡ ÆÄÀÏ ´Ù¿î·Îµå


/*
HMC5883L Triple Axis Digital Compass. Output for HMC5883L_processing.pde
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-magnetometr-hmc5883l.html
GIT: https://github.com/jarzebski/Arduino-HMC5883L
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
*/
#include <Wire.h>
#include "hmc5883l.h"
HMC5883L compass;
int previousDegree;
void setup()
{
Serial.begin(9600);
// Initialize HMC5883L
while (!compass.begin())
{
delay(500);
}
// Set measurement range
compass.setRange(HMC5883L_RANGE_1_3GA);
// Set measurement mode
compass.setMeasurementMode(HMC5883L_CONTINOUS);
// Set data rate
compass.setDataRate(HMC5883L_DATARATE_30HZ);
// Set number of samples averaged
compass.setSamples(HMC5883L_SAMPLES_8);
// Set calibration offset. See HMC5883L_calibration.ino
compass.setOffset(0, 0); }
void loop()
{
long x = micros();
Vector norm = compass.readNormalize();
// Calculate heading
float heading = atan2(norm.YAxis, norm.XAxis);
// Set declination angle on your location and fix heading
// You can find your declination on: http://magnetic-declination.com/
// (+) Positive or (-) for negative
// For Bytom / Poland declination angle is 4'26E (positive)
// Formula: (deg + (min / 60.0)) / (180 / M_PI);
float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / M_PI);
heading += declinationAngle;
// Correct for heading < 0deg and heading > 360deg
if (heading < 0)
{
heading += 2 * PI;
}
if (heading > 2 * PI)
{
heading -= 2 * PI;
}
// Convert to degrees
float headingDegrees = heading * 180/M_PI; // Fix HMC5883L issue with angles
float fixedHeadingDegrees;
if (headingDegrees >= 1 && headingDegrees < 240)
{
fixedHeadingDegrees = map(headingDegrees, 0, 239, 0, 179);
} else
if (headingDegrees >= 240)
{
fixedHeadingDegrees = map(headingDegrees, 240, 360, 180, 360);
}
// Smooth angles rotation for +/- 3deg
int smoothHeadingDegrees = round(fixedHeadingDegrees);
if (smoothHeadingDegrees < (previousDegree + 3) && smoothHeadingDegrees > (previousDegree - 3))
{
smoothHeadingDegrees = previousDegree;
}
previousDegree = smoothHeadingDegrees;
// Output
Serial.print(norm.XAxis);
Serial.print(":");
Serial.print(norm.YAxis);
Serial.print(":");
Serial.print(norm.ZAxis);
Serial.print(":");
Serial.print(headingDegrees);
Serial.print(":");
Serial.print(fixedHeadingDegrees);
Serial.print(":");
Serial.print(smoothHeadingDegrees); Serial.println();
// One loop: ~5ms @ 115200 serial.
// We need delay ~28ms for allow data rate 30Hz (~33ms)
delay(30);
}

(2) ½ÇÇà °á°ú

mpu6050

¾ÆµÎÀÌ³ë ½Ã¸®¾ó ¸ð´ÏÅÍâ¿¡¼­ ¹Ýµå½Ã º¸µå·¹ÀÌÆ®(Baudate)¸¦  9600 À¸·Î ¼öÁ¤ ÇØ¾ß ÇÑ´Ù. ±×·¸Áö ¾ÊÀ¸¸é ½Ã¸®¾ó ¸ð´ÏÅÍ Ã¢¿¡ ¾Æ¹«·± µ¥ÀÌÅÍ°¡ Ç¥½ÃµÇÁö ¾Ê°Å³ª À߸øµÈ µ¥ÀÌÅÍ°¡ Ç¥½ÃµÉ °ÍÀÌ´Ù. ÇÁ·Î¼¼½Ì µ¥ÀÌÅ͸¦ ó¸®Çϱâ À§ÇÑ µ¥ÀÌÅÍ À̹ǷΠµ¥ÀÌÅ͸¦ ¹Ù·Î Æǵ¶Çϱâ´Â ¾î·Æ´Ù. µ¥ÀÌÅÍ°¡ ¿Ã¹Ù¸£°Ô Ç¥½ÃµÇ´Â°ÍÀ» È®ÀÎ ÇÏ¿´´Ù¸é ÇÁ·Î¼¼½Ì¿¡¼­ µ¿ÀÏÇÑ ½Ã¸®¾óÆ÷Æ®¸¦ »ç¿ëÇØ¾ß Çϱ⠶§¹®¿¡ ¾ÆµÎÀÌ³ë ½Ã¸®¾ó ¸ð´ÏÅÖ Ã¢À» ´Ýµµ·Ï ÇÏÀÚ.

3.4 ÇÁ·Î¼¼½Ì ÄÚµå

ÇÁ·Î¼¼½Ì Äڵ忡¼­ ÇÑ°¡Áö ÁÖÀÇ ÇؾßÇÒ »çÇ×Àº ½Ã¸®¾ó Æ÷Æ®¸¦ °¢ÀÚÀÇ È¯°æ¿¡ ¸ÂÃ߾ ¼öÁ¤À» ÇØÁÖ¾î¾ß ÇÑ´Ù´Â °ÍÀÌ´Ù.
¾Æ·¡ ÇÁ·Î¼¼½Ì Äڵ忡¼­ "[0]" ÀÇ 0À̶ó´Â ¼ýÀÚ´Â ÀåÄ¡°ü¸®ÀÚ¿¡¼­ COMÆ÷Æ®ÀÇ ¹øÈ£°¡ ¾Æ´Ï¶ó Æ÷Æ®ÀÇ ¼ø¼­¶ó´Â°Í¿¡ ÁÖÀÇ ÇØ¾ß ÇÑ´Ù.

mpu6050

À§ÀÇ ÀåÄ¡°ü¸®ÀÚ È­¸é¿¡¼­ ¿¹¸¦ µç´Ù¸é ´ÙÀ½°ú °°´Ù.

Serial.list()[0]; // --> COM31
Serial.list()[1]; // --> COM5

ÇÁ·Î¼¼½Ì Äڵ带 ½ÇÇàÇÒ¶§ Å×½ºÆ®ÇÏ´Â PCÀÇ COM Æ÷Æ® »óÅ¿¡ µû¶ó¼­ "Serial.list()[0]" ÀÇ ¼ýÀÚ¸¦ ¹Ù²Ù¾î ÁÖ¾î¾ß ÇÑ´Ù.

(1) ÇÁ·Î¼¼½Ì ÄÚµå

/*
HMC5883L Triple Axis Digital Compass.
Processing for HMC5883L_processing.ino
Processing for HMC5883L_processing_MPU6050.ino
Read more: http://www.jarzebski.pl/arduino/czujniki-i-sensory/3-osiowy-magnetometr-hmc5883l.html
GIT: https://github.com/jarzebski/Arduino-HMC5883L
Web: http://www.jarzebski.pl
(c) 2014 by Korneliusz Jarzebski
*/
import processing.serial.*;
Serial myPort;
// Data samples
int actualSample = 0;
int maxSamples = 400;
int sampleStep = 1;
boolean hasData = false;
// Charts
PGraphics pgChart;
int[] colors = { #ff4444, #33ff99, #5588ff };
String[] magneticSeries = { "XAxis", "YAxis", "ZAxis" };
String[] headingSeries = { "Normal", "Fixed", "Smooth" };
// Data for compare
float[][] magneticValues = new float[3][maxSamples];
float[][] headingValues = new float[3][maxSamples];
// Artificial Horizon
PGraphics pgCompassPlate;
PImage imgCompass;
PImage imgCompassRing;
PImage imgCompassPlateWhite;
PImage imgCompassPlateBlack;
int compassWidth;
int compassHeight;
void setup ()
{
size(755, 550, P2D);
background(0);
// Init
initCompass();
// Serial
myPort = new Serial(this, Serial.list()[0], 9600);
myPort.bufferUntil(10);
}
void drawChart(String title, String[] series, float[][] chart, int x, int y, int h, boolean symmetric, boolean fixed, int fixedMin, int fixedMax, int hlines) {
int actualColor = 0;
int maxA = 0;
int maxB = 0;
int maxAB = 0;
int min = 0;
int max = 0;
int step = 0;
int divide = 0;
if (fixed)
{
min = fixedMin;
max = fixedMax;
step = hlines;
} else
{
if (hlines > 2)
{
divide = (hlines - 2);
} else
{
divide = 1;
}
if (symmetric)
{
maxA = (int)abs(getMin(chart));
maxB = (int)abs(getMax(chart));
maxAB = max(maxA, maxB);
step = (maxAB * 2) / divide;
min = -maxAB-step;
max = maxAB+step;
} else
{
min = (int)(getMin(chart));
max = (int)(getMax(chart));
if ((max >= 0) && (min <= 0)) step = (abs(min) + abs(max)) / divide; if ((max < 0) && (min < 0)) step = abs(min - max) / divide; if ((max > 0) && (min > 0)) step = (max - min) / divide; if (divide > 1)
{
min -= step;
max += step;
}
}
}
pgChart = createGraphics((maxSamples*sampleStep)+50, h+60);
pgChart.beginDraw();
// Draw chart area and title
pgChart.background(0);
pgChart.strokeWeight(1);
pgChart.noFill();
pgChart.stroke(50);
pgChart.rect(0, 0, (maxSamples*sampleStep)+49, h+59);
pgChart.text(title, ((maxSamples*sampleStep)/2)-(textWidth(title)/2)+40, 20);
// Draw chart description
String Description[] = new String[chart.length];
int DescriptionWidth[] = new int[chart.length];
int DesctiptionTotalWidth = 0;
int DescriptionOffset = 0;
for (int j = 0; j < chart.length; j++)
{
Description[j] = " "+series[j]+" = ";
DescriptionWidth[j] += textWidth(Description[j]+"+0000.00");
Description[j] += nf(chart[j][actualSample-1], 0, 2)+" ";
DesctiptionTotalWidth += DescriptionWidth[j];
}
actualColor = 0;
for (int j = 0; j < chart.length; j++)
{
pgChart.fill(colors[actualColor]);
pgChart.text(Description[j], ((maxSamples*sampleStep)/2)-(DesctiptionTotalWidth/2)+DescriptionOffset+40, h+50);
DescriptionOffset += DescriptionWidth[j];
actualColor++;
if (actualColor >= colors.length) actualColor = 0;
}
// Draw H-Lines
pgChart.stroke(100);
for (float t = min; t <= max; t=t+step)
{
float line = map(t, min, max, 0, h);
pgChart.line(40, h-line+30, (maxSamples*sampleStep)+40, h-line+30);
pgChart.fill(200, 200, 200);
pgChart.textSize(12);
pgChart.text(int(t), 5, h-line+34);
}
// Draw data series
pgChart.strokeWeight(2);
for (int i = 1; i < actualSample; i++)
{
actualColor = 0;
for (int j = 0; j < chart.length; j++)
{
pgChart.stroke(colors[actualColor]);
float d0 = chart[j][i-1];
float d1 = chart[j][i];
if (d0 < min) d0 = min;
if (d0 > max) d0 = max;
if (d1 < min) d1 = min;
if (d1 > max) d1 = max;
float v0 = map(d0, min, max, 0, h);
float v1 = map(d1, min, max, 0, h);
pgChart.line(((i-1)*sampleStep)+40, h-v0+30, (i*sampleStep)+40, h-v1+30);
actualColor++;
if (actualColor >= colors.length) actualColor = 0;
}
}
pgChart.endDraw();
image(pgChart, x, y);
}
void initCompass()
{
imgCompass = loadImage("compass.png");
imgCompassRing = loadImage("compassRing.png");
imgCompassPlateWhite = loadImage("compassPlateWhite.png");
imgCompassPlateBlack = loadImage("compassPlateBlack.png");
compassWidth = imgCompass.width;
compassHeight = imgCompass.height;
}
void drawCompass(int x, int y, float[][] head, PImage plate)
{
pgCompassPlate = createGraphics(compassWidth, compassWidth); float heading = head[2][actualSample-1];
float north = 180 + heading;
pgCompassPlate.beginDraw();
pgCompassPlate.clear();
pgCompassPlate.translate(100,100);
pgCompassPlate.rotate(-radians(heading));
pgCompassPlate.image(plate, -100, -100);
pgCompassPlate.endDraw();
image(pgCompassPlate, x+30, y+30);
image(imgCompass, x, y);
image(imgCompassRing, x, y);
textAlign(CENTER);
text((int)heading+" deg", x+130, y+265);
textAlign(LEFT);
}
void draw() {
if (!hasData) return;
background(0);
drawChart("Magnetic field [mG]", magneticSeries, magneticValues, 10, 10, 200, false, false, 0, 0, 10);
drawChart("Heading [deg]", headingSeries, headingValues, 10, 280, 200, true, true, 0, 360, 30);
drawCompass(480, 5, headingValues, imgCompassPlateWhite);
drawCompass(480, 275, headingValues, imgCompassPlateBlack);
}
float getMin(float[][] chart)
{
float minValue = 0;
float[] testValues = new float[chart.length];
float testMin = 0;
for (int i = 0; i < actualSample; i++)
{
for (int j = 0; j < testValues.length; j++)
{
testValues[j] = chart[j][i];
}
testMin = min(testValues);
if (i == 0)
{
minValue = testMin;
} else
{
if (minValue > testMin) minValue = testMin;
}
}
return ceil(minValue)-1; }
float getMax(float[][] chart)
{
float maxValue = 0;
float[] testValues = new float[chart.length];
float testMax = 0;
for (int i = 0; i < actualSample; i++)
{
for (int j = 0; j < testValues.length; j++)
{
testValues[j] = chart[j][i];
}
testMax = max(testValues);
if (i == 0)
{
maxValue = testMax;
} else
{
if (maxValue < testMax) maxValue = testMax;
}
}
return ceil(maxValue); }
void nextSample(float[][] chart)
{
for (int j = 0; j < chart.length; j++)
{
float last = chart[j][maxSamples-1];
for (int i = 1; i < maxSamples; i++)
{
chart[j][i-1] = chart[j][i];
}
chart[j][(maxSamples-1)] = last;
}
}
void serialEvent (Serial myPort)
{
String inString = myPort.readStringUntil(10);
if (inString != null)
{
inString = trim(inString);
String[] list = split(inString, ':');
String testString = trim(list[0]);
if (list.length != 6) return;
// Magnetic field
magneticValues[0][actualSample] = (float(list[0]));
magneticValues[1][actualSample] = (float(list[1]));
magneticValues[2][actualSample] = (float(list[2]));
// Headings
headingValues[0][actualSample] = (float(list[3]));
headingValues[1][actualSample] = (float(list[4]));
headingValues[2][actualSample] = (float(list[5]));
if (actualSample > 1)
{
hasData = true;
}
if (actualSample == (maxSamples-1))
{
nextSample(magneticValues);
nextSample(headingValues);
} else
{
actualSample++;
}
}
}

(2) ½ÇÇà °á°ú



º» ¸Þ´º¾óÀÇ ÇÁ·Î¼¼½Ì ÄÚµå´Â ¾Æ·¡ URLÀÇ ³»¿ëÀ» ÂüÁ¶ÇÏ¿© ÀÛ¼º ÇÏ¿´´Ù.
https://github.com/jarzebski/Arduino-HMC5883L

* ´Ù¸¥ ¼¾¼­µéÀÇ ¾ÆµÎÀ̳ë¿Í ÇÁ·Î¼¼½Ì ¸Þ´º¾ó º¸±â

(1) MPU6050 GY-521 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(2) MPU9250 GY-9250 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(3) L3G4200D GY-50 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(4) HMC5883L GY-271 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(5) BMP180 GY-68 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(6) ADXL345 GY-80 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)
(7) ADXL335 GY-61 ¼¾¼­ ¾ÆµÎÀ̳ë, ÇÁ·Î¼¼½Ì ¸Þ´º¾ó(»õâ)