Python Forum

Full Version: Raspberry Pi pygameui - Fails with error index out of range
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I am using pygame and pygameui because these were the examples that I found on Adafruit when I first started this project. I am reading values from a DHT22 temperature/humidity sensor and from a pressure sensor. After running for about 45 minutes, I get an error - list index out of range. text_shadow_surface = self.text_shadow_surfaces[index] from label.py line 225 in draw which is being called by view.py line 235 in draw child.draw() which is coming from scene.current.draw() __init__.py line 153 called by ui.run() (ui being my name for pygameui)

# Display static pressure
self.pressure_value = ui.Label (ui.Rect(270 ,next_pos, 100, label_height), '', halign=ui.LEFT)
self.add_child (self.pressure_value)

# Displaying humidity label
next_pos += label_height + BUFFER
self.hum_label = ui.Label (ui.Rect(130, next_pos, 100, label_height), "Humidity", halign=ui.LEFT)
self.add_child(self.hum_label)

# Display humidity
next_pos += label_height + BUFFER
self.hum_value = ui.Label(ui.Rect(130, next_pos, 80, label_height), '')
self.add_child (self.hum_value)

#Display run time
next_pos += (label_height + BUFFER) * 3
self.run_time_label = ui.Label (ui.Rect(MARGIN, next_pos, 200, label_height), "Run time:", halign=ui.LEFT)
self.add_child (self.run_time_label)

self.runtime_value = ui.Label (ui.Rect (MARGIN+100, next_pos, 100, label_height), ' ')
self.add_child (self.runtime_value)
*****
def set_pressure(self, pressure):
self.pressure_value.text = '%.2f' % pressure + " inches"

def set_temp_label(self, temp):
self.temp_value.text = '%.2f' % temp + ' F'

def set_hum_label (self, hum):
self.hum_value.text = '%.2f' % hum
*****

pressure_sensor = read_adc()
if pressure_sensor < 204.8:
pressure_sensor = 0
else:
pressure_sensor = ((pressure_sensor - 204.8) / (1024 - 204.8) * 4) * 4.01463133
pressure_values.append(pressure_sensor)
self.pitft.set_pressure(pressure_sensor)
temp_fail = False
try:
humidity, temperature = Adafruit_DHT.read_retry(TEMP_HUM_TYPE, TEMP_HUM_SENSOR_PIN)

except:
print "Failed to read temp"
temp_fail = True

if temp_fail == False:
# Convert C to F
temp_f = temperature * 9.0 / 5.0 + 32
temp_values.append(temp_f)
hum_values.append (humidity)
print temp_f, humidity
self.pitft.set_temp_label(temp_f)
self.pitft.set_hum_label (humidity)
curr_time = time.time()
if temp_f > TEMP_ALERT:
email_s.send_email("Alert","OVER TEMP")