ds1841_lut_test.py
1 import time 2 import board 3 import busio 4 from analogio import AnalogIn 5 import adafruit_ds1841 6 7 # WIRING: 8 # 1 Wire connecting VCC to RH to make a voltage divider using the 9 # internal resistor between RH and RW 10 # 2 Wire connecting RW to A0 11 def wiper_voltage(_wiper_pin): 12 raw_value = _wiper_pin.value 13 return raw_value / (2 ** 16 - 1) * _wiper_pin.reference_voltage 14 15 16 i2c = busio.I2C(board.SCL, board.SDA) 17 ds = adafruit_ds1841.DS1841(i2c) 18 19 20 LUT_MAX_INDEX = 71 21 WIPER_MAX = 127 22 wiper_pin = AnalogIn(board.A0) 23 24 ds.lut_mode_enabled = True 25 26 # you only need to run this once per DS1841 since the LUT is stored to EEPROM 27 # for i in range(0, LUT_MAX_INDEX+1): 28 # new_lut_val = WIPER_MAX-i 29 # ds.set_lut(i, new_lut_val) 30 31 while True: 32 for i in range(0, LUT_MAX_INDEX + 1): 33 ds.lut_selection = i 34 # for printing to serial terminal: 35 print( 36 "\tLUTAR/LUT Selection: %s" % hex(ds.lut_selection), 37 "\tWiper = %d" % ds.wiper, 38 "\tWiper Voltage: %f" % wiper_voltage(wiper_pin), 39 ) 40 time.sleep(0.5) 41 42 # uncomment this and comment out the above to print out a mu plotter friendly format (tuple) 43 # print((wiper_voltage(wiper_pin),))