Skip to content

Commit b02b63d

Browse files
authored
Merge pull request #31 from pimoroni/temp-compensation
Improvements for #28 (Temperature compensation without sub process)
2 parents d64d5c0 + 0456541 commit b02b63d

File tree

3 files changed

+13
-12
lines changed

3 files changed

+13
-12
lines changed

examples/all-in-one-no-pm.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414

1515
from bme280 import BME280
1616
from enviroplus import gas
17-
from subprocess import PIPE, Popen
1817
from PIL import Image
1918
from PIL import ImageDraw
2019
from PIL import ImageFont
@@ -90,9 +89,10 @@ def display_text(variable, data, unit):
9089

9190
# Get the temperature of the CPU for compensation
9291
def get_cpu_temperature():
93-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
94-
output, _error = process.communicate()
95-
return float(output[output.index('=') + 1:output.rindex("'")])
92+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
93+
temp = f.read()
94+
temp = int(temp) / 1000.0
95+
return temp
9696

9797

9898
# Tuning factor for compensation. Decrease this number to adjust the

examples/all-in-one.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
from bme280 import BME280
1515
from pms5003 import PMS5003, ReadTimeoutError as pmsReadTimeoutError
1616
from enviroplus import gas
17-
from subprocess import PIPE, Popen
1817
from PIL import Image
1918
from PIL import ImageDraw
2019
from PIL import ImageFont
@@ -94,9 +93,10 @@ def display_text(variable, data, unit):
9493

9594
# Get the temperature of the CPU for compensation
9695
def get_cpu_temperature():
97-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
98-
output, _error = process.communicate()
99-
return float(output[output.index('=') + 1:output.rindex("'")])
96+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
97+
temp = f.read()
98+
temp = int(temp) / 1000.0
99+
return temp
100100

101101

102102
# Tuning factor for compensation. Decrease this number to adjust the

examples/luftdaten.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,12 @@ def read_values():
7878
return values
7979

8080

81-
# Get CPU temperature to use for compensation
81+
# Get the temperature of the CPU for compensation
8282
def get_cpu_temperature():
83-
process = Popen(['vcgencmd', 'measure_temp'], stdout=PIPE, universal_newlines=True)
84-
output, _error = process.communicate()
85-
return float(output[output.index('=') + 1:output.rindex("'")])
83+
with open("/sys/class/thermal/thermal_zone0/temp", "r") as f:
84+
temp = f.read()
85+
temp = int(temp) / 1000.0
86+
return temp
8687

8788

8889
# Get Raspberry Pi serial number to use as ID

0 commit comments

Comments
 (0)