If you would like to accurately log the temperature on the FunHouse using the onboard environmental sensors, one potential issue you may notice is that the sensors are near the power supply. The sensors are on an area of the board that is cut out to physically separate them from the power supply components and help mitigate the heating. This helps to an extent, but it is still affected. We wanted to keep the sensors low on the PCB (since heat rises) and also far away from the TFT backlight since it is also very warm.
There are a few things you can do to make the temperature more accurate, which we'll cover in this example. Mostly we will keep the board asleep as much as possible and keep the backlight off (or dim) to conserve power.
Full Example
Go ahead and click Download Project Bundle to download the full example and the required libraries. Rename funhouse_temperature_logger.py to code.py and copy all the files over to your FunHouse to run the Temperature Logger example. Make sure your secrets.py file includes your Adafruit IO information.
Adjust the variables at the top to your liking. You may see the display initialize at first, but once the script runs, it should turn off the backlight. Connect to the serial console to see the output and when it is logging the data. You can see the data being logged by connecting to Adafruit IO. To learn more, see our Welcome to Adafruit IO guide.
# SPDX-FileCopyrightText: 2017 Scott Shawcroft, written for Adafruit Industries # SPDX-FileCopyrightText: Copyright (c) 2021 Melissa LeBlanc-Williams for Adafruit Industries # # SPDX-License-Identifier: MIT """ This example demonstrates how to log temperature on the FunHouse. Due to the sensors being near the power supply, usage of peripherals generates extra heat. By turning off unused peripherals and back on only during usage, it can lower the heat. Using light sleep in between readings will also help. By using an offset, we can improve the accuracy even more. Improving airflow near the FunHouse will also help. """ from adafruit_funhouse import FunHouse funhouse = FunHouse(default_bg=None) DELAY = 180 FEED = "temperature" TEMPERATURE_OFFSET = 3 # Degrees C to adjust the temperature to compensate for board produced heat # Turn things off funhouse.peripherals.dotstars.fill(0) funhouse.display.brightness = 0 funhouse.network.enabled = False def log_data(): print("Logging Temperature") print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET)) # Turn on WiFi funhouse.network.enabled = True # Connect to WiFi funhouse.network.connect() # Push to IO using REST funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET) # Turn off WiFi funhouse.network.enabled = False while True: log_data() print(f"Sleeping for {DELAY} seconds...") funhouse.enter_light_sleep(DELAY)
Code Walkthrough
This example uses of the top levelĀ FunHouse layer and makes use of the network and peripherals. The code starts out with just the FunHouse import and instantiating the funhouse
object. Setting default_bg
to None causes the console output to be written to the display, but it doesn't really matter because the backlight will be off all the time.
from adafruit_funhouse import FunHouse funhouse = FunHouse(default_bg=None)
Next there are a few variables that you can change to match your needs. DELAY
is the amount of time in between each time the script checks the temperature and logs it. Decreasing the number will update more often, but because WiFi is turned on to log, it may increase the temperature slightly.
FEED
is the Adafruit IO feed that you would like to publish to. TEMPERATURE_OFFSET
is in degrees Celsius and will be subtracted from the measured temperature. The number will really depend on your specific setup to give more accuracy, so you will likely need to change this number. We will cover this more further down.
DELAY = 180 FEED = "temperature" TEMPERATURE_OFFSET = ( 3 # Degrees C to adjust the temperature to compensate for board produced heat )
We start off by immediately turning off the DotStar LEDs, display backlight, and WiFi.
# Turn things off funhouse.peripherals.dotstars.fill(0) funhouse.display.brightness = 0 funhouse.network.enabled = False
Next we create a function that will briefly turn on the WiFi, connect, and log the data. Then it will immediately shut it back off to reduce the heat. Since we are not maintaining a connection, it makes more sense to use the push_to_io
function and publish via REST.
def log_data(): print("Logging Temperature") print("Temperature %0.1F" % (funhouse.peripherals.temperature - TEMPERATURE_OFFSET)) # Turn on WiFi funhouse.network.enabled = True # Connect to WiFi funhouse.network.connect() # Push to IO using REST funhouse.push_to_io(FEED, funhouse.peripherals.temperature - TEMPERATURE_OFFSET) # Turn off WiFi funhouse.network.enabled = False
Finally there is the main loop. This loop is pretty basic and involves running the log_data()
function and using the light sleep functionality of the ESP32-S2 processor to conserve power and heat.
while True: log_data() print("Sleeping for {} seconds...".format(DELAY)) funhouse.enter_light_sleep(DELAY)
Adjusting the Offset
Some factors that can affect the temperature include the airflow around the FunHouse, positioning, and whether it is near insulating materials. For instance, if there is good airflow, this will naturally reduce the temperature. If the FunHouse is standing up as opposed to laying flat against a desk, this will also affect the temperature and is related to airflow. If the FunHouse is inside of a box that insulates the sensor, it will also be higher than if it's not near anything insulating.
This is why we wanted the OFFSET
variable to be easily settable. We went with about 3 degrees, which is more on the ideal side. One way you can tell the actual room temperature is by leaving the FunHouse unplugged for a while and then turning it on and seeing what the temperature is. It will rise to a certain amount and then you can use the difference to set the offset for your setup.
Page last edited January 21, 2025
Text editor powered by tinymce.