Skip to content

Conversation

@dem1tris
Copy link
Contributor

@dem1tris dem1tris commented Nov 3, 2025

fixes #7522
fixes #6835

Problem

The current SHT4x and SHT3x environment sensors distinguishing algorithm is wrong. It writes 0x89 and accepts only certain values returned.

registerValue = getRegisterValue(ScanI2CTwoWire::RegisterLocation(addr, 0x89), 2);
if (registerValue == 0x11a2 || registerValue == 0x11da || registerValue == 0x11f3 || registerValue == 0xe9c ||
    registerValue == 0xc8d) {
    type = SHT4X;
    logFoundDevice("SHT4X", (uint8_t)addr.address);
}

Actually, 0x89's answer from SHT4x is the unique serial number, according to the datasheet (p. 4.7).

Fix

The fixed code firstly checks for OPT3001, then uses 0x89 and considers any non-zero value as SHT4x. Otherwise, it's SHT3x. Also note that SHT3x will not respond to the 0x89, since its commands have 2-byte length, according to the datasheet.

🤝 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:
    • SHT41 sensor
    • Heltec (Lora32) V3
    • Heltec MeshNode T114

@dem1tris dem1tris force-pushed the fix-sht4x-sht3x-detection branch from f744ea9 to b25fed0 Compare November 3, 2025 11:06
@thebentern thebentern requested a review from Copilot November 3, 2025 12:15
@thebentern thebentern added the bugfix Pull request that fixes bugs label Nov 3, 2025
Copy link
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 refactors the I2C sensor detection logic for SHT4X, SHT31, and OPT3001 sensors that share the same I2C addresses (0x44 and 0x45). The detection order and logic have been improved for more reliable identification.

  • Changed the detection order to check OPT3001 first, then SHT4X, and finally SHT31 as the fallback
  • Simplified the SHT4X detection logic to check for any non-zero value at register 0x89 instead of checking for specific IDs
  • Added a debug log statement to trace register values during detection

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@thebentern thebentern merged commit 0a124b7 into meshtastic:develop Nov 3, 2025
82 of 87 checks passed
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]: SHT40 and SHT41 Temp Sensor is not usable, Output is shown as "NaN" [Bug]: SHT45 not data

2 participants