ScrollPhat + EnviroPhat error

HI,

I am trying to get a python code working so i can display the temp on my scroll phat.

Here is the python script and error:

import sys
import string
import time
import scrollphat

from envirophat import weather

scrollphat.set_brightness(2)

while True:
try:
temp = weather.temperature()
scrollphat.write_string(temp)
print temp
time.sleep(4)

    except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)

With the error

Traceback (most recent call last):
File “tempd.py”, line 13, in
scrollphat.write_string(temp)
File “/usr/lib/python2.7/dist-packages/scrollphat/init.py”, line 68, in write_string
controller.write_string(chars,x)
File “/usr/lib/python2.7/dist-packages/scrollphat/IS31FL3730.py”, line 80, in write_string
for char in chars:
TypeError: ‘float’ object is not iterable

Any ideas ?

the value you get back for your temp variable is a float - you have to convert it to a string before you can display it on the scroll pHAT.

OK i have the pi showing the temp but how do i keep showing the new temp at 5 min intervals.

here is my code

import sys
import time
import scrollphat

from envirophat import weather

scrollphat.set_brightness(2)

scrollphat.clear()
temp = "The temp is " + str(weather.temperature())
scrollphat.write_string(temp,0)
length = scrollphat.buffer_len()

for i in range(length):
try:
scrollphat.scroll()
time.sleep(0.1)

    except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)

Ok i have it working

import sys
import time
import scrollphat

from envirophat import weather

scrollphat.set_brightness(2)

while True:
try:
print(“updating new temp to diplay”)
scrollphat.clear()
temp = "The temp is " + str(weather.temperature())
scrollphat.write_string(temp,0)
length = scrollphat.buffer_len()

            for i in range(length):
                    scrollphat.scroll()
                    time.sleep(0.1)
            scrollphat.clear()
            time.sleep(10)
    except KeyboardInterrupt:
            scrollphat.clear()
            sys.exit(-1)