Closed frozenmafia closed 2 years ago
What microcontroller are you using?
I am using esp32 vroom. I even failed at SPI communication. I have made connection like the following image.
If there is any mistake please do tell me. Thanking you
I'm not familiar enough with ESP32 to check the pinout without taking more time to figure out the labels. For I2C, ESP32 doesn't correctly support repeated starts, despite some attempts at reporting this bug to them. You would want to search my code for endTransmission(false) and replace it with endTransmission(). That should fix I2C communication, assuming that the wiring and everything else is good.
I have edited the code
bool Mpu9250::ReadRegisters(uint8_t reg, uint8_t count, uint8_t *data) {
if (iface_ == I2C) {
i2c_->beginTransmission(dev_);
i2c_->write(reg);
// i2c_->endTransmission(false);
i2c_->endTransmission();
bytes_rx_ = i2c_->requestFrom(static_cast<uint8_t>(dev_), count);
if (bytes_rx_ == count) {
for (std::size_t i = 0; i < count; i++) {
data[i] = i2c_->read();
}
return true;
} else {
return false;
}
} else {
spi_->beginTransaction(SPISettings(spi_clock_, MSBFIRST, SPI_MODE3));
#if defined(TEENSYDUINO)
digitalWriteFast(dev_, LOW);
#else
digitalWrite(dev_, LOW);
#endif
#if defined(__IMXRT1062__)
delayNanoseconds(50);
#endif
spi_->transfer(reg | SPI_READ_);
spi_->transfer(data, count);
#if defined(TEENSYDUINO)
digitalWriteFast(dev_, HIGH);
#else
digitalWrite(dev_, HIGH);
#endif
#if defined(__IMXRT1062__)
delayNanoseconds(50);
#endif
spi_->endTransaction();
return true;
}
}
Still same error , I think something is wrong with my sensor.
Hi, I have a similar problem, also with ESP32, different devboard though (Node32S), and GY-91 sensor board. The setup previously worked with another breakout board, with different library (). After I switched sensor board, the other library didn't work (https://github.com/hideakitai/MPU9250).
I found another, which reads the gyro and acc data, but not the magnetometer, and in this thread this lib was suggested (https://github.com/asukiaaa/MPU9250_asukiaaa/issues/22), but with this library it can't estabilish the communication. I tried replacing the endTransmission as you suggested, but it didn't work either.
Do you have maybe any suggestion what should I try? I'm not that familiar with low level communication, so far the libs I found worked just fine.
If you run an I2C scanner does it see the sensor? Are you certain that the board is an MPU-9250 and not an MPU-6500?
It sees the sensor (0x68), but I looked more into it and if I'm right, the magnetometer should actually have it's unique address, I tried to bypass the acc and gyro with writing 00000010 to 0x37, but it didn't show up. If I do it with my other sensor, a 0x0C address shows up. On the chip MP92 236LA 1833 is written, so I'm pretty sure it should be MPU-9250
Maybe it's a fake? You could modify my library to print out the WHO_AM_I byte, which is queried on this line: https://github.com/bolderflight/mpu9250/blob/main/src/mpu9250.cpp#L92
Or instead of returning false, modify the Begin method to return an integer based on where it is failing.
My MPU9250 looks exactly like this.
First I check i2c connections using the following code (I copied it from somewhere else):
I get the following output
Now here I am only able to detect 0x68 . But magnetormeter is not detected.
Then I uploaded i2c example from your library.
If there is any information missing please tell me so that I can properly frame the question.
Thanking you.