I have a B+ with an adafruit LCD character plate and DS18B20 temperature sensor. I currently have it displaying the current temperature and the max and min values reached on the LCD. However I have noticed that a lot of the time the max temp value follows the current temperature reading even if it is dropping ie. not the max temperature reached.
I hope some one can help me out with this! I suspect its to do with the refresh and sample values in the code but not entirely sure.
My current code is:
Code: Select all
# Import all the libraries
import Adafruit_CharLCD as LCD
from w1thermsensor import W1ThermSensor
import time
# Sample/Refresh time in seconds
refresh = 2
# Temperature history in values (history duration will be samples * refresh)
samples = 10
# Define and initialise the LCD
lcd = LCD.Adafruit_CharLCDPlate()
# Set Display Colour
lcd.set_color(0.0, 1.0, 0.0)
# Set Size
lcd_columns = 16
lcd_rows = 2
lcd.message("Logging\nBeginning.......")
# Define the temperature sensor
sensor = W1ThermSensor()
# Set up the history array
temp = sensor.get_temperature()
templist = [temp] * samples
try:
while True:
# Shift out the oldest temperature value
for x in range(len(templist)-1):
templist[x] = templist[x+1]
# Set the end item to be our current temperature
templist[len(templist)-1] = sensor.get_temperature()
# Uncomment the following line for debugging
print "max %.2f min %.2f\n" % (max(templist),min(templist))
# Display it on the LCD
lcd.set_cursor(0,0)
lcd.message(""" Temp %.2fC\n+%.2f -%.2f""" %
(templist[len(templist)-1],max(templist),min(templist)))
# Sleep until we need to sample/refresh
time.sleep(refresh)
except KeyboardInterrupt:
print "\n\nProgram Stopped By User\n"
lcd.clear()
lcd.message("Logging Aborted\nBy User........")
Many Thanks to anyone who can help!
Byron