Skip to content
This repository has been archived by the owner on Aug 25, 2023. It is now read-only.

Commit

Permalink
support MPU9255 without code change
Browse files Browse the repository at this point in the history
  • Loading branch information
hideakitai committed Mar 9, 2021
1 parent 70dcf5c commit d1241ba
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 16 deletions.
7 changes: 3 additions & 4 deletions MPU9250.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct MPU9250Setting {
ACCEL_DLPF_CFG accel_dlpf_cfg {ACCEL_DLPF_CFG::DLPF_45HZ};
};

template <typename WireType, uint8_t WHO_AM_I>
template <typename WireType>
class MPU9250_ {
static constexpr uint8_t MPU9250_DEFAULT_ADDRESS {0x68}; // Device address when ADO = 0
static constexpr uint8_t AK8963_ADDRESS {0x0C}; // Address of magnetometer
Expand Down Expand Up @@ -175,7 +175,7 @@ class MPU9250_ {
Serial.print("MPU9250 WHO AM I = ");
Serial.println(c, HEX);
}
return (c == WHO_AM_I);
return (c == MPU9250_WHOAMI_DEFAULT_VALUE) || (c == MPU9255_WHOAMI_DEFAULT_VALUE);
}

bool isConnectedAK8963() {
Expand Down Expand Up @@ -951,7 +951,6 @@ class MPU9250_ {
}
};

using MPU9250 = MPU9250_<TwoWire, MPU9250_WHOAMI_DEFAULT_VALUE>;
using MPU9255 = MPU9250_<TwoWire, MPU9255_WHOAMI_DEFAULT_VALUE>;
using MPU9250 = MPU9250_<TwoWire>;

#endif // MPU9250_H
14 changes: 2 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ This library is based on the [great work](https://github.com/kriswiner/MPU9250)
``` C++
#include "MPU9250.h"

MPU9250 mpu;
// MPU9255 mpu; // You can also use MPU9255
MPU9250 mpu; // You can also use MPU9255 as is

void setup() {
Serial.begin(115200);
Expand Down Expand Up @@ -40,8 +39,7 @@ void loop() {
``` C++
#include "MPU9250.h"

MPU9250 mpu;
// MPU9255 mpu; // You can also use MPU9255
MPU9250 mpu; // You can also use MPU9255 as is

void setup() {
Serial.begin(115200);
Expand Down Expand Up @@ -191,14 +189,6 @@ MPU9250Setting setting;
mpu.setup(0x70, setting, sw);
```

### MPU9255

To use MPU9255 instead of MPU9250, just declare MPU9255.

```C++
MPU9255 mpu;
```

## APIs

``` C++
Expand Down

0 comments on commit d1241ba

Please sign in to comment.