I am using ESP32 with MPU6050_DMP6_ESPWiFi.ino file(The snippet of the mpu_setup() function is here
void mpu_setup()
{
// join I2C bus (I2Cdev library doesn't do this automatically)
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
Wire.begin();
Wire.setClock(100000); // 400kHz I2C clock. Comment this line if having compilation difficulties
#elif I2CDEV_IMPLEMENTATION == I2CDEV_BUILTIN_FASTWIRE
Fastwire::setup(400, true);
#endif
// initialize device
Serial.println(F("Initializing I2C devices..."));
mpu.initialize();
pinMode(INTERRUPT_PIN, INPUT);
// verify connection
Serial.println(F("Testing device connections..."));
Serial.println(mpu.testConnection() ? F("MPU6050 connection successful") : F("MPU6050 connection failed"));
// load and configure the DMP
Serial.println(F("Initializing DMP..."));
devStatus = mpu.dmpInitialize();
// supply your own gyro offsets here, scaled for min sensitivity
mpu.setXGyroOffset(220);
mpu.setYGyroOffset(76);
mpu.setZGyroOffset(-85);
mpu.setZAccelOffset(1788); // 1688 factory default for my test chip
// make sure it worked (returns 0 if so)
if (devStatus == 0) {
// turn on the DMP, now that it's ready
Serial.println(F("Enabling DMP..."));
mpu.setDMPEnabled(true);
// enable Arduino interrupt detection
Serial.println(F("Enabling interrupt detection (Arduino external interrupt 0)..."));
attachInterrupt(digitalPinToInterrupt(INTERRUPT_PIN), dmpDataReady, RISING);
mpuIntStatus = mpu.getIntStatus();
// set our DMP Ready flag so the main loop() function knows it's okay to use it
Serial.println(F("DMP ready! Waiting for first interrupt..."));
dmpReady = true;
// get expected DMP packet size for later comparison
packetSize = mpu.dmpGetFIFOPacketSize();
} else {
// ERROR!
// 1 = initial memory load failed
// 2 = DMP configuration updates failed
// (if it's going to break, usually the code will be 1)
Serial.print(F("DMP Initialization failed (code "));
Serial.print(devStatus);
Serial.println(F(")"));
}
}
This results in the following following behaviour
- A fresh powerup and running the code provides DMP outputs without any major issues for few seconds(One or two FIFO overflows occur as shown below). This is the output from a successful start on powerup. After few seconds, the
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
error occurs.
Output from a successful start
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Resetting MPU6050...
Disabling sleep mode...
Selecting user bank 16...
Selecting memory byte 6...
Checking hardware revision...
Revision @ user[16][6] = 4D
Resetting memory bank selection to 0...
Reading OTP bank valid flag...
OTP bank is valid!
Reading gyro offset TC values...
X gyro offset = 63
Y gyro offset = 0
Z gyro offset = 0
Setting slave 0 address to 0x7F...
Disabling I2C Master mode...
Setting slave 0 address to 0x68 (self)...
Resetting I2C Master control...
Writing DMP code to MPU memory banks (1929 bytes)
Success! DMP code written and verified.
Writing DMP configuration to MPU memory banks (192 bytes in config def)
Success! DMP configuration written and verified.
Setting clock source to Z Gyro...
Setting DMP and FIFO_OFLOW interrupts enabled...
Setting sample rate to 200Hz...
Setting external frame sync to TEMP_OUT_L[0]...
Setting DLPF bandwidth to 42Hz...
Setting gyro sensitivity to +/- 2000 deg/sec...
Setting DMP programm start address
Clearing OTP Bank flag...
Setting X/Y/Z gyro offset TCs to previous values...
Writing final memory update 1/7 (function unknown)...
Writing final memory update 2/7 (function unknown)...
Resetting FIFO...
Reading FIFO count...
Current FIFO count=0
Setting motion detection threshold to 2...
Setting zero-motion detection threshold to 156...
Setting motion detection duration to 80...
Setting zero-motion detection duration to 0...
Resetting FIFO...
Enabling FIFO...
Enabling DMP...
Resetting DMP...
Writing final memory update 3/7 (function unknown)...
Writing final memory update 4/7 (function unknown)...
Writing final memory update 5/7 (function unknown)...
Waiting for FIFO count > 2...
Current FIFO count=42
Reading FIFO data...
Reading interrupt status...
Current interrupt status=7
Reading final memory update 6/7 (function unknown)...
Waiting for FIFO count > 2...
Current FIFO count=42
Reading FIFO data...
Reading interrupt status...
Current interrupt status=3
Writing final memory update 7/7 (function unknown)...WiFi connected! IP address: 192.168.137.12
WiFi connected! IP address: 192.168.137.12
DMP is good to go! Finally.
Disabling DMP (you turn it on later)...
Setting up internal 42-byte (default) DMP packet buffer...
Resetting FIFO and clearing INT status one last time...
Enabling DMP...
Enabling interrupt detection (Arduino external interrupt 0)...
DMP ready! Waiting for first interrupt...
FIFO overflow!
ypr -66.46 -35.96 -42.60
- Any subsequent reset of ESP32(no power cycle of MPU/ESP32) results in either of the following errors
Error 1
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Resetting MPU6050...
Disabling sleep mode...
Selecting user bank 16...
Selecting memory byte 6...
Checking hardware revision...
Revision @ user[16][6] = 4D
Resetting memory bank selection to 0...
Reading OTP bank valid flag...
OTP bank is invalid!
Reading gyro offset TC values...
X gyro offset = 63
Y gyro offset = 0
Z gyro offset = 0
Setting slave 0 address to 0x7F...
Disabling I2C Master mode...
Setting slave 0 address to 0x68 (self)...
Resetting I2C Master control...
Writing DMP code to MPU memory banks (1929 bytes)
ERROR! DMP code verification failed.
DMP Initialization failed (code 1)
Error 2
Initializing I2C devices...
Testing device connections...
MPU6050 connection successful
Initializing DMP...
Resetting MPU6050...
Disabling sleep mode...
Selecting user bank 16...
Selecting memory byte 6...
Checking hardware revision...
Revision @ user[16][6] = 4D
Resetting memory bank selection to 0...
Reading OTP bank valid flag...
OTP bank is valid!
Reading gyro offset TC values...
X gyro offset = 63
Y gyro offset = 0
Z gyro offset = 0
Setting slave 0 address to 0x7F...
Disabling I2C Master mode...
Writing DMP code to MPU memory banks (1929 bytes)
Success! DMP code written and verified.
Writing DMP configuration to MPU memory banks (192 bytes in config def)
Success! DMP configuration written and verified.
Setting clock source to Z Gyro...
Setting DMP and FIFO_OFLOW interrupts enabled...
Setting sample rate to 200Hz...
Setting external frame sync to TEMP_OUT_L[0]...
Setting DLPF bandwidth to 42Hz...
Setting gyro sensitivity to +/- 2000 deg/sec...
Setting DMP programm start address
Clearing OTP Bank flag...
Setting X/Y/Z gyro offset TCs to previous values...
Writing final memory update 1/7 (function unknown)...
Writing final memory update 2/7 (function unknown)...
Resetting FIFO...
Reading FIFO count...
Current FIFO count=0
Setting motion detection threshold to 2...
Setting zero-motion detection threshold to 156...
Setting motion detection duration to 80...
Setting zero-motion detection duration to 0...
Resetting FIFO...
Enabling FIFO...
Enabling DMP...
Resetting DMP...
Writing final memory update 3/7 (function unknown)...
Writing final memory update 4/7 (function unknown)...
Writing final memory update 5/7 (function unknown)...
Waiting for FIFO count > 2...
Current FIFO count=42
Reading FIFO data...
Reading interrupt status...
Current interrupt status=7
Reading final memory update 6/7 (function unknown)...
Waiting for FIFO count > 2...
Current FIFO count=42
Reading FIFO data...
WiFi connected! IP address: 192.168.137.12
WiFi connected! IP address: 192.168.137.12
[E][esp32-hal-i2c.c:313] i2cRead(): Timeout! Addr: 68, index 42
Reading interrupt status...
Current interrupt status=[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
0
Writing final memory update 7/7 (function unknown)...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
DMP is good to go! Finally.
Disabling DMP (you turn it on later)...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
Setting up internal 42-byte (default) DMP packet buffer...
Resetting FIFO and clearing INT status one last time...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
Enabling DMP...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
Enabling interrupt detection (Arduino external interrupt 0)...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
DMP ready! Waiting for first interrupt...
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
- I have to power cycle the MPU to make it work(atleast for a short duration)
The changes made to stock code are
- Added BUFFER_LENGTH IN I2Cdev.h as
#ifdef ARDUINO
#if ARDUINO < 100
#include "WProgram.h"
#else
#include "Arduino.h"
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_ARDUINO_WIRE
#include <Wire.h>
#ifndef BUFFER_LENGTH
#ifdef TwoWire_h
#warning "i2c BUFFER_LENGTH not defined. Using I2C_BUFFER_LENGTH as BUFFER_LENGTH"
#define BUFFER_LENGTH I2C_BUFFER_LENGTH
#else
#warning "i2c BUFFER_LENGTH not defined. Check the Wire.h file for you hardware. Self-defining as 32."
#define BUFFER_LENGTH 32
#endif
#endif
#endif
#if I2CDEV_IMPLEMENTATION == I2CDEV_I2CMASTER_LIBRARY
#include <I2C.h>
#endif
#endif
- Reduced the Wire speed from 400Khz to 100Khz since 400Khz was causing i2c errors. Although 100Khz was also causing problems (but it worked at least for few seconds)
HARDWARE
ESP32 DoIT devkit connected to GY 521
ESP32 GY 521
VIN <=> VCC
22 <=> SCL
21 <=> SDA
GND <=> AD0
INT <=> VP
I am using ESP32 with MPU6050_DMP6_ESPWiFi.ino file(The snippet of the mpu_setup() function is here
This results in the following following behaviour
[E][esp32-hal-i2c.c:161] i2cWrite(): Busy Timeout! Addr: 68
error occurs.
Output from a successful start
Error 1
Error 2
The changes made to stock code are
HARDWARE
ESP32 DoIT devkit connected to GY 521
ESP32 GY 521
VIN <=> VCC
22 <=> SCL
21 <=> SDA
GND <=> AD0
INT <=> VP