logo elektroda
logo elektroda
X
logo elektroda

SHT25 Sensirion I2C Code for Reading Temperature and Humidity—Data Conversion Steps

207 12
ADVERTISEMENT
  • #1 21666104
    kiran B
    Anonymous  
  • ADVERTISEMENT
  • #2 21666105
    kiran B
    Anonymous  
  • ADVERTISEMENT
  • #3 21666106
    Steve Spence
    Anonymous  
  • #4 21666107
    kiran B
    Anonymous  
  • ADVERTISEMENT
  • #5 21666108
    kiran B
    Anonymous  
  • #6 21666109
    Todd Hayden
    Anonymous  
  • #7 21666110
    Mark Harrington
    Anonymous  
  • ADVERTISEMENT
  • #8 21666111
    Mark Harrington
    Anonymous  
  • #9 21666112
    kiran B
    Anonymous  
  • #10 21666113
    Mark Harrington
    Anonymous  
  • #11 21666114
    kiran B
    Anonymous  
  • #12 21666115
    Mark Harrington
    Anonymous  
  • #13 21666116
    Mark Harrington
    Anonymous  

Topic summary

✨ The discussion centers on coding challenges for reading temperature and humidity data from the Sensirion SHT25 sensor via I2C, focusing on data conversion steps to achieve high resolution (0.01°C) and accurate relative humidity measurements. The original code snippet is incomplete, prompting requests for detailed coding examples and clarification on data handling, including definitions of constants and buffer usage. Contributors highlight the importance of specifying the microcontroller (C8051F020), programming language (C with Keil C51 compiler), and resolution settings (8/12/14-bit modes) as per the sensor datasheet, which indicates typical accuracy of 1.8% RH. Issues reported include obtaining only 0.7°C resolution instead of 0.01°C and relative humidity readings exceeding 100%. Suggestions emphasize verifying test system accuracy, ensuring proper timing and instruction execution, and possibly rewriting critical code sections in assembly to reduce overhead. References to example code for similar sensors (SHT21) and requests for complete code, schematics, and detailed system parameters are made to facilitate troubleshooting. The discussion also touches on the cost and accessibility of development tools like Keil C51 and the need for manufacturer technical support with comprehensive system information.
Generated by the language model.

FAQ

TL;DR: To read SHT25 over I2C, use 14‑bit mode for ~0.01°C steps; “The datasheet suggests a 1.8%RH accuracy.” [Elektroda, Mark Harrington, post #21666110] Why it matters: This FAQ helps embedded developers fix 0.7°C step issues and >100% RH readings by applying the right conversion and timing.

Quick Facts

How do I get 0.01°C temperature resolution from an SHT25?

Enable 14‑bit temperature resolution and apply the datasheet conversion. Keep the raw 16‑bit word, clear status bits, and convert using the published linear formula. Use double or 32‑bit float to retain 0.01°C steps. “Use the highest resolution when you need accuracy.” [Sensirion, SHT2x Datasheet]

Why am I seeing 0.7°C steps instead of fine resolution?

You’re likely reading a lower resolution mode or truncating during conversion. Check the resolution setting in the user register and ensure integer math isn’t rounding early. Allow the specified measurement time before I2C read to avoid stale values. [Sensirion, SHT2x Datasheet]

My relative humidity shows over 100%. What’s wrong?

Two common causes: you didn’t clear the status bits before scaling, or you skipped linearization/temperature compensation. Also verify supply, timing, and CRC. Over‑range RH typically indicates a conversion or masking error, not a bad sensor. [Sensirion, SHT2x Datasheet]

What are the basic data conversion steps for SHT25 (I2C)?

1) Trigger temperature or humidity measurement. 2) Wait the specified conversion time. 3) Read MSB, LSB, and CRC; clear the lowest two status bits. 4) Apply the datasheet linear formula to get °C or %RH. 5) Optionally apply temperature compensation for RH. [Sensirion, SHT2x Datasheet]

How long should I wait after starting a measurement?

Respect the datasheet’s measurement time for the selected resolution. Reading too soon yields incorrect or stepped values. Many designs use continuous measurement to improve stability and reduce error. [Elektroda, Mark Harrington, post #21666110]

Is SHT21 code compatible with SHT25?

They share the same SHT2x command set and conversion approach. You can adapt SHT21 examples, but confirm device ID, user‑register bits, and timing for your target. Validate with CRC to catch porting mistakes. [Sensirion, SHT2x Datasheet]

Which resolution should I set for humidity and temperature?

Use 14‑bit temperature and 12‑bit humidity when you want peak resolution; lower settings reduce time and noise sensitivity. Match your timing, filtering, and power budget to the chosen mode. [Elektroda, Mark Harrington, post #21666110]

What causes CONNECTED_NOT_RESPONDING errors during reads?

Typical causes include missing pull‑ups, reading before conversion completes, or bus contention. Confirm I2C speed, watch start/stop timing, and verify ACKs. If possible, read the status register and CRC to isolate link versus conversion faults. [Sensirion, SHT2x Datasheet]

How do I clear the status bits correctly before scaling?

Mask the two LSBs of the raw 16‑bit value to zero before applying the scale formula. Those bits encode status and resolution; leaving them set skews your final °C/%RH. [Sensirion, SHT2x Datasheet]

Why do people recommend continuous conversions for better accuracy?

Continuous operation keeps the sensor thermally and electrically steady, reducing transient error and improving repeatability. It also helps average short‑term noise for more stable display readings. [Elektroda, Mark Harrington, post #21666110]

Can integer math cause precision loss on SHT25?

Yes. Doing the scale and offset in integers can quantize results severely. Use floating‑point or scaled fixed‑point with sufficient headroom, then round at the very end to your display resolution. [Sensirion, SHT2x Datasheet]

What’s a minimal 3‑step fix for >100% RH and coarse °C steps?

1) Set 14‑bit/12‑bit resolution in the user register. 2) Wait the full conversion time; then read MSB/LSB/CRC. 3) Mask status bits and apply the datasheet formulas with float math. [Sensirion, SHT2x Datasheet]

Do platform choices matter (e.g., C8051F020 with Keil C51)?

Any MCU works if it meets I2C timing and has precise math. Ensure watchdogs don’t preempt conversions and that your compiler’s float implementation matches expectations. Validate with CRC to catch bus glitches. [Elektroda, kiran B, post #21666114]

What’s a quick diagnostic when two boards read differently?

Swap sensors between boards. If the problem follows the sensor, inspect handling damage or environmental effects. If it stays with the board, probe pull‑ups, bus integrity, and timing. Log raw words and CRC to compare. [Elektroda, Todd Hayden, post #21666109]

Any expert tips from the thread before rewriting code?

Confirm requirements first: resolution, timing, and CPU details. “Always read the datasheet first before copying code and making purchases.” That saves hours of blind debugging. [Elektroda, Mark Harrington, post #21666110]
Generated by the language model.
ADVERTISEMENT