tmp006_simpletest.py
1 import time 2 import board 3 import busio 4 import adafruit_tmp006 5 6 # Define a function to convert celsius to fahrenheit. 7 def c_to_f(c): 8 return c * 9.0 / 5.0 + 32.0 9 10 11 # Create library object using our Bus I2C port 12 i2c = busio.I2C(board.SCL, board.SDA) 13 sensor = adafruit_tmp006.TMP006(i2c) 14 15 # Initialize communication with the sensor, using the default 16 samples per conversion. 16 # This is the best accuracy but a little slower at reacting to changes. 17 # The first sample will be meaningless 18 while True: 19 obj_temp = sensor.temperature 20 print( 21 "Object temperature: {0:0.3F}*C / {1:0.3F}*F".format(obj_temp, c_to_f(obj_temp)) 22 ) 23 time.sleep(5.0)