Skip to content

fix i2c scann stalling on ESP32* boards - #538

Open
unlogisch04 wants to merge 7 commits into
mainfrom
fix/i2cscan_esp32
Open

fix i2c scann stalling on ESP32* boards#538
unlogisch04 wants to merge 7 commits into
mainfrom
fix/i2cscan_esp32

Conversation

@unlogisch04

Copy link
Copy Markdown
Contributor
  • Move Wire.end() to the correct position
  • ESP32-C6 Pin 0 and 9 Report all addresses
  • Fix wrong numbers/names in output

@unlogisch04

Copy link
Copy Markdown
Contributor Author

Still has some flaws in it.

@unlogisch04
unlogisch04 marked this pull request as ready for review July 29, 2026 13:38
@unlogisch04

Copy link
Copy Markdown
Contributor Author

Done changing stuff.

  • Now the correct ports are shown
  • On ESP32 changing i2c pins fixed (multiple positive hits till the SDA was changed)
  • Added what number represents SDA / SCL

I decided to leave my comments and "debug" prints in.

Tested with:

  • ESP8266 D1 Mini

  • SlimeVR 1.0 R11 Board

  • ESP32-C3 Beetle

  • ESP32-C6 Beetle

  • ESP32

  • IMU MPU9250, BNO085, ICM42668

@gorbit99 can you take a look at it

For later, we should move that code, so it uses the https://github.com/SlimeVR/SlimeVR-Tracker-ESP/blob/main/src/sensorinterface/I2CPCAInterface.h if possible.

Comment thread lib/i2cscan/i2cscan.cpp Outdated

currentSCL = 0;
currentSDA++;
void incvalidPortsIndex(uint8_t &index) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd personally write out "inc" as "increment"ú, admittedly I read "invalid" here and got very confused by the implementation

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah ok will change.

Comment thread lib/i2cscan/i2cscan.cpp Outdated
}

if (currentSDA >= validPorts.size()) {
bool incSDA(){

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here as above

Comment thread lib/i2cscan/i2cscan.cpp Outdated
Comment on lines +104 to +106
// Debug
// Serial.printf("CCCC currentSDAPortIndex: %d currentSCLPortIndex: %d validPortsIndex.size: %d\r\n",
// currentSDAPortIndex, currentSCLPortIndex, validPortsIndex.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to leave it in. For normal use it is not needed. But if you need to debug the code it is already here.

Comment thread lib/i2cscan/i2cscan.cpp Outdated
Comment on lines +171 to +175
// Debug
// for (const auto& portsIndex : validPortsIndex) {
// Serial.printf("Pin Index: %2d PinNum: %2d PinName: %s\r\n", portsIndex, portArray[portsIndex], portMap[portsIndex].c_str());
// }
// Serial.printf("startSDAPortIndex: %2d startSCLPortIndex: %2d\r\n", startSDAPortIndex, startSCLPortIndex);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to leave it in. For normal use it is not needed. But if you need to debug the code it is already here.

Comment thread lib/i2cscan/i2cscan.cpp Outdated
}
}

// Serial.printf_P(PSTR("[ERROR] [I2CSCAN] Default I2C Ports SDA: %d SCL: %d\r\n"), defaultSDAPin, defaultSCLPin);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to leave it in. For normal use it is not needed. But if you need to debug the code it is already here.

Comment thread lib/i2cscan/i2cscan.cpp Outdated
Comment on lines +188 to +190
// Debug
// Serial.printf("AAAA currentSDAPortIndex: %d currentSCLPortIndex: %d validPortsIndex.size: %d\r\n",
// currentSDAPortIndex, currentSCLPortIndex, validPortsIndex.size());

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove if not needed

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would love to leave it in. For normal use it is not needed. But if you need to debug the code it is already here.

@unlogisch04
unlogisch04 requested a review from gorbit99 July 31, 2026 10:36
unlogisch04 and others added 6 commits August 3, 2026 22:46
@unlogisch04

Copy link
Copy Markdown
Contributor Author

@gorbit99 can you recheck?

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants