Ks0128 keyestudio EASY plug ADXL345 Three Axis Acceleration Module: Difference between revisions

From Keyestudio Wiki
Jump to navigation Jump to search
No edit summary
 
(12 intermediate revisions by the same user not shown)
Line 1: Line 1:
[[image:ks0118图.jpg|thumb|600px|right|Keyestudio EASY plug ADXL345 Acceleration Module]]
[[image:ks0128图.jpg|thumb|600px|right|Keyestudio EASY plug ADXL345 Acceleration Module]]


==Introduction==
==Introduction==
Line 5: Line 5:
Digital output data is formatted as 16-bit twos complement, and is accessible through either a SPI or I2C digital interface.<br>
Digital output data is formatted as 16-bit twos complement, and is accessible through either a SPI or I2C digital interface.<br>
The ADXL345 is well suited to measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock.<br>
The ADXL345 is well suited to measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock.<br>
<span style="color: red">'''Note: '''this module needs to be used together with EASY plug control board.<br>
This module needs to be used together with EASY plug control board.<br>
 
<span style=color:red> '''Special Note:''' <br>
The sensor/module is equipped with the RJ11 6P6C interface, compatible with our keyestudio EASY plug Control Board with RJ11 6P6C interface. <br> If you have the control board of other brands, it is also equipped with the RJ11 6P6C interface but has different internal line sequence, can’t be used compatibly with our sensor/module. </span><br>
 
<br>
<br>


