Arduinoをいじりはじめてみたよ-その4

#1. はじめに
## あいさつ
ひょんなことからArduinoを使って遊ぶことになったので
その備忘録としてまとめていこうかと。
の第四回です。

[第一回](http://qiita.com/kojisato118/items/df1fb5437c90e2ca5abd)
[第二回](http://qiita.com/kojisato118/items/5e5e23d68a0807a26117)
[第三回](http://qiita.com/kojisato118/items/84b0c05e969e8a4531ca)

## 今回の内容
今回は、地磁気センサー(HMC5883L)の値を取得するところまで。

## 参考ページ
* [データシート](http://www51.honeywell.com/aero/common/documents/myaerospacecatalog-documents/Defense_Brochures-documents/HMC5883L_3-Axis_Digital_Compass_IC.pdf)
* [参考ページ1](http://wiki.androciti.com/index.php?HMC5883L%BB%B0%BC%B4%A5%C7%A5%B8%A5%BF%A5%EB%A5%B3%A5%F3%A5%D1%A5%B9%A5%E2%A5%B8%A5%E5%A1%BC%A5%EB)
* [参考ページ2](https://www.arduino.cc/en/Reference/Wire)

#2. 配線
写真と表の表に配線する。
参考ページ1だとArduino UNOだが、私はMegaだったのでSCL,SDAのピン番号が違う。参考ページ2を参照。

|arduino mega|HMC5883L|
|:----------:|:------:|
|5V          |Vcc     |
|GND         |GND     |
|21(SCL)     |SCL     |
|20(SDA)     |SDA     |
 
![IMG_2092.JPG](https://qiita-image-store.s3.amazonaws.com/0/25918/fbea553c-4ceb-a07e-6fd9-70f11542d74a.jpeg)


#3. スケッチ(プログラム)
参考ページ1の通り[ここ](http://wiki.androciti.com/download/SNS-1006/SNS-1006_HMC5883L_Module.rar)からDownloadして、HMC5883LフォルダをArduino 開発環境(Arduino IDE)の「libraries」フォルダーにコピーする。
あとは、HMC5883L_Exampleを開いてArduinoに書き込めば動く。

## 説明
割愛

## 動作
下記みたいな出力がされます。

```
Starting the I2C interface.
Constructing new HMC5883L
Setting scale to +/- 1.3 Ga
Setting measurement mode to continous.
Raw:	599   659   -830   	Scaled:	551.08   606.28   -763.60   	Heading:	0.96 Radians   	55.21 Degrees   	
Raw:	598   657   -834   	Scaled:	550.16   604.44   -767.28   	Heading:	0.96 Radians   	54.99 Degrees   	
Raw:	600   653   -835   	Scaled:	552.00   600.76   -768.20   	Heading:	0.96 Radians   	54.72 Degrees   	
Raw:	600   654   -838   	Scaled:	552.00   601.68   -770.96   	Heading:	0.96 Radians   	54.77 Degrees   	
Raw:	596   647   -854   	Scaled:	548.32   595.24   -785.68   	Heading:	0.95 Radians   	54.65 Degrees   	
Raw:	594   639   -864   	Scaled:	546.48   587.88   -794.88   	Heading:	0.95 Radians   	54.39 Degrees   	
Raw:	592   635   -872   	Scaled:	544.64   584.20   -802.24   	Heading:	0.95 Radians   	54.31 Degrees   	
Raw:	594   624   -876   	Scaled:	546.48   574.08   -805.92   	Heading:	0.94 Radians   	53.71 Degrees   	
Raw:	592   626   -874   	Scaled:	544.64   575.92   -804.08   	Heading:	0.94 Radians   	53.90 Degrees   	
Raw:	590   631   -874   	Scaled:	542.80   580.52   -804.08   	Heading:	0.95 Radians   	54.22 Degrees   	
Raw:	595   628   -874   	Scaled:	547.40   577.76   -804.08   	Heading:	0.94 Radians   	53.85 Degrees   	
Raw:	592   625   -874   	Scaled:	544.64   575.00   -804.08   	Heading:	0.94 Radians   	53.85 Degrees   	
Raw:	593   627   -873   	Scaled:	545.56   576.84   -803.16   	Heading:	0.94 Radians   	53.90 Degrees   	
Raw:	594   628   -873   	Scaled:	546.48   577.76   -803.16   	Heading:	0.94 Radians   	53.89 Degrees   	
Raw:	591   628   -872   	Scaled:	543.72   577.76   -802.24   	Heading:	0.94 Radians   	54.04 Degrees   	
Raw:	594   630   -872   	Scaled:	546.48   579.60   -802.24   	Heading:	0.94 Radians   	53.98 Degrees   	
Raw:	593   630   -877   	Scaled:	545.56   579.60   -806.84   	Heading:	0.94 Radians   	54.03 Degrees   	
Raw:	575   646   -873   	Scaled:	529.00   594.32   -803.16   	Heading:	0.97 Radians   	55.63 Degrees   	
Raw:	544   671   -871   	Scaled:	500.48   617.32   -801.32   	Heading:	1.02 Radians   	58.27 Degrees   	
Raw:	526   687   -872   	Scaled:	483.92   632.04   -802.24   	Heading:	1.04 Radians   	59.86 Degrees   	
Raw:	484   710   -869   	Scaled:	445.28   653.20   -799.48   	Heading:	1.10 Radians   	63.02 Degrees   	
Raw:	454   727   -871   	Scaled:	417.68   668.84   -801.32   	Heading:	1.14 Radians   	65.32 Degrees   	
Raw:	444   733   -870   	Scaled:	408.48   674.36   -800.40   	Heading:	1.15 Radians   	66.09 Degrees   	
Raw:	417   746   -871   	Scaled:	383.64   686.32   -801.32   	Heading:	1.19 Radians   	68.10 Degrees   	
Raw:	396   751   -869   	Scaled:	364.32   690.92   -799.48   	Heading:	1.21 Radians   	69.50 Degrees   	
Raw:	382   759   -868   	Scaled:	351.44   698.28   -798.56   	Heading:	1.23 Radians   	70.58 Degrees   	
Raw:	350   773   -863   	Scaled:	322.00   711.16   -793.96   	Heading:	1.27 Radians   	72.94 Degrees   	
Raw:	331   779   -859   	Scaled:	304.52   716.68   -790.28   	Heading:	1.30 Radians   	74.28 Degrees   	
Raw:	327   781   -862   	Scaled:	300.84   718.52   -793.04   	Heading:	1.30 Radians   	74.58 Degrees   	
Raw:	309   788   -859   	Scaled:	284.28   724.96   -790.28   	Heading:	1.32 Radians   	75.89 Degrees   	
Raw:	304   786   -856   	Scaled:	279.68   723.12   -787.52   	Heading:	1.33 Radians   	76.15 Degrees   	
Raw:	294   791   -855   	Scaled:	270.48   727.72   -786.60   	Heading:	1.34 Radians   	76.91 Degrees   	
Raw:	291   794   -851   	Scaled:	267.72   730.48   -782.92   	Heading:	1.35 Radians   	77.17 Degrees   	
Raw:	283   796   -853   	Scaled:	260.36   732.32   -784.76   	Heading:	1.36 Radians   	77.73 Degrees   	
Raw:	270   796   -852   	Scaled:	248.40   732.32   -783.84   	Heading:	1.37 Radians   	78.56 Degrees   	
Raw:	261   800   -853   	Scaled:	240.12   736.00   -784.76   	Heading:	1.38 Radians   	79.23 Degrees   	
Raw:	252   799   -851   	Scaled:	231.84   735.08   -782.92   	Heading:	1.39 Radians   	79.79 Degrees   	
Raw:	239   803   -850   	Scaled:	219.88   738.76   -782.00   	Heading:	1.41 Radians   	80.72 Degrees   	
Raw:	221   808   -850   	Scaled:	203.32   743.36   -782.00   	Heading:	1.43 Radians   	82.00 Degrees   	
Raw:	206   809   -849   	Scaled:	189.52   744.28   -781.08   	Heading:	1.45 Radians   	83.01 Degrees   	
Raw:	192   809   -846   	Scaled:	176.64   744.28   -778.32   	Heading:	1.47 Radians   	83.95 Degrees   	
Raw:	173   813   -845   	Scaled:	159.16   747.96   -777.40   	Heading:	1.49 Radians   	85.29 Degrees   	
Raw:	168   812   -844   	Scaled:	154.56   747.04   -776.48   	Heading:	1.49 Radians   	85.61 Degrees   	
Raw:	155   815   -843   	Scaled:	142.60   749.80   -775.56   	Heading:	1.51 Radians   	86.53 Degrees   	
Raw:	146   815   -844   	Scaled:	134.32   749.80   -776.48   	Heading:	1.52 Radians   	87.14 Degrees   	
Raw:	136   814   -844   	Scaled:	125.12   748.88   -776.48   	Heading:	1.53 Radians   	87.81 Degrees   

```