Simple test
Ensure your device works with this simple test.
examples/as726x_simpletest.py
1# SPDX-FileCopyrightText: 2020 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4import time
5
6import board
7
8# for I2C use:
9from adafruit_as726x import AS726x_I2C
10
11# for UART use:
12# from adafruit_as726x import AS726x_UART
13
14# maximum value for sensor reading
15max_val = 16000
16
17# max number of characters in each graph
18max_graph = 80
19
20
21def graph_map(x):
22 return min(int(x * max_graph / max_val), max_graph)
23
24
25# for I2C use:
26i2c = board.I2C() # uses board.SCL and board.SDA
27# i2c = board.STEMMA_I2C() # For using the built-in STEMMA QT connector on a microcontroller
28sensor = AS726x_I2C(i2c)
29
30# for UART use:
31# uart = board.UART()
32# sensor = AS726x_UART(uart)
33
34sensor.conversion_mode = sensor.MODE_2
35
36while True:
37 # Wait for data to be ready
38 while not sensor.data_ready:
39 time.sleep(0.1)
40
41 # plot plot the data
42 print("\n")
43 print("V: " + graph_map(sensor.violet) * "=")
44 print("B: " + graph_map(sensor.blue) * "=")
45 print("G: " + graph_map(sensor.green) * "=")
46 print("Y: " + graph_map(sensor.yellow) * "=")
47 print("O: " + graph_map(sensor.orange) * "=")
48 print("R: " + graph_map(sensor.red) * "=")
49
50 time.sleep(1)