allow temperature reads to converge a bit faster
[EVA-2020-02-2.git] / examples / all-in-one.py
index 413b0999be3c6cdc59e70ffdabb3f875972c8c19..ca0760b6e84f651a456921b88f5ed34f37a1c424 100755 (executable)
@@ -84,7 +84,7 @@ def display_text(variable, data, unit):
 
 # Get the temperature of the CPU for compensation
 def get_cpu_temperature():
-    process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE)
+    process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
     output, _error = process.communicate()
     return float(output[output.index('=') + 1:output.rindex("'")])
 
@@ -93,7 +93,7 @@ def get_cpu_temperature():
 # temperature down, and increase to adjust up
 factor = 0.8
 
-cpu_temps = [0] * 5
+cpu_temps = [get_cpu_temperature()] * 5
 
 delay = 0.5  # Debounce the proximity tap
 mode = 0  # The starting mode
@@ -198,7 +198,7 @@ try:
 
         if mode == 9:
             variable = "pm10"
-            unit = "g/m3"
+            unit = "ug/m3"
             data = pms5003.read()
             data = data.pm_ug_per_m3(10)
             display_text(variable, data, unit)