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