/ README.rst
README.rst
  1  Introduction
  2  ============
  3  
  4  .. image:: https://readthedocs.org/projects/adafruit-circuitpython-ds1841/badge/?version=latest
  5      :target: https://circuitpython.readthedocs.io/projects/ds1841/en/latest/
  6      :alt: Documentation Status
  7  
  8  .. image:: https://img.shields.io/discord/327254708534116352.svg
  9      :target: https://adafru.it/discord
 10      :alt: Discord
 11  
 12  .. image:: https://github.com/adafruit/Adafruit_CircuitPython_DS1841/workflows/Build%20CI/badge.svg
 13      :target: https://github.com/adafruit/Adafruit_CircuitPython_DS1841/actions
 14      :alt: Build Status
 15  
 16  .. image:: https://img.shields.io/badge/code%20style-black-000000.svg
 17      :target: https://github.com/psf/black
 18      :alt: Code Style: Black
 19  
 20  CircuitPython library for the Maxim DS1841 I2C Logarithmic Resistor
 21  
 22  
 23  Dependencies
 24  =============
 25  This driver depends on:
 26  
 27  * `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_
 28  * `Bus Device <https://github.com/adafruit/Adafruit_CircuitPython_BusDevice>`_
 29  * `Register <https://github.com/adafruit/Adafruit_CircuitPython_Register>`_
 30  
 31  Please ensure all dependencies are available on the CircuitPython filesystem.
 32  This is easily achieved by downloading
 33  `the Adafruit library and driver bundle <https://circuitpython.org/libraries>`_.
 34  
 35  Installing from PyPI
 36  =====================
 37  On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
 38  PyPI <https://pypi.org/project/adafruit-circuitpython-ds1841/>`_. To install for current user:
 39  
 40  .. code-block:: shell
 41  
 42      pip3 install adafruit-circuitpython-ds1841
 43  
 44  To install system-wide (this may be required in some cases):
 45  
 46  .. code-block:: shell
 47  
 48      sudo pip3 install adafruit-circuitpython-ds1841
 49  
 50  To install in a virtual environment in your current project:
 51  
 52  .. code-block:: shell
 53  
 54      mkdir project-name && cd project-name
 55      python3 -m venv .env
 56      source .env/bin/activate
 57      pip3 install adafruit-circuitpython-ds1841
 58  
 59  Usage Example
 60  =============
 61  
 62  .. code-block:: python
 63  
 64      from time import sleep
 65      import board
 66      import busio
 67      import adafruit_ds1841
 68      from analogio import AnalogIn
 69  
 70      ####### NOTE ################
 71      # this example will not work with Blinka/rasberry Pi due to the lack of analog pins.
 72      # Blinka and Raspberry Pi users should run the "ds1841_blinka_simpletest.py" example
 73  
 74      # WIRING:
 75      # 1 Wire connecting  VCC to RH to make a voltage divider using the
 76      #   internal resistor between RH and RW
 77      # 2 Wire connecting RW to A0
 78  
 79      i2c = busio.I2C(board.SCL, board.SDA)
 80      ds1841 = adafruit_ds1841.DS1841(i2c)
 81      wiper_output = AnalogIn(board.A0)
 82  
 83      while True:
 84  
 85          ds1841.wiper = 127
 86          print("Wiper set to %d"%ds1841.wiper)
 87          voltage = wiper_output.value
 88          voltage *= 3.3
 89          voltage /= 65535
 90          print("Wiper voltage: %.2f"%voltage)
 91          print("")
 92          sleep(1.0)
 93  
 94          ds1841.wiper = 0
 95          print("Wiper set to %d"%ds1841.wiper)
 96          voltage = wiper_output.value
 97          voltage *= 3.3
 98          voltage /= 65535
 99          print("Wiper voltage: %.2f"%voltage)
100          print("")
101          sleep(1.0)
102  
103          ds1841.wiper = 63
104          print("Wiper set to %d"%ds1841.wiper)
105          voltage = wiper_output.value
106          voltage *= 3.3
107          voltage /= 65535
108          print("Wiper voltage: %.2f"%voltage)
109          print("")
110          sleep(1.0)
111  
112  
113  Contributing
114  ============
115  
116  Contributions are welcome! Please read our `Code of Conduct
117  <https://github.com/adafruit/Adafruit_CircuitPython_DS1841/blob/master/CODE_OF_CONDUCT.md>`_
118  before contributing to help this project stay welcoming.
119  
120  Documentation
121  =============
122  
123  For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.