Simple test

Ensure your device works with this simple test.

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