Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
import time
import board
import busio
import adafruit_mlx90640
PRINT_TEMPERATURES = False
PRINT_ASCIIART = True
i2c = busio.I2C(board.SCL, board.SDA, frequency=800000)
mlx = adafruit_mlx90640.MLX90640(i2c)
print("MLX addr detected on I2C")
print([hex(i) for i in mlx.serial_number])
mlx.refresh_rate = adafruit_mlx90640.RefreshRate.REFRESH_2_HZ
frame = [0] * 768
while True:
stamp = time.monotonic()
try:
mlx.getFrame(frame)
except ValueError:
# these happen, no biggie - retry
continue
print("Read 2 frames in %0.2f s" % (time.monotonic() - stamp))
for h in range(24):
for w in range(32):
t = frame[h * 32 + w]
if PRINT_TEMPERATURES:
print("%0.1f, " % t, end="")
if PRINT_ASCIIART:
c = "&"
# pylint: disable=multiple-statements
if t < 20:
c = " "
elif t < 23:
c = "."
elif t < 25:
c = "-"
elif t < 27:
c = "*"
elif t < 29:
c = "+"
elif t < 31:
c = "x"
elif t < 33:
c = "%"
elif t < 35:
c = "#"
elif t < 37:
c = "X"
# pylint: enable=multiple-statements
print(c, end="")
print()
print()
|