read_temperature.py
1 """ 2 Example: Read Temperature 3 4 This example shows how to read temperature values in degrees from a temperature input module. 5 6 Temperature inputs are analog inputs that read data from a temperature sensor and convert it into a 7 temperature reading. These include thermistors, thermocouples and resistance temperature detectors (RTDs) 8 9 This example works with all P1000 Series: 10 - Temperature input modules such as P1-04NTC, P1-04RTD, and P1-04THM. 11 12 The default ranges are: 13 - P1-04THM: J-Type 14 - P1-04RTD: Pt100 15 - P1-04NTC: 2252 16 17 This example will print every channel's temperature to the serial monitor every second. 18 This can be tested by: 19 - Using an appropriate temperature probe for the module 20 - Shorting the positive and negative inputs of a THM module to read room temperature. 21 - Using a potentiometer to simulate thermistor/RTD signal on an NTC or RTD 22 module and using a temp. vs. resistance chart to verify values. 23 24 The reported temperature defaults to degrees Fahrenheit. 25 _____ _____ 26 | P || S | 27 | 1 || L | 28 | A || O | 29 | M || T | 30 | - || | 31 | 1 || 0 | 32 | 0 || 1 | 33 | 0 || | 34 ¯¯¯¯¯ ¯¯¯¯¯ 35 Written by FACTS Engineering 36 Copyright (c) 2023 FACTS Engineering, LLC 37 Licensed under the MIT license. 38 39 """ 40 41 import time 42 import P1AM 43 44 base = P1AM.Base() # Intializes base. Returns the base object. 45 module = base[1] # module object for slot 1 46 47 while module.not_ready: 48 pass # Wait for temperature module to be ready 49 50 while True: 51 # Loop through channel values 52 for idx, value in enumerate(module.values): 53 print(f"Channel {idx + 1} is reading {value} degrees F") 54 time.sleep(1)