wollewald / MPU9250_WE

An Arduino library for the 9-axis accelerometer, gyroscope and magnetometer MPU9250 and MPU6500. It contains many example sketches make it easy to use.
https://wolles-elektronikkiste.de/en/mpu9250-9-axis-sensor-module-part-1
MIT License
56 stars 26 forks source link

Is this library support multiple MPU6500 using SPI? #9

Closed dayinji closed 2 years ago

dayinji commented 2 years ago

First of all thanks to the author.

I would like to know is this lib support multiple MPU6500 using SPI? I have an ESP32 board and more than 6 MPU6500 sensors. I try to connect them together and transfer datas by SPI. However, it seems that only one sensor connected successfully each time, while other sensor show 'not response' and they return wrong datas.

wollewald commented 2 years ago

Hi @dayinji , yes this is possible, but each MPU6500 needs a separate CS line.

For three MPU6500 modules it would look like this (please take appropriate pins - this shall only show the principle!):

const int csPin_1 = 10; 
const int csPin_2 = 11;
const int csPin_3 = 13;
bool useSPI = true;    // SPI use flag

MPU6500_WE myMPU6500_1 = MPU6500_WE(&SPI, csPin_1, useSPI);
MPU6500_WE myMPU6500_2 = MPU6500_WE(&SPI, csPin_2, useSPI);
MPU6500_WE myMPU6500_3 = MPU6500_WE(&SPI, csPin_3, useSPI);

I have not tried it but in theory this should work.

dayinji commented 2 years ago

Thanks ! It works.