Line 28: Line 32:
<br>
<br>
==Upload the Code==
==Upload the Code==
Copy and paste below code to [http://wiki.keyestudio.com/index.php/How_to_Download_Arduino_IDE Arduino IDE] and upload.
Below is an example code. Open or drag below code to [https://wiki.keyestudio.com/Getting_Started_with_Mixly  Mixly Blocks] and upload the code to your board to check the 3-axis acceleration data and the module's tilt information.<br>
<pre>
<br>[[File:ks0397 22.1.png|500px|frameless|thumb]]<br>
#include <Wire.h>    // place file “Wire.h” under the directory “libraries” of Arduino
// Registers for ADXL345
#define ADXL345_ADDRESS (0xA6 >> 1)  // address for device is 8 bit but shift to the
                                    // right by 1 bit to make it 7 bit because the
                                    // wire library only takes in 7 bit addresses
#define ADXL345_REGISTER_XLSB (0x32)


int accelerometer_data[3];
<br>
// void because this only tells the cip to send data to its output register
==What You Should See==
// writes data to the slave's buffer
Open the Serial monitor to see the 3-axis acceleration data. See changes as you sway the Accelerometer.
void i2c_write(int address, byte reg, byte data) {
<br>[[File:ks0397 22-2.png|600px|frameless|thumb]]<br>
  // Send output register address
  Wire.beginTransmission(address);
  // Connect to device
  Wire.write(reg);
  // Send data
  Wire.write(data); //low byte
  Wire.endTransmission();
}


// void because using pointers
<br>
// microcontroller reads data from the sensor's input register
<span style="color: red">'''Little Knowledge:'''</span> <br>
void i2c_read(int address, byte reg, int count, byte* data) {
If you think the monitor’s result is too fast to see the data clearly, you can drag a Delay block to add into the source code. Shown below. <br>
  // Used to read the number of data received
After that, upload the code again and open the monitor, you should be able to see the display data clearly. <br>
  int i = 0;
<br>[[File:ks0397 22-3.png|600px|frameless|thumb]]<br>
  // Send input register address
  Wire.beginTransmission(address);
  // Connect to device
  Wire.write(reg);
  Wire.endTransmission();


  // Connect to device
  Wire.beginTransmission(address);
  // Request data from slave
  // Count stands for number of bytes to request
  Wire.requestFrom(address, count);
  while(Wire.available()) // slave may send less than requested
  {
    char c = Wire.read(); // receive a byte as character
    data[i] = c;
    i++;
  }
  Wire.endTransmission();
}


void init_adxl345() {
<br>
  byte data = 0;


  i2c_write(ADXL345_ADDRESS, 0x31, 0x0B);  // 13-bit mode  +_ 16g
==Extension Experiment==
  i2c_write(ADXL345_ADDRESS, 0x2D, 0x08);  // Power register
<br>
<span style=color:brown><big>'''Controlling Three LEDs'''</big>  </span><br>
<br>
'''Hookup Guide'''<br>
Connect the EASY Plug ADXL345 Acceleration module and three LED modules to control board using RJ11 cables.
<br>[[File:三轴灯.jpg|500px|frameless|thumb]]<br>


  i2c_write(ADXL345_ADDRESS, 0x1E, 0x00);  // x
<br>
  i2c_write(ADXL345_ADDRESS, 0x1F, 0x00);  // Y
'''Test Code'''<br>
  i2c_write(ADXL345_ADDRESS, 0x20, 0x05);  // Z
Upload the test code below to your board to check the 3-axis acceleration data and the module's tilt information.
<br>[[File:ks0397 22.2.png|600px|frameless|thumb]]<br>
  // Check to see if it worked!
  i2c_read(ADXL345_ADDRESS, 0X00, 1, &data);
  if(data==0xE5)
    Serial.println("it work Success");
  else
    Serial.println("it work Fail");
}


void read_adxl345() {
<br>
  byte bytes[6];
'''What You Should See'''<br>
  memset(bytes,0,6);
<br>[[File:ks0397 22-4.png|500px|frameless|thumb]]<br>
<br>
Upload success, open the serial monitor, it prints out the value of X,Y,Z axis. Each axis controls a light. If the measured value is greater than 200, LED lights up.
<br>[[File:ks0397 22-6.png|500px|frameless|thumb]]<br>
<br>[[File:ks0397 22-7.png|500px|frameless|thumb]]<br>
<br>[[File:ks0397 22-8.png|500px|frameless|thumb]]<br>


  // Read 6 bytes from the ADXL345
  i2c_read(ADXL345_ADDRESS, ADXL345_REGISTER_XLSB, 6, bytes);
  // Unpack data
  for (int i=0;i<3;++i) {
    accelerometer_data[i] = (int)bytes[2*i] + (((int)bytes[2*i + 1]) << 8);
  }
}
// initialise and start everything
void setup() {
  Wire.begin();
  Serial.begin(9600);
  for(int i=0; i<3; ++i) {
    accelerometer_data[i]  = 0;
  }
  init_adxl345();
}
void loop() {
  read_adxl345();
  Serial.print("ACCEL: ");
  Serial.print(float(accelerometer_data[0])*3.9/1000);//3.9mg/LSB scale factor in 13-bit mode
  Serial.print("\t");
  Serial.print(float(accelerometer_data[1])*3.9/1000);
  Serial.print("\t");
  Serial.print(float(accelerometer_data[2])*3.9/1000);
  Serial.print("\n");
  delay(100);
}
</pre>


<br>
<br>
==What You Should See==
Open the Serial monitor to see the 3-axis acceleration data. See changes as you sway the Accelerometer.
<br>[[File:ks0128 Result.gif|500px|frameless|thumb]]<br>


<br>
==Resources ==
==Resources ==
'''PDF'''<br>
 
https://drive.google.com/open?id=1Tf19JMZ9C_47d3Gzar8xb766qp5pAFz2
https://fs.keyestudio.com/KS0128
 


<br>
<br>
==Buy from ==
==Buy from ==
'''Official Website'''<br>
*[https://www.keyestudio.com/newkeyestudio-easy-plug-adxl345-three-axis-acceleration-module-for-arduino-steam-p0098-p0098.html  '''Official Website''' ]
http://www.keyestudio.com/keyestudio-easy-plug-adxl345-three-axis-acceleration-module-for-arduino.html
 
*[https://www.aliexpress.com/store/product/New-Keyestudio-EASY-plug-ADXL345-Three-Axis-Acceleration-Module-for-arduino/1452162_32644046717.html?spm=2114.12010612.8148356.48.41484ba7Q6bjKs  Shop on aliexpress]




[[category:EASY Plug]]
[[category:EASY Plug]]

Latest revision as of 16:41, 7 January 2021

Keyestudio EASY plug ADXL345 Acceleration Module

Introduction

The ADXL345 module is a low power, 3-axis MEMS accelerometer with high resolution (13-bit) and measurement at up to ±16g (gravitational force).
Digital output data is formatted as 16-bit twos complement, and is accessible through either a SPI or I2C digital interface.
The ADXL345 is well suited to measures the static acceleration of gravity in tilt-sensing applications, as well as dynamic acceleration resulting from motion or shock.
This module needs to be used together with EASY plug control board.

Special Note:
The sensor/module is equipped with the RJ11 6P6C interface, compatible with our keyestudio EASY plug Control Board with RJ11 6P6C interface.
If you have the control board of other brands, it is also equipped with the RJ11 6P6C interface but has different internal line sequence, can’t be used compatibly with our sensor/module.


Features

  • Connector: Easy plug
  • Working Voltage: 2.0-3.6V
  • Ultra Low Power @2.5v: 40uA /working mode; 0.1uA / standby mode
  • Communication interface: I2C / SPI
  • Tap/Double Tap Detection
  • Free-Fall Detection


Technical Details

  • Dimensions: 41mm*20mm*18mm
  • Weight: 4.6g


Connect It Up

Connect the EASY Plug ADXL345 Acceleration module to control board using an RJ11 cable. Then connect the control board to your PC with a USB cable.
thumb


Upload the Code

Below is an example code. Open or drag below code to Mixly Blocks and upload the code to your board to check the 3-axis acceleration data and the module's tilt information.

thumb


What You Should See

Open the Serial monitor to see the 3-axis acceleration data. See changes as you sway the Accelerometer.
thumb


Little Knowledge:
If you think the monitor’s result is too fast to see the data clearly, you can drag a Delay block to add into the source code. Shown below.
After that, upload the code again and open the monitor, you should be able to see the display data clearly.

thumb



Extension Experiment


Controlling Three LEDs

Hookup Guide
Connect the EASY Plug ADXL345 Acceleration module and three LED modules to control board using RJ11 cables.
thumb


Test Code
Upload the test code below to your board to check the 3-axis acceleration data and the module's tilt information.
thumb


What You Should See

thumb

Upload success, open the serial monitor, it prints out the value of X,Y,Z axis. Each axis controls a light. If the measured value is greater than 200, LED lights up.
thumb

thumb

thumb



Resources

https://fs.keyestudio.com/KS0128



Buy from