-
Notifications
You must be signed in to change notification settings - Fork 14
/
read_max.py
53 lines (43 loc) · 1.77 KB
/
read_max.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/usr/bin/env python3
# This file is part of HoneyPi [honey-pi.de] which is released under Creative Commons License Attribution-NonCommercial-ShareAlike 3.0 Unported (CC BY-NC-SA 3.0).
# See file LICENSE or go to http://creativecommons.org/licenses/by-nc-sa/3.0/ for full license details.
from sensors.MAX6675 import MAX6675
from sensors.MAX31855 import MAX31855
import RPi.GPIO as GPIO
import logging
logger = logging.getLogger('HoneyPi.read_max')
def measure_tc(tc_sensor):
# get sensor pins
pin_cs = 26
pin_clock = 18
pin_miso = 19
max_type = 6675
try:
pin_cs = int(tc_sensor["pin_cs"])
pin_clock = int(tc_sensor["pin_clock"])
pin_miso = int(tc_sensor["pin"])
max_type = int(tc_sensor["max_type"])
except Exception as ex:
logger.error("MAX6675/MAX31855 missing param: " + repr(ex))
tc_temperature = None
# setup tc-Sensor
try:
tc = None
if max_type == 6675:
tc = MAX6675(cs_pin = pin_cs, clock_pin = pin_clock, data_pin = pin_miso, units = "c", board = GPIO.BCM)
elif max_type == 31855:
tc = MAX31855(cs_pin = pin_cs, clock_pin = pin_clock, data_pin = pin_miso, units = "c", board = GPIO.BCM)
except Exception as ex:
logger.exception("Init MAX6675/MAX31855 failed.")
if tc is not None:
try:
# get data
tc_temperature = tc.get()
if 'offset' in tc_sensor:
offset = float(tc_sensor["offset"])
tc_temperature = tc_temperature-offset
except Exception as ex:
logger.exception("Reading MAX6675/MAX31855 failed.")
if 'ts_field' in tc_sensor and tc_temperature is not None:
return ({tc_sensor["ts_field"]: round(tc_temperature, 1)})
return {}