Library for ADXL362 accelerometer that uses SPI DMA for efficient transfers
The ADXL362 is an inexpensive 3-DOF ultra-low power accelerometer. It can do movement detection from rest continuously at 270 nA (yes, nano-amps!) and also has a large FIFO that makes it possible to buffer samples while the processor is busy or even sleeping.
The GY362 is a compatible version of the ADXL362 and also works with this library.
- Github repository
- License: MIT (free for use in open or closed source projects, including commercial products)
- Datasheet
- Full browsable API documentation
This library uses the ADXL362 in SPI mode.
Breakout | Particle Device | Color | Description |
---|---|---|---|
VIN | 3V3 | Red | 3.3V DC Power |
GND | GND | Black | Ground |
SCL / SCLK | Orange | SPI CLK | |
SDA / MOSI / SDI | Blue | SPI MOSI | |
SDO / MISO | Green | SPI MISO | |
CS | A2 | Yellow | SPI Chip Select |
INT2 | n/c | Interrupt 2 (not used) | |
INT1 | n/c | Interrupt 1 (not used) |
Instantiate a global object for the accelerometer. The first parameter is the SPI bus amd the second is the CS line.
ADXL362DMA accel(SPI, A2);
Initialize the chip:
accel.softReset();
while(accel.readStatus() == 0) {
Log.info("no status yet, waiting for accelerometer");
delay(1000);
}
Enable measuring mode (it boots into standby mode):
accel.setMeasureMode(true);
}
Read data. There is also a function to read roll and pitch data instead of raw data, see example 4-rollpitch.
int16_t x, y, z;
accel.readXYZ(x, y, z);
Serial.printlnf("%5d %5d %5d", (int)x, (int)y, (int)z);
- Fixed occasional SOS+1 hard fault at boot when using the class as a globally constructed object.