i2cdevlib icon indicating copy to clipboard operation
i2cdevlib copied to clipboard

esp 32 mpu6050 with dmp not working in arduino ide

Open abhinmajix opened this issue 3 years ago • 14 comments

esp 32 mpu6050 with dmp not working with latest esp 32 boards 2.0.3. but it works with older 1.0.3 version. when using 2.0.3 dmp example able to upload but nothing coming up in serial monitor. is there anything to be initialized to work with esp 32 boards. iam using wemos lolin32

abhinmajix avatar May 18 '22 09:05 abhinmajix

I encounter the same issue

yufuping avatar May 23 '22 05:05 yufuping

Same problem here

isai17 avatar May 27 '22 16:05 isai17

This may help: https://github.com/jrowberg/i2cdevlib/issues/672#issuecomment-1120611043 I have not tested this.

ZHomeSlice avatar May 29 '22 07:05 ZHomeSlice

I use Arudino IDE with esp32 for Arduino 2.03, it doesn't work.

yufuping avatar May 31 '22 02:05 yufuping

same here

askuric avatar Jul 02 '22 09:07 askuric

I encounter the same issue

igcxl avatar Jul 07 '22 08:07 igcxl

hello, i encounter this issue too, and i take some time look into it, i found out the root cause, in the new version of esp32 for Arduino lib,they add semaphore lock to TwoWire driver, the beginTransmission funtion will take the semaphore and in the endTransmission function it will give the taken semaphore, 。 But in I2Cdev::readBytes function the i2c reading procedure is as follow ,before the requestFrom() the semphore is taken by beginTransmission function , so requestFrom will always pending on the taken semphore and no one will release it.

I2Cdev::readBytes useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); useWire->beginTransmission(devAddr); useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH));

There is two approach to fix , 1. comment the sencond beginTransmission function in both I2Cdev::readBytes and I2Cdev::readWords;(it is ok for ESP32 but i dont if it will break the other hardware platform ) or 2. add a definition #define CONFIG_DISABLE_HAL_LOCKS 1 in esp32 for Arduino lib to disable the semaphore lock.

GiveSomeColor avatar Jul 12 '22 06:07 GiveSomeColor

Worked fine for me!!!!! Thanks a lot for solving this!

ArtrixTech avatar Jul 18 '22 16:07 ArtrixTech

Awesome thanks!

askuric avatar Jul 18 '22 17:07 askuric

should we consider adding something like: #if not defined(ESP32)

Example:

I2Cdev::readBytes
useWire->beginTransmission(devAddr);
useWire->write(regAddr);
useWire->endTransmission();
#if not defined(ESP32)
useWire->beginTransmission(devAddr);
#endif
useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH));

ZHomeSlice avatar Jul 18 '22 18:07 ZHomeSlice

No, that spurious beginTransmission() call should just be removed. The requestFrom() call does the whole read transaction atomically. I thought this was gone already from other implementation, but it seems it's still there. I suspect that the duplicate operation is silently ignored in the AVR/SAM/SAMD core code, but it appears to cause a problem here. It can (and should) come out of all implementations.

There's a good explanation of what each of the main Wire library transaction functions do here, for reference:

https://github.com/Koepel/How-to-use-the-Arduino-Wire-library/wiki/Explanation-of-the-functions-of-the-Wire-library

jrowberg avatar Jul 18 '22 19:07 jrowberg

hello, i encounter this issue too, and i take some time look into it, i found out the root cause, in the new version of esp32 for Arduino lib,they add semaphore lock to TwoWire driver, the beginTransmission funtion will take the semaphore and in the endTransmission function it will give the taken semaphore, 。 But in I2Cdev::readBytes function the i2c reading procedure is as follow ,before the requestFrom() the semphore is taken by beginTransmission function , so requestFrom will always pending on the taken semphore and no one will release it.

I2Cdev::readBytes useWire->beginTransmission(devAddr); useWire->write(regAddr); useWire->endTransmission(); useWire->beginTransmission(devAddr); useWire->requestFrom((uint8_t)devAddr, (uint8_t)min((int)length - k, I2CDEVLIB_WIRE_BUFFER_LENGTH));

There is two approach to fix , 1. comment the sencond beginTransmission function in both I2Cdev::readBytes and I2Cdev::readWords;(it is ok for ESP32 but i dont if it will break the other hardware platform ) or 2. add a definition #define CONFIG_DISABLE_HAL_LOCKS 1 in esp32 for Arduino lib to disable the semaphore lock.

#633

#define CONFIG_DISABLE_HAL_LOCKS 1

chufusheng avatar Sep 27 '22 10:09 chufusheng

hello, I encountered this problem too ,and I think the current header i was using caused this problem. I changed another version of I2Cdev.h ,which I got form another project ,thus it worked .

alin2585 avatar Oct 06 '22 16:10 alin2585

Has this " solution" been edited in the library? after searching through I2CDev.h /.cpp & mpu6050.h/.cpp I am unable to find the above-mentioned portion to attempt the edit.

Aarpp avatar Apr 04 '23 19:04 Aarpp