-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmax31855_example.py
More file actions
48 lines (34 loc) · 1.52 KB
/
max31855_example.py
File metadata and controls
48 lines (34 loc) · 1.52 KB
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
# To use this example, connect the MAX31855 CS to pin 3
import time
from mcp2210 import Mcp2210, Mcp2210GpioDesignation
mcp = Mcp2210(serial_number="0000992816")
mcp.configure_spi_timing(chip_select_to_data_delay=0,
last_data_byte_to_cs=0,
delay_between_bytes=0)
mcp.set_spi_mode(0)
mcp.set_gpio_designation(3, Mcp2210GpioDesignation.CHIP_SELECT)
while 1:
response = mcp.spi_exchange(b'\x00' * 4, cs_pin_number=3)
print("##############################")
print("received:", ' '.join("{:02X}".format(x) for x in response))
response_merged = (response[0] << 24) | (response[1] << 16) | (response[2] << 8) | response[3]
thermocouple_temp_raw = (response_merged & 0xFFFC0000) >> 18
if thermocouple_temp_raw & (1 << 13):
thermocouple_temp = ((thermocouple_temp_raw & 0x1FFF) ^ 0x1FFF) * -0.25
else:
thermocouple_temp = thermocouple_temp_raw * 0.25
internal_temp_raw = (response_merged >> 4) & 0xFFF
if internal_temp_raw & (1 << 11):
internal_temp = (internal_temp_raw ^ 0x7FF) * -0.0625
else:
internal_temp = internal_temp_raw * 0.0625
print()
print("fault:", (response_merged & (1 << 16)) != 0)
print("open circuit:", (response_merged & (1 << 0)) != 0)
print("short to GND:", (response_merged & (1 << 1)) != 0)
print("short to VCC:", (response_merged & (1 << 2)) != 0)
print()
print("thermocouple temp:", thermocouple_temp)
print("internal temp:", internal_temp)
print("\n")
time.sleep(1)