/ examples / tmp007_simpletest.py
tmp007_simpletest.py
 1  #!/usr/bin/python
 2  # Author: Adapted to CircuitPython by Jerry Needell
 3  #     Adafruit_Python_TMP example by Tony DiCola
 4  #
 5  
 6  import time
 7  import board
 8  import busio
 9  import adafruit_tmp007
10  
11  
12  # Define a function to convert celsius to fahrenheit.
13  def c_to_f(c):
14      return c * 9.0 / 5.0 + 32.0
15  
16  
17  # Create library object using our Bus I2C port
18  i2c = busio.I2C(board.SCL, board.SDA)
19  sensor = adafruit_tmp007.TMP007(i2c)
20  
21  
22  # Initialize communication with the sensor, using the default 16 samples per conversion.
23  # This is the best accuracy but a little slower at reacting to changes.
24  # The first sample will be meaningless
25  while True:
26      die_temp = sensor.die_temperature
27      print(
28          "   Die temperature: {0:0.3F}*C / {1:0.3F}*F".format(die_temp, c_to_f(die_temp))
29      )
30      obj_temp = sensor.temperature
31      print(
32          "Object temperature: {0:0.3F}*C / {1:0.3F}*F".format(obj_temp, c_to_f(obj_temp))
33      )
34      time.sleep(5.0)