Skip to content
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

Add usb temp compensation to weather #160

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 18 additions & 3 deletions enviro/boards/weather.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from breakout_ltr559 import BreakoutLTR559
from machine import Pin, PWM
from pimoroni import Analog
from enviro import i2c, activity_led
from enviro import i2c, activity_led, config
import enviro.helpers as helpers
from phew import logging
from enviro.constants import WAKE_REASON_RTC_ALARM, WAKE_REASON_BUTTON_PRESS
Expand Down Expand Up @@ -190,10 +190,25 @@ def get_sensor_readings(seconds_since_last, is_usb_power):
ltr_data = ltr559.get_reading()
rain, rain_per_second = rainfall(seconds_since_last)

temperature = bme280_data[0]
humidity = bme280_data[2]

# Compensate for additional heating when on usb power - this also changes the
# relative humidity value.
if is_usb_power:
logging.info(f" - recorded temperature: {temperature}")
logging.info(f" - recorded humidity: {humidity}")
adjusted_temperature = temperature - config.usb_power_temperature_offset
absolute_humidity = helpers.relative_to_absolute_humidity(humidity, temperature)
humidity = helpers.absolute_to_relative_humidity(absolute_humidity, adjusted_temperature)
temperature = adjusted_temperature
logging.info(f" - USB adjusted temperature: {temperature}")
logging.info(f" - USB adjusted humidity: {humidity}")

from ucollections import OrderedDict
return OrderedDict({
"temperature": round(bme280_data[0], 2),
"humidity": round(bme280_data[2], 2),
"temperature": round(temperature, 2),
"humidity": round(humidity, 2),
"pressure": round(bme280_data[1] / 100.0, 2),
"luminance": round(ltr_data[BreakoutLTR559.LUX], 2),
"wind_speed": wind_speed(),
Expand Down
2 changes: 1 addition & 1 deletion enviro/config_template.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,5 +52,5 @@
moisture_target_b = 50
moisture_target_c = 50

# compensate for usb power
# compensate for usb power - degrees to remove from measured temperature
usb_power_temperature_offset = 4.5