Python Forum
Raspberry Pi pygameui - Fails with error index out of range
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Raspberry Pi pygameui - Fails with error index out of range
#1
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")
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  index error when using lists to blit rotated images codefun45 7 3,542 Sep-03-2020, 11:11 PM
Last Post: codefun45
  [IndexError: List Index out of Range] RPG Game Donovan 3 2,277 Aug-31-2020, 12:41 AM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020