/ README.rst
README.rst
  1  Introduction
  2  ============
  3  
  4  .. image:: https://readthedocs.org/projects/adafruit-circuitpython-pcf8591/badge/?version=latest
  5      :target: https://circuitpython.readthedocs.io/projects/pcf8591/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_PCF8591/workflows/Build%20CI/badge.svg
 13      :target: https://github.com/adafruit/Adafruit_CircuitPython_PCF8591/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  ADC+DAC Combo
 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  
 38  
 39  On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from
 40  PyPI <https://pypi.org/project/adafruit-circuitpython-pcf8591/>`_. To install for current user:
 41  
 42  .. code-block:: shell
 43  
 44      pip3 install adafruit-circuitpython-pcf8591
 45  
 46  To install system-wide (this may be required in some cases):
 47  
 48  .. code-block:: shell
 49  
 50      sudo pip3 install adafruit-circuitpython-pcf8591
 51  
 52  To install in a virtual environment in your current project:
 53  
 54  .. code-block:: shell
 55  
 56      mkdir project-name && cd project-name
 57      python3 -m venv .env
 58      source .env/bin/activate
 59      pip3 install adafruit-circuitpython-pcf8591
 60  
 61  Usage Example
 62  =============
 63  
 64  .. code-block:: python3
 65  
 66      import time
 67      import board
 68  
 69      import adafruit_pcf8591.pcf8591 as PCF
 70      from adafruit_pcf8591.analog_in import AnalogIn
 71      from adafruit_pcf8591.analog_out import AnalogOut
 72  
 73      ############# AnalogOut & AnalogIn Example ##########################
 74      #
 75      # This example shows how to use the included AnalogIn and AnalogOut
 76      # classes to set the internal DAC to output a voltage and then measure
 77      # it with the first ADC channel.
 78      #
 79      # Wiring:
 80      # Connect the DAC output to the first ADC channel, in addition to the
 81      # normal power and I2C connections
 82      #
 83      #####################################################################
 84      i2c = board.I2C()
 85      pcf = PCF.PCF8591(i2c)
 86  
 87      pcf_in_0 = AnalogIn(pcf, PCF.A0)
 88      pcf_out = AnalogOut(pcf, PCF.OUT)
 89  
 90      while True:
 91  
 92          print("Setting out to ", 65535)
 93          pcf_out.value = 65535
 94          raw_value = pcf_in_0.value
 95          scaled_value = (raw_value / 65535) * pcf_in_0.reference_voltage
 96  
 97          print("Pin 0: %0.2fV" % (scaled_value))
 98          print("")
 99          time.sleep(1)
100  
101  
102  
103  Contributing
104  ============
105  
106  Contributions are welcome! Please read our `Code of Conduct
107  <https://github.com/adafruit/Adafruit_CircuitPython_PCF8591/blob/master/CODE_OF_CONDUCT.md>`_
108  before contributing to help this project stay welcoming.
109  
110  Documentation
111  =============
112  
113  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>`_.