esphome / esphome/feature-requests
Support ADXL345 sensor (digital accelerometer)
- Dominant language
- No language data
- Stars
- 450
- Forks
- 29
- PR merge metrics
- No merged PRs in 30d
Description
**Describe the problem you have/What new integration you would like**
Support i2c ADXL345 sensor (digital accelerometer)
**Please describe your use case for this integration and alternatives you've tried:**
Got it working using custom sensor
```
#include "esphome.h"
#include
#include
#include
class ADXL345Sensor : public PollingComponent {
public:
Adafruit_ADXL345_Unified accel = Adafruit_ADXL345_Unified(12345);
Sensor *accel_x_sensor = new Sensor();
Sensor *accel_y_sensor = new Sensor();
Sensor *accel_z_sensor = new Sensor();
ADXL345Sensor() : PollingComponent(1000) { }
void setup() override {
accel.begin();
/* Set the range to whatever is appropriate for your project */
// accel.setRange(ADXL345_RANGE_16_G);
accel.setRange(ADXL345_RANGE_8_G);
// accel.setRange(ADXL345_RANGE_4_G);
// accel.setRange(ADXL345_RANGE_2_G);
//
}
void update() override {
sensors_event_t event;
accel.getEvent(&event);
accel_x_sensor->publish_state(event.acceleration.x);
accel_y_sensor->publish_state(event.acceleration.y);
accel_z_sensor->publish_state(event.acceleration.z);
}
};
```
```
esphome:
[...]
includes:
- ADXL345.h
libraries:
- "Grove 3-Axis Digital Gyro"
- platform: custom
lambda: |-
auto adxl345 = new ADXL345Sensor();
App.register_component(adxl345);
return { adxl345->accel_x_sensor, adxl345->accel_y_sensor, adxl345->accel_z_sensor };
sensors:
- name: "Acceleration X"
- name: "Acceleration Y"
- name: "Acceleration Z"
```
**Additional context**
[Adafruit-ADXL345](https://platformio.org/lib/show/15/Adafruit-ADXL345-Unified)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.