ADXL345 3-axis Acceleration Sensor sample
Dependencies: ADXL345_I2C mbed
Fork of ADXL345 by
About ADXL345
ADXL345 is a 3-axis acceleration sensor and can be controlled by using the I2C.
- Datasheet of ADXL345
http://www.analog.com/media/en/technical-documentation/data-sheets/ADXL345.pdf
About sample program
This program outputs the acceleration information of 3-axis to the terminal.
The 3-axis is as follows:
In the graph, the acceleration information of 3-axis showes.
About wiring
Sensor | GR-PEACH |
VDD | 3.3V |
GND | GND |
SCL | D15 |
SDA | D14 |
main.cpp
- Committer:
- 1050186
- Date:
- 2016-04-28
- Revision:
- 1:c835cfa8b41c
- Parent:
- 0:75c7bfd01ea0
File content as of revision 1:c835cfa8b41c:
#include "mbed.h" #include "ADXL345_I2C.h" ADXL345_I2C accelerometer(I2C_SDA, I2C_SCL); Serial pc(USBTX, USBRX); int main() { int readings[3] = {0, 0, 0}; pc.printf("Starting ADXL345 test...\n"); pc.printf("Device ID is: 0x%02x\n", accelerometer.getDevId()); //Go into standby mode to configure the device. accelerometer.setPowerControl(0x00); //Full resolution, +/-16g, 4mg/LSB. accelerometer.setDataFormatControl(0x0B); //3.2kHz data rate. accelerometer.setDataRate(ADXL345_3200HZ); //Measurement mode. accelerometer.setPowerControl(0x08); while (1) { wait(0.1); accelerometer.getOutput(readings); //13-bit, sign extended values. pc.printf("%i, %i, %i\n", (int16_t)readings[0], (int16_t)readings[1], (int16_t)readings[2]); } }