Skip to content

ESP32: Including Wire.h causes built-in IMU initialization to fail on Core Gray #366

Closed

Description

@niguragu

Summary

On M5Stack Core Gray, including Wire.h causes the built-in BMI270 IMU to fail initialization with M5GFX 0.2.33.

The failure occurs during sequential initialization and does not require concurrent I2C access, external sensor communication, or radio operations.

Environment

  • Board: M5Stack Core Gray (ESP32-D0WDQ6-V3, rev 3.1)
  • Board package: M5Stack ESP32 2.1.4 (Arduino-ESP32 2.0.14)
  • M5Unified: 0.2.26
  • M5GFX: 0.2.33
  • Built-in IMU: BMI270
  • FQBN: m5stack:esp32:m5stack_core

Steps to reproduce

  1. Build a sketch including Wire.h, M5Unified.h, and M5GFX.h.
  2. Initialize M5Unified and the built-in IMU using the diagnostic sketch.
  3. Read acceleration values repeatedly using M5.Imu.getAccel().
  4. Observe the IMU initialization status and successful read count.

The diagnostic uses the built-in IMU without external I2C devices or concurrent bus access.

Expected behavior

The built-in BMI270 should initialize successfully, and acceleration readings should succeed.

I2C bus initialization and release should not leave the bus unusable for subsequent initialization.

Actual behavior

With unmodified M5GFX 0.2.33:

  • The built-in BMI270 is not detected.
  • All 40 acceleration readings fail in the Wire-only regression test.
  • Reinitialization of M5GFX-owned I2C buses fails on both hardware ports.

Serial output

WIRE_ONLY_SUMMARY patched=0 samples=40 ok=0 auto_imu=0 auto_accel=0 pass=0
OWNED_SUMMARY port=0 cycles=10 init_ok=20/20 id_ok=10/20 closed_ok=0/10 pass=0
OWNED_SUMMARY port=1 cycles=10 init_ok=20/20 id_ok=10/20 closed_ok=0/10 pass=0

Additional observations

Instrumented execution shows the SDA/SCL output signal selectors changing from I2C signals 30/29 to GPIO 256/256.

During subsequent initialization, the bus is reported as externally owned (foreign_bus=1), despite having originally been initialized by M5GFX.

Earlier version comparisons also showed:

M5GFX M5Unified Successful acceleration reads
0.2.28 0.2.13 44/44
0.2.29 0.2.13 0/47

These results suggest a regression introduced between M5GFX 0.2.28 and 0.2.29.

Scope

The issue has been reproduced on M5Stack Core Gray with the environment specified above.

Other ESP32 variants and Arduino-ESP32 versions have not been tested.

An earlier blank-screen symptom has not been conclusively linked to this failure and is outside the scope of this report.

Activity

  1. ainyan03 commented on Oct 20, 2026

    @ainyan03
    Contributor

    Thank you for the detailed report and the fix. The fix is now merged into develop (#368) and will be in the next release.

    We reproduced it on an M5Stack Gray with the M5Stack 2.1.4 board package: with Wire.h included, the built-in IMU was not found (0/40 reads), and after M5.In_I2C.release() / begin() the SDA/SCL pins stayed routed as GPIO. With the fix the IMU is found (40/40) and the port can be released and opened again (10/10).

    The cause was as you described: the M5Stack 2.1.4 package does not ship core_version.h, so ARDUINO_ESP32_GIT_VER is undefined and Wire.end() was skipped on release. Your fix (WIRE_HAS_END) was taken as is, and #368 then moved the same decision into one place for the other path that ends and restores Wire (the temporary pin switcher). Without core_version.h it now uses esp_arduino_version.h (2.0.1 or later), because WIRE_HAS_END only appeared in core 2.0.5.

    If you can, please try the develop branch with your sketch; if it works for you, I believe this issue can be closed.

  2. niguragu commented on Oct 20, 2026

    @niguragu
    Author

    I tested the develop branch on my M5Stack Core Gray and confirmed that the issue is resolved.

    Thank you for the fix! This issue can be closed.

  3. ainyan03 commented on Oct 20, 2026

    @ainyan03
    Contributor

    Thank you for testing — the fix has now been released in M5GFX 0.2.34 (together with LovyanGFX 1.2.34). Please update to 0.2.34 from the library manager.

    Since you confirmed it on develop, feel free to close this issue whenever it suits you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions