Simple test

Ensure your device works with this simple test.

examples/ds3502_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4from time import sleep
 5
 6import board
 7from analogio import AnalogIn
 8
 9import adafruit_ds3502
10
11####### NOTE ################
12# this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
13# Blinka and Raspberry Pi users should run the "ds3502_blinka_simpletest.py" example
14
15i2c = board.I2C()  # uses board.SCL and board.SDA
16# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
17ds3502 = adafruit_ds3502.DS3502(i2c)
18wiper_output = AnalogIn(board.A0)
19
20while True:
21    ds3502.wiper = 127
22    print(f"Wiper set to {ds3502.wiper:d}")
23    voltage = wiper_output.value
24    voltage *= 3.3
25    voltage /= 65535
26    print(f"Wiper voltage: {voltage:.2f} V")
27    print("")
28    sleep(1.0)
29
30    ds3502.wiper = 0
31    print(f"Wiper set to {ds3502.wiper:d}")
32    voltage = wiper_output.value
33    voltage *= 3.3
34    voltage /= 65535
35    print(f"Wiper voltage: {voltage:.2f} V")
36    print("")
37    sleep(1.0)
38
39    ds3502.wiper = 63
40    print(f"Wiper set to {ds3502.wiper:d}")
41    voltage = wiper_output.value
42    voltage *= 3.3
43    voltage /= 65535
44    print(f"Wiper voltage: {voltage:.2f} V")
45    print("")
46    sleep(1.0)