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