Skip to content

fix for offsets #4

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 12, 2025
Merged

fix for offsets #4

merged 1 commit into from
Mar 12, 2025

Conversation

mikeysklar
Copy link
Contributor

handle tuple input to match the docs, minimal change.

Tested on Pi 4, Bookworm Lite with HDC302x. Small change to have library accept tuple for offset values and unpack the tuple.

Forum issue

example code to set offsets with proposed patch:

import time
import board
import adafruit_hdc302x

i2c = board.I2C()
sensor = adafruit_hdc302x.HDC302x(i2c)

sensor.offsets = (1.5, -3.0)

while True:
    raw_temp = sensor.temperature
    raw_humidity = sensor.relative_humidity
    temp_offset, humidity_offset = sensor.offsets

    print(f"Raw Temperature: {raw_temp:0.1f}°C, Offset: {temp_offset:+0.1f}°C, Corrected: {raw_temp + temp_offset:0.1f}°C")
    print(f"Raw Humidity: {raw_humidity:0.1f}%, Offset: {humidity_offset:+0.1f}%, Corrected: {raw_humidity + humidity_offset:0.1f}%")
    print()

    time.sleep(2)

example output:

Raw Temperature: 20.9°C, Offset: +1.5°C, Corrected: 22.4°C
Raw Humidity: 55.7%, Offset: -2.9%, Corrected: 52.8%

Raw Temperature: 22.7°C, Offset: +1.5°C, Corrected: 24.2°C
Raw Humidity: 52.4%, Offset: -2.9%, Corrected: 49.5%

Raw Temperature: 22.7°C, Offset: +1.5°C, Corrected: 24.2°C
Raw Humidity: 52.4%, Offset: -2.9%, Corrected: 49.5%

Raw Temperature: 22.7°C, Offset: +1.5°C, Corrected: 24.2°C
Raw Humidity: 52.4%, Offset: -2.9%, Corrected: 49.5%

Raw Temperature: 22.7°C, Offset: +1.5°C, Corrected: 24.2°C
Raw Humidity: 52.4%, Offset: -2.9%, Corrected: 49.5%

handle tuple input to match the docs, minimal change.
@mikeysklar
Copy link
Contributor Author

@ladyada

@ladyada ladyada requested a review from BlitzCityDIY March 12, 2025 16:34
@BlitzCityDIY BlitzCityDIY merged commit d488c01 into adafruit:main Mar 12, 2025
1 check passed
adafruit-adabot added a commit to adafruit/Adafruit_CircuitPython_Bundle that referenced this pull request Mar 18, 2025
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.

2 participants