GR-ADZUKI ACCELEROMETER

Pocket

GR-ADZUKIには、基板上に加速度センサー(アナログ出力)、デジタルコンパス(I2C通信)用DIPピンソケットが装備されています。
今回は、加速度センサを使用してみます。
3軸加速度センサモジュール KXSC7-2050
http://akizukidenshi.com/catalog/g/gK-07243/
データシート
http://kionixfs.kionix.com/en/datasheet/KXTC9-2050%20Specifications%20Rev%202.pdf#search=%27KXSC7+datasheet%27

2つのソケットのうちUSB側のソケットが加速度センサーのソケットになります。
加速度センサモジュールは、ピンのはんだ付け必要です。
ピンのはんだ付けが済んだら、向きを間違えないように差し込みます。
ソケットの凹みがある側とモジュール基板上の凹みの絵がある側を揃えて差し込みます。

ピン配置は、
アナログ入力A3 X軸出力
アナログ入力A4 Y軸出力
アナログ入力A5 Z軸出力
となっています。

プログラムの説明をします。

まず、ピンの定義をします。
const int X_Axis = A3;
const int Y_Axis = A4;
const int Z_Axis = A5;

次に加速度と傾きの角度を保持する変数を宣言します。
double X_Value = 0;
double Y_Value = 0;
double Z_Value = 0;

double X_degree = 0;
double Y_degree = 0;
double Z_degree = 0;

setup()関数でシリアル通信の開始を行っています。
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
}

loop()関数では、各軸の加速度の値を取得しします。
void loop() {
// read the value from the sensor:
X_Value = (double)analogRead(X_Axis) – 512;
Y_Value = (double)analogRead(Y_Axis) – 512;
Z_Value = (double)analogRead(Z_Axis) – 512;
加速度の0点が512なので加速度=0の値を0にするために512を引いています。

傾きを次に計算します。逆三角関数を使用しています。
X_degree = atan(X_Value / sqrt(Y_Value*Y_Value+Z_Value*Z_Value)) * 180 / PI;
Y_degree = atan(Y_Value / sqrt(X_Value*X_Value+Z_Value*Z_Value)) * 180 / PI;
Z_degree = atan(Z_Value / sqrt(X_Value*X_Value+Y_Value*Y_Value)) * 180 / PI;
最後の*180/PIは、ラジアン単位を角度単位に変換するための物です。
PIは、円周率の定数で、値は、3.14159です。

最後に結果をシリアルモニタに送ります。
// send sensor values:
Serial.print(“(x,y,z)=(“);
Serial.print(X_Value);
Serial.print(“, “);
Serial.print(Y_Value);
Serial.print(“, “);
Serial.print(Z_Value);
Serial.print(“), Tx=”);
Serial.print(X_degree);
Serial.print(“, Ty=”);
Serial.print(Y_degree);
Serial.print(“, Tz=”);
Serial.print(Z_degree);
Serial.println();

300msecごとに処理を繰り返します。
delay(300);

サンプルプログラムは以下にあります。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/acceleration/acceleration.ino

 

GR-ADZUKI is equipped with a DIP pin socket for acceleration sensor (analog output) and digital compass (I2C communication) on the board.
This time, I will try using the acceleration sensor.
Three-axis acceleration sensor module KXSC 7-2050
http://akizukidenshi.com/catalog/g/gK-07243/
Data sheet
http://kionixfs.kionix.com/en/datasheet/KXTC9-2050%20Specifications%20Rev%202.pdf#search=%27KXSC7+datasheet%27

Among the two sockets, the socket on the USB side becomes the socket of the acceleration sensor.
For the acceleration sensor module, pin soldering is necessary.
After soldering the pin, insert it so as not to mistake the direction.
Insert the side where the socket is dented and the side with the indentation on the module board aligned.

The pin arrangement is as shown below.
analog input A3 to X axis output
Analog input A4 to Y axis output
Analog input A5 to Z axis output

I will explain the program.

First, I will define pin.
const int X_Axis = A3;
const int Y_Axis = A4;
const int Z_Axis = A5;

Next we declare variables that hold the angles of acceleration and slope.
double X_Value = 0;
double Y_Value = 0;
double Z_Value = 0;

double X_degree = 0;
double Y_degree = 0;
double Z_degree = 0;

Serial communication is started with setup() function.
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
}

In the loop() function, we obtain the acceleration vAalue of each axis.
void loop() {
// read the value from the sensor:
X_Value = (double)analogRead(X_Axis) – 512;
Y_Value = (double)analogRead(Y_Axis) – 512;
Z_Value = (double)analogRead(Z_Axis) – 512;
The 0 point of acceleration is 512. In order to set the acceleration 0 value to 0, 512 is subtracted from the value.

Then calculate the slope. Inverse trigonometric function is used.
X_degree = atan(X_Value / sqrt(Y_Value*Y_Value+Z_Value*Z_Value)) * 180 / PI;
Y_degree = atan(Y_Value / sqrt(X_Value*X_Value+Z_Value*Z_Value)) * 180 / PI;
Z_degree = atan(Z_Value / sqrt(X_Value*X_Value+Y_Value*Y_Value)) * 180 / PI;
The final * 180 / PI is for converting radian units to angular units.
PI is a constant of Pi, the value is 3.14159.

Finally, we send the result to the serial monitor.
// send sensor values:
Serial.print(“(x,y,z)=(“);
Serial.print(X_Value);
Serial.print(“, “);
Serial.print(Y_Value);
Serial.print(“, “);
Serial.print(Z_Value);
Serial.print(“), Tx=”);
Serial.print(X_degree);
Serial.print(“, Ty=”);
Serial.print(Y_degree);
Serial.print(“, Tz=”);
Serial.print(Z_degree);
Serial.println();

Repeat processing every 300 msec.
delay(300);

The sample program is below.
https://github.com/jendo1969/GR-ADZUKI2/blob/master/acceleration/acceleration.ino

 

GR-ADZUKI在板上配有用於加速度傳感器(模擬輸出)和數字羅盤(I2C通信)的DIP引腳插座。
這一次,我會嘗試使用加速度傳感器。
三軸加速度傳感器模塊KXSC 7-2050
http://akizukidenshi.com/catalog/g/gK-07243/
數據表
http://kionixfs.kionix.com/en/datasheet/KXTC9-2050%20Specifications%20Rev%202.pdf#search=%27KXSC7+datasheet%27

在這兩個插座中,USB端的插座成為加速度傳感器的插座。
對於加速度傳感器模塊,引腳焊接是必要的。
在焊接引腳之後,將其插入以免錯誤方向。
將插座凹陷的一側和模塊板上缺口的一側對齊。

引腳排列如下。
模擬輸入A3 X軸輸出
模擬輸入A4 Y軸輸出
模擬輸入A5 Z軸輸出

我會解釋一下這個程序。

首先,我將定義引腳。
const int X_Axis = A3;
const int Y_Axis = A4;
const int Z_Axis = A5;

接下來我們聲明包含加速度和斜率角度的變量。
double X_Value = 0;
double Y_Value = 0;
double Z_Value = 0;

double X_degree = 0;
double Y_degree = 0;
double Z_degree = 0;

setup()関数でシリアル通信の開始を行っています。
void setup() {
Serial.begin(9600);
while (!Serial) {
; // wait for serial port to connect.
}
}

在loop()函數中,我們獲得每個軸的加速度值。
void loop() {
// read the value from the sensor:
X_Value = (double)analogRead(X_Axis) – 512;
Y_Value = (double)analogRead(Y_Axis) – 512;
Z_Value = (double)analogRead(Z_Axis) – 512;
加速度的0點是512。 要將加速度= 0的值減小到0,將從該值中減去512。

然後計算斜率。 使用反三角函數
X_degree = atan(X_Value / sqrt(Y_Value*Y_Value+Z_Value*Z_Value)) * 180 / PI;
Y_degree = atan(Y_Value / sqrt(X_Value*X_Value+Z_Value*Z_Value)) * 180 / PI;
Z_degree = atan(Z_Value / sqrt(X_Value*X_Value+Y_Value*Y_Value)) * 180 / PI;
最後的* 180 / PI用於將弧度單位轉換為角度單位。
PI是一個常數Pi,值是3.14159。

最後,我們將結果發送到串行監視器。
// send sensor values:
Serial.print(“(x,y,z)=(“);
Serial.print(X_Value);
Serial.print(“, “);
Serial.print(Y_Value);
Serial.print(“, “);
Serial.print(Z_Value);
Serial.print(“), Tx=”);
Serial.print(X_degree);
Serial.print(“, Ty=”);
Serial.print(Y_degree);
Serial.print(“, Tz=”);
Serial.print(Z_degree);
Serial.println();

每300毫秒重複處理一次。
delay(300);

示例程序如下。
https://github.com/jendo1969/GR-ADZUKI2/blob/master/acceleration/acceleration.ino

Post Tagged with , ,

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください