ADXL345 accelerometer
The Analog Devices ADXL345 three-axis accelerometer on the GY-291 breakout.
Aliases: GY-291, ADXL345 module, 3-axis accelerometer. It measures acceleration, including gravity, on three axes, so at rest it says which way is down: the tilt sensor of the SunFounder kits and many Adafruit tutorials, and the simpler cousin of the MPU6050.
Pins
| Pin | What it does |
|---|---|
GND, VCC |
Ground and the supply; the breakout takes 3.3 V or 5 V. |
CS |
High for I2C. The breakout pulls it up; leave it. |
INT1, INT2 |
Interrupt outputs (data ready here). |
SDO |
The address: low or open is 0x53, high is 0x1D. |
SDA, SCL |
The I2C bus. |
While it runs
Drag the board to tip it: left and right is roll, up and down is pitch. The arrow on its face is where gravity is pulling in the chip's own axes.
Reading it on an Arduino
With Adafruit's unified-sensor library, which Mokxi ships as
Adafruit_ADXL345_U.h:
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_ADXL345_U.h>
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
void setup() {
Serial.begin(9600);
accel.begin();
accel.setRange(ADXL345_RANGE_16_G);
}
void loop() {
sensors_event_t event;
accel.getEvent(&event);
Serial.println(event.acceleration.z); // about 9.8 lying flat
delay(500);
}
getX(), getY() and getZ() give the raw counts. getSensor() is not in Mokxi.
What the model gets right
From the ADXL345 datasheet, over I2C:
Standby at power-on. The chip does not measure until bit 3 of POWER_CTL
(0x2D) is set; until then the data registers read zero. DEVID (0x00) reads 0xE5.
The scale. In 10-bit mode 256, 128, 64 or 32 counts a g on the 2, 4, 8 and 16 g ranges; at full resolution 3.9 mg a count on every range. Past the range the reading saturates.
The data rate. A new sample lands at the BW_RATE rate, 100 Hz at reset, and
sets DATA_READY, which reading the data clears and which drives INT1 or INT2
when enabled.
Offsets in OFSX, OFSY and OFSZ add to the output at 15.6 mg a count, and
left justification and the interrupt polarity follow DATA_FORMAT.
Gravity. The tilt is resolved onto the axes as on the MPU6050: flat is 1 g on Z, tipped 30 degrees nose up is -0.5 g on X.
What it does not model
SPI (with CS held low the chip ignores I2C, and SPI itself is not modeled), the
tap, double-tap, activity and free-fall detectors (their registers hold what is
written, and no event fires), the FIFO (it reads as bypass), self-test, noise and
the offset and sensitivity errors the sheet allows.
Common mistakes
Reading zeros because the chip was never put in measure mode: write 0x08 to
POWER_CTL, or call begin().
Reading at 0x1D when SDO is low, or at 0x53 when it is tied high.
See it in action
Tilt level prints the three axes and tells you which way to tip. Open it at /templates.