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