Simple test

Ensure your device works with this simple test.

examples/ds1841_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4from time import sleep
 5
 6import board
 7import busio
 8from analogio import AnalogIn
 9
10import adafruit_ds1841
11
12####### NOTE ################
13# this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
14# Blinka and Raspberry Pi users should run the "ds1841_blinka_simpletest.py" example
15
16# WIRING:
17# 1 Wire connecting  VCC to RH to make a voltage divider using the
18#   internal resistor between RH and RW
19# 2 Wire connecting RW to A0
20
21# setup of the i2c bus giving the SCL (clock) and SDA (data) pins from the board
22i2c = busio.I2C(board.SCL, board.SDA)
23# create the ds1841 instance giving the I2C bus we just set up
24ds1841 = adafruit_ds1841.DS1841(i2c)
25
26# set up an analog input, selecting the A0 pin
27wiper_output = AnalogIn(board.A0)
28
29while True:
30    # set th
31    ds1841.wiper = 127
32    print(f"Wiper set to {ds1841.wiper:d}")
33    voltage = wiper_output.value
34    voltage *= 3.3
35    voltage /= 65535
36    print(f"Wiper voltage: {voltage:.2f} V")
37    print("")
38    sleep(1.0)
39
40    ds1841.wiper = 0
41    print(f"Wiper set to {ds1841.wiper:d}")
42    voltage = wiper_output.value
43    voltage *= 3.3
44    voltage /= 65535
45    print(f"Wiper voltage: {voltage:.2f} V")
46    print("")
47    sleep(1.0)
48
49    ds1841.wiper = 63
50    print(f"Wiper set to {ds1841.wiper:d}")
51    voltage = wiper_output.value
52    voltage *= 3.3
53    voltage /= 65535
54    print(f"Wiper voltage: {voltage:.2f} V")
55    print("")
56    sleep(1.0)