MPU6050 Accelerometer/Gyroscope Component

The MPU6050 allows you to use your MPU6050 i2c-enabled accelerometers/gyroscopes with esphomelib (datasheet, Sparkfun). It requires i2c to be setup to work.

This component only supports reading in the measurements directly from the registers of the chip at the moment. If you do need some more complicated signal processing and/or configuration options, I would recommend copying the code over and creating your own custom component, as supporting every single possible configuration is not esphomelib’s ultimate goal with a chip that supports such a variety of options.

Example Usage

// inside setup()
App.init_i2c(SDA_PIN, SCL_PIN); // change these values for your pins.
// create sensors
auto *mpu6050 = App.make_mpu6050_sensor();
App.register_sensor(mpu6050->make_accel_x_sensor("MPU6050 Accel X"));
App.register_sensor(mpu6050->make_accel_y_sensor("MPU6050 Accel Y"));
App.register_sensor(mpu6050->make_accel_z_sensor("MPU6050 Accel Z"));
App.register_sensor(mpu6050->make_gyro_x_sensor("MPU6050 Gyro X"));
App.register_sensor(mpu6050->make_gyro_y_sensor("MPU6050 Gyro Y"));
App.register_sensor(mpu6050->make_gyro_z_sensor("MPU6050 Gyro Z"));
App.register_sensor(mpu6050->make_temperature_sensor("MPU6050 Temperature"));

See Application::make_mpu6050_sensor().

API Reference

class MPU6050Component : public PollingComponent, public I2CDevice

Public Functions

sensor::MPU6050Component::MPU6050Component(I2CComponent * parent, uint8_t address = 0x68, uint32_t update_interval = 15000)
void setup()

Where the component’s initialization should happen.

Analogous to Arduino’s setup(). This method is guaranteed to only be called once. Defaults to doing nothing.

void dump_config()
void update()
float get_setup_priority() const

priority of setup().

higher -> executed earlier

Defaults to 0.

Return
The setup priority of this component

MPU6050AccelSensor *make_accel_x_sensor(const std::string &name)
MPU6050AccelSensor *make_accel_y_sensor(const std::string &name)
MPU6050AccelSensor *make_accel_z_sensor(const std::string &name)
MPU6050GyroSensor *make_gyro_x_sensor(const std::string &name)
MPU6050GyroSensor *make_gyro_y_sensor(const std::string &name)
MPU6050GyroSensor *make_gyro_z_sensor(const std::string &name)
MPU6050TemperatureSensor *make_temperature_sensor(const std::string &name)

Protected Attributes

MPU6050AccelSensor *accel_x_sensor_ = {nullptr}
MPU6050AccelSensor *accel_y_sensor_ = {nullptr}
MPU6050AccelSensor *accel_z_sensor_ = {nullptr}
MPU6050TemperatureSensor *temperature_sensor_ = {nullptr}
MPU6050GyroSensor *gyro_x_sensor_ = {nullptr}
MPU6050GyroSensor *gyro_y_sensor_ = {nullptr}
MPU6050GyroSensor *gyro_z_sensor_ = {nullptr}