1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
* 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|
|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  |
 
###
;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