diff --git a/ICM20948.h b/ICM20948.h index da4438d..00de8eb 100644 --- a/ICM20948.h +++ b/ICM20948.h @@ -215,6 +215,7 @@ class ICM20948 : public IMUInterface, public Logger /* Constructors */ ICM20948(uint8_t addr = 0x68) : _wire{&Wire}, i2cAddress{addr}, useSPI{false} {} ICM20948(TwoWire *w, uint8_t addr = 0x68) : _wire{w}, i2cAddress{addr}, useSPI{false} {} + ICM20948(TwoWire& w, uint8_t addr = 0x68) : _wire{&w}, i2cAddress{addr}, useSPI{false} {} ICM20948(SPIClass& s, int cs = -1) : _spi{&s}, csPin{cs}, useSPI{true} {} bool begin() override; diff --git a/MPU9250.h b/MPU9250.h index 171a73b..02b9a70 100644 --- a/MPU9250.h +++ b/MPU9250.h @@ -69,12 +69,10 @@ class MPU9250 : public IMUInterface, public Logger { WOM_RATE_500HZ = 0x0B }; MPU9250() {} - MPU9250(TwoWire *i2c, const I2cAddr addr) : - imu_(i2c, static_cast(addr)) {} - MPU9250(SPIClass *spi, const uint8_t cs = 255) : - imu_(spi, cs) {} - MPU9250(SPIClass& spi, const uint8_t cs = 255) : - imu_(&spi, cs) {} + MPU9250(TwoWire *i2c, const I2cAddr addr) : imu_(i2c, static_cast(addr)) {} + MPU9250(TwoWire& i2c, const I2cAddr addr = I2C_ADDR_PRIM) : imu_(&i2c, static_cast(addr)) {} + MPU9250(SPIClass *spi, const uint8_t cs = 255) : imu_(spi, cs) {} + MPU9250(SPIClass& spi, const uint8_t cs = 255) : imu_(&spi, cs) {} void config(TwoWire *i2c, const I2cAddr addr); void config(SPIClass *spi, const uint8_t cs); bool begin() override; diff --git a/README.md b/README.md index ad6b716..3e121a1 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,23 @@ Notice, that MPU6500 does not include a magnetometer, so magnetometer data will You can also use `` header and `MPU6500` class, which is an alias for `MPU9250` class. +#### I²C + +In case of using I²C connection (not recommended), the initialization would look like this: + +```cpp +#include +#include + +MPU9250 IMU(Wire); // the default address is used automatically + +void setup() { + Wire.begin(); + Wire.setClock(400000); // 400 kHz I²C clock + IMU.begin(); +} +``` + ### ICM-20948 The ICM-20948 IMU driver has the same interface. Only the declaration is changed in the example above: