2010年2月2日火曜日

HMC5843 3軸磁気センサ

Sparkfun から12ビットA/D内蔵のI2Cインターフェースの軸磁気センサ HMC5843 のブレイクアウトボードが発売された.ネット上で見つかる Arduino 用ライブラリコードはなんか動作があやしいので,というかメモリ節約のため? Wire ライブラリを使っていないので,結局自分で作った.
HMC5843.zip: Extract the folder and put it into library
最大 1 ミリガウスあたり 1620 カウントの分解能であるという...ほんとかいな

スケッチ HMC5843.ped
-----

#include
#include
#include

i2cLCD lcd = i2cLCD();
HMC5843 hmc = HMC5843();

void setup() {
  Wire.begin();
  lcd.begin();

  delay(50);
  hmc.begin(Gain1300);
}

int x,y,z;
void loop() {
  int tx, ty, tz;
  float cpmg;
  hmc.measured(tx, ty, tz);
  x = (tx + x)/2;
  y = (ty + y)/2;
  z = (tz + z)/2;
  cpmg = hmc.countsPerMilliGauss(Gain1300);
  lcd.setCursor(0,0);
  lcd.print((float)x/cpmg, 3);
  lcd.print(" ");
  lcd.print((float)y/cpmg, 3);
  lcd.print(" ");
  lcd.setCursor(0,1);
  lcd.print((float)z/cpmg, 3);
  lcd.print(" ");
  delay(200);
}

0 件のコメント:

コメントを投稿