Skip to content

Fix SHT2x detection for INA219 addresses#10482

Open
balya wants to merge 1 commit into
meshtastic:developfrom
balya:fix-ina219-sht2x-detection
Open

Fix SHT2x detection for INA219 addresses#10482
balya wants to merge 1 commit into
meshtastic:developfrom
balya:fix-ina219-sht2x-detection

Conversation

@balya
Copy link
Copy Markdown

@balya balya commented May 15, 2026

Summary

Fixes #10110.

This PR fixes false-positive SHT2x/SHTxx detection on I2C addresses shared with INA219/INA-series sensors.

INA219 can respond on 0x40/0x41, which overlaps with SHT2x probing. The previous SHT2x serial-number probe only checked that enough bytes were returned, so an INA219 could be incorrectly registered as SHTXX. That caused environment telemetry initialization to fail and prevented INA219 voltage readings from being reported correctly.

This change validates the SHT2x serial-number response using the Sensirion CRC-8 checksum before accepting the device as SHT2x. If the CRC validation fails, detection falls through to the existing INA detection path.

Testing

Tested on an ESP32-S3 E22 W5500 node with INA219 at I2C address 0x41.

Before this change, boot logs showed:

SHTXX (SHT2X) found at address 0x41
Init sensor: SHTXX
SHTXX: init(): failed

After this change, the same hardware is detected correctly:

Init sensor: INA219
Opened INA219 sensor on i2c bus
Using INA on I2C addr 0x41 for charging detection
DeviceTelemetry Send: ... battery_level=100, voltage=4.968000

🤝 Attestations

  • I have tested that my proposed changes behave as described.
  • I have tested that my proposed changes do not cause any obvious regressions on the following devices:
    • Heltec (Lora32) V3
    • LilyGo T-Deck
    • LilyGo T-Beam
    • RAK WisBlock 4631
    • Seeed Studio T-1000E tracker card
    • Other: ESP32-S3 E22 W5500 with INA219 on I2C address 0x41

@github-actions github-actions Bot added the bugfix Pull request that fixes bugs label May 15, 2026
@thebentern thebentern requested a review from Copilot May 15, 2026 12:46
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves I2C sensor detection by validating SHT2x serial-number responses before registering an overlapping INA-series address as SHTXX, addressing false positives that blocked INA219 telemetry.

Changes:

  • Adds Sensirion CRC-8 validation for SHT2x serial-number bytes.
  • Reads and checks both SHT2x serial-number response blocks before accepting the detection.
  • Allows failed SHT2x validation to fall through to existing INA219 detection behavior.

@thebentern thebentern requested a review from oscgonfer May 16, 2026 01:04
@oscgonfer
Copy link
Copy Markdown
Contributor

Good job. I don't have a sht21, but this looks good to me.

@oscgonfer
Copy link
Copy Markdown
Contributor

@Tomas-Kuchta-FPV You have a sht21 still, right? Can you give this a go?

@Tomas-Kuchta-FPV
Copy link
Copy Markdown

@Tomas-Kuchta-FPV You have a sht21 still, right? Can you give this a go?

Right I have it. But it's now integrated on a wall sadly, so I have no good access to it and also I don't want to mess with it anymore.

PXL_20260407_111515901.jpg

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

Labels

bugfix Pull request that fixes bugs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: INA219 detected as SHT21, fails to initialize.

4 participants