DIGILENT Pmodモジュールを Arduino UNO テスト
No.1 3軸加速度センサー PmodACL
Pmod ACL のページ
https://reference.digilentinc.com/reference/pmod/pmodacl/start
このページから
Example Projects の中の
Using the Pmod ACL with Arduino Uno - Application note のページにアクセス。
Pmod ACL and Arduino Uno Fritzing Image の通りに配線して
Pmod ACL and Arduino Uno CodeArduino のソースコードを Arduino IDE にコピペして
コンパイル & 書込み
シリアルモニターで確認すると x, y, z ともに 0 しか表示しない。
それで、i2c adress check プログラムでI2C のaddressを確認
ソースコード上では
#define ADXL345_Adresse 0x53 // ADXL345 adress
となっているが、実際にチェックした結果 Adress は 0x1D
なのでここを書き直して再実行。
今度は x, y, z すべてデータが取得できました。
なお、I2Cアドレスチェックプログラムは
こちらのページに公開されています。
https://playground.arduino.cc/Main/I2cScanner/
/************************************************************************ * * Test of the Pmod * ************************************************************************* * Description: Pmod_ACL * The 3 components X, Y, and Z of the accelerometer * are displayed in the serial monitor * * Material * 1. Arduino Uno * 2. Pmod ACL * ************************************************************************/ // Déclaration of the adress of the module #define ADXL345_Adresse 0x1D // ADXL345 adress #define POWER_CTL 0x2D // Power Control register #define DATA_FORMAT 0x31 // Data Format register #define DATAX0 0x32 // LSB axe X #define DATAX1 0x33 // MSB axe X #define DATAY0 0x34 // LSB axe Y #define DATAY1 0x35 // MSB Y #define DATAZ0 0x36 // LSB axe Z #define DATAZ1 0x37 // bMSB Z // Configuration of the module #define ADXL345_Precision2G 0x00 #define ADXL345_Precision4G 0x01 #define ADXL345_Precision8G 0x02 #define ADXL345_Precision16G 0x03 #define ADXL345_ModeMesure 0x08 // call library #include <Wire.h> byte buffer[6]; // storage of data of the module int i = 0; int composante_X; int composante_Y; int composante_Z; void setup(void) { Serial.begin(9600); // initialization of serial communication Wire.begin (); // initialization of I2C communication Wire.beginTransmission (ADXL345_Adresse); // configuration of the module Wire.write (DATA_FORMAT); Wire.write (ADXL345_Precision4G); Wire.endTransmission (); Wire.beginTransmission (ADXL345_Adresse); Wire.write (POWER_CTL); Wire.write (ADXL345_ModeMesure); Wire.endTransmission (); } void loop() { Wire.beginTransmission (ADXL345_Adresse); Wire.write(DATAX0); Wire.endTransmission (); Wire.beginTransmission (ADXL345_Adresse); Wire.requestFrom(ADXL345_Adresse, 6); // Recovery of the 6 components i=0; while(Wire.available()) { buffer[i] = Wire.read(); i++; } Wire.endTransmission(); composante_X=(buffer[1] << 8) | buffer[0]; // Development of the 3 components composante_Y=(buffer[3] << 8) | buffer[2]; composante_Z=(buffer[5] << 8) | buffer[4]; Serial.print("X="); // Display of components in the serial monitor Serial.print (composante_X); Serial.print('\t'); // tabulation Serial.print("Y="); Serial.print (composante_Y); Serial.print('\t'); Serial.print("Z="); Serial.print (composante_Z); Serial.println(""); delay(500); }