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