mrjoli021
Posts: 10
Joined: Tue Aug 25, 2015 5:17 pm

dynamic display of temperature

Wed Nov 20, 2019 8:43 pm

I have an I2C display that I am using to get weather and time information. I am not sure how to dynamically update the display. The code below grabs the current temperature and displays it on my screen. This works fine, but it does not update automatically. I would like for it to go out and fetch the temperature every 5 min.

All the methods I have used either makes everything being displayed flash constantly or I clear the screen completely for 5 min until next cycle. I am looking for a way to only change the temperature not the rest of what is being displayed.

Code: Select all

#wait 1 minute
time.sleep( 300 )
openWeather()

while True:
    #while variables
    Degree = chr(176)
    removeM = time.strftime('%p').strip('M') #removes M from AM or PM
    currentTemp = str(openWeather())
    useTemp = 0

    if str(openWeather()) != useTemp:
        mylcd.lcd_clear()
        useTemp = str(openWeather())
   
   #displays date in Hour:Minute:AM/PM  Month/Day/Year
    mylcd.lcd_display_string(time.strftime("%I:%M" + removeM + " %m/%d/%y " + useTemp +Degree), 1)
    mylcd.lcd_display_string(time.strftime(''), 2)
    mylcd.lcd_display_string(time.strftime("LAN= " + myIp()), 3)
    mylcd.lcd_display_string(time.strftime("WAN= " + publicIP()), 4)

pcmanbob
Posts: 9612
Joined: Fri May 31, 2013 9:28 pm
Location: Mansfield UK

Re: dynamic display of temperature

Thu Nov 21, 2019 11:26 am

Have you tried just adding a time.sleep to the end of the looping code, that way your loop will only run once every 5 min,

Code: Select all

while True:
    #while variables
    Degree = chr(176)
    removeM = time.strftime('%p').strip('M') #removes M from AM or PM
    currentTemp = str(openWeather())
    useTemp = 0

    if str(openWeather()) != useTemp:
        mylcd.lcd_clear()
        useTemp = str(openWeather())
   
   #displays date in Hour:Minute:AM/PM  Month/Day/Year
    mylcd.lcd_display_string(time.strftime("%I:%M" + removeM + " %m/%d/%y " + useTemp +Degree), 1)
    mylcd.lcd_display_string(time.strftime(''), 2)
    mylcd.lcd_display_string(time.strftime("LAN= " + myIp()), 3)
    mylcd.lcd_display_string(time.strftime("WAN= " + publicIP()), 4)
    time.sleep(300) # wait 5min
    
now you screen will clear once every 5min and them post the updated temp/time and all other data.

this is obviously just part of you r code so that's what my answer is based on.
We want information… information… information........................no information no help
The use of crystal balls & mind reading are not supported

Return to “Interfacing (DSI, CSI, I2C, etc.)”