Simple test

Ensure your device works with this simple test.

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