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    # set th
29    ds1841.wiper = 127
30    print("Wiper set to %d" % ds1841.wiper)
31    voltage = wiper_output.value
32    voltage *= 3.3
33    voltage /= 65535
34    print("Wiper voltage: %.2f V" % voltage)
35    print("")
36    sleep(1.0)
37
38    ds1841.wiper = 0
39    print("Wiper set to %d" % ds1841.wiper)
40    voltage = wiper_output.value
41    voltage *= 3.3
42    voltage /= 65535
43    print("Wiper voltage: %.2f V" % voltage)
44    print("")
45    sleep(1.0)
46
47    ds1841.wiper = 63
48    print("Wiper set to %d" % ds1841.wiper)
49    voltage = wiper_output.value
50    voltage *= 3.3
51    voltage /= 65535
52    print("Wiper voltage: %.2f V" % voltage)
53    print("")
54    sleep(1.0)