* KXR94-2050 [#pdc05a51]
- 3軸加速度センサモジュール KXR94−2050
-- 秋月: http://akizukidenshi.com/catalog/g/gM-05153/
--- 仕様:http://akizukidenshi.com/download/ds/kionix/KXR94-2050_Specifications_Rev_3.pdf
--- 取説:http://akizukidenshi.com/download/ds/akizuki/AE-KXR94-2050.pdf
-- マルツ: https://www.marutsu.co.jp/pc/i/833004/

* ハード [#rac03bfe]
|VDD   |1|8|Out.X|
|Enable|2|7|Out.Y|
|GND   |3|6|Out.Z|
|----  |4|5|Test |
|vdd|1|8|out.x|
|en |2|7|out.u|
|gnd|3|6|out.Z|
|---|4|5|test |

通常動作
|VDD   |1|8|Out.X|
|VDD   |2|7|Out.Y|
|GND   |3|6|Out.Z|
|----  |4|5|GND  |
|vdd|1|8|out.x|
|vdd|2|7|out.y|
|gnd|3|6|out.z|
|---|4|5|gnd  |

###
;Arduino.nano ctrl
;KXR94-2050   acc

;acc.vdd = acc.en   = ctrl.v5
;acc.gnd = acc.test = ctrl.gnd
;acc.out.x = ctrl.a1
;acc.out.y = ctrl.a2
;acc.out.z = ctrl.a3
###

* ソフト [#rca0a3b9]
###
#ifdef ARDUINO_AVR_UNO
  const int pX = 0;
  const int pY = 1;
  const int pZ = 2;
#endif
#ifdef ARDUINO_AVR_NANO
  const int pX = 1;
  const int pY = 2;
  const int pZ = 3;
#endif

static char gBuffer[1024];

#define dAveQueueSize 30
static int gAveQueueX[dAveQueueSize];
static int gAveQueueY[dAveQueueSize];
static int gAveQueueZ[dAveQueueSize];
static int gAveQueueIndex = 0;
static int gAveX = 0;
static int gAveY = 0;
static int gAveZ = 0;

////////////////////////////////////////////////////////////////
void fInit() {
  for(int i = 0; i < dAveQueueSize; i++) {
    gAveQueueX[i] = 0;
    gAveQueueY[i] = 0;
    gAveQueueZ[i] = 0;
  }
}

#define dAnalogOffset 512
void fSet(int x, int y, int z) {
  gAveX -= gAveQueueX[gAveQueueIndex];
  gAveY -= gAveQueueY[gAveQueueIndex];
  gAveZ -= gAveQueueZ[gAveQueueIndex];

  gAveQueueX[gAveQueueIndex] = (x - dAnalogOffset) / dAveQueueSize;
  gAveQueueY[gAveQueueIndex] = (y - dAnalogOffset) / dAveQueueSize;
  gAveQueueZ[gAveQueueIndex] = (z - dAnalogOffset) / dAveQueueSize;

  gAveX += gAveQueueX[gAveQueueIndex];
  gAveY += gAveQueueY[gAveQueueIndex];
  gAveZ += gAveQueueZ[gAveQueueIndex];

  gAveQueueIndex++;
  if (gAveQueueIndex >= dAveQueueSize) gAveQueueIndex = 0;
}

////////////////////////////////////////////////////////////////
void setup() {
  Serial.begin(9600);
  Serial.println("#AccSensor.Start");
  Serial.println("#Format: Ax,Ay,Az");

  #ifdef ARDUINO_AVR_UNO
    Serial.println("#Arduino: ARDUINO_AVR_UNO");
  #endif
  #ifdef ARDUINO_AVR_NANO
    Serial.println("#Arduino: ARDUINO_AVR_NANO");
  #endif

  fInit();
}

////////////////////////////////////////////////////////////////
void loop() {
  int x = analogRead(pX);
  int y = analogRead(pY);
  int z = analogRead(pZ);

  fSet(x,y,z);
  
  snprintf(gBuffer, sizeof(gBuffer),
    "%d, %d, %d",
     gAveX, gAveY, gAveZ
  );
  Serial.println(gBuffer);
}

////////////////////////////////////////////////////////////////

###

* 参考 [#c353d4f5]
- https://deviceplus.jp/hobby/entry017/
- https://www.petitmonte.com/robot/howto_kxr94_2050.html
- http://myct.jp/arduino/index.php?%E5%8A%A0%E9%80%9F%E5%BA%A6%E3%82%BB%E3%83%B3%E3%82%B5%20KXR94-2050
- http://physics.cocolog-nifty.com/weblog/2018/07/arduino203kxr94.html
    技術 一覧 検索 最新 バックアップ リンク元   ヘルプ   最終更新のRSS