2016-06-05 22:59:55 +02:00
|
|
|
# ADXL345 Module
|
|
|
|
| Since | Origin / Contributor | Maintainer | Source |
|
|
|
|
| :----- | :-------------------- | :---------- | :------ |
|
|
|
|
| 2016-04-08 | [Jason Schmidlapp](https://github.com/jschmidlapp) | [Jason Schmidlapp](https://github.com/jschmidlapp) | [adxl345.c](../../../app/modules/adxl345.c)|
|
|
|
|
|
|
|
|
|
|
|
|
This module provides access to the [ADXL345](https://www.sparkfun.com/products/9836) triple axis accelerometer.
|
|
|
|
|
|
|
|
## adxl345.read()
|
|
|
|
Samples the sensor and returns X,Y and Z data from the accelerometer.
|
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
`adxl345.read()`
|
|
|
|
|
|
|
|
#### Returns
|
|
|
|
X,Y,Z data (integers)
|
|
|
|
|
|
|
|
#### Example
|
|
|
|
```lua
|
2017-05-21 16:17:29 +02:00
|
|
|
local sda, scl = 1, 2
|
|
|
|
i2c.setup(0, sda, scl, i2c.SLOW) -- call i2c.setup() only once
|
|
|
|
adxl345.setup()
|
2016-06-05 22:59:55 +02:00
|
|
|
local x,y,z = adxl345.read()
|
|
|
|
print(string.format("X = %d, Y = %d, Z = %d", x, y, z))
|
|
|
|
```
|
|
|
|
|
|
|
|
## adxl345.init()
|
|
|
|
Initializes the module and sets the pin configuration.
|
|
|
|
|
2017-05-21 16:17:29 +02:00
|
|
|
!!! attention
|
|
|
|
|
|
|
|
This function is deprecated and will be removed in upcoming releases. Use `adxl345.setup()` instead.
|
|
|
|
|
2016-06-05 22:59:55 +02:00
|
|
|
#### Syntax
|
|
|
|
`adxl345.init(sda, scl)`
|
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
- `sda` data pin
|
|
|
|
- `scl` clock pin
|
|
|
|
|
|
|
|
#### Returns
|
|
|
|
`nil`
|
2017-05-21 16:17:29 +02:00
|
|
|
|
|
|
|
## adxl345.setup()
|
|
|
|
Initializes the module.
|
|
|
|
|
|
|
|
#### Syntax
|
|
|
|
`adxl345.setup()`
|
|
|
|
|
|
|
|
#### Parameters
|
|
|
|
None
|
|
|
|
|
|
|
|
#### Returns
|
|
|
|
`nil`
|