/ adafruit_mcp3xxx / mcp3004.py
mcp3004.py
 1  # The MIT License (MIT)
 2  #
 3  # Copyright (c) 2018 Brent Rubell for Adafruit
 4  #
 5  # Permission is hereby granted, free of charge, to any person obtaining a copy
 6  # of this software and associated documentation files (the "Software"), to deal
 7  # in the Software without restriction, including without limitation the rights
 8  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 9  # copies of the Software, and to permit persons to whom the Software is
10  # furnished to do so, subject to the following conditions:
11  #
12  # The above copyright notice and this permission notice shall be included in
13  # all copies or substantial portions of the Software.
14  #
15  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18  # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21  # THE SOFTWARE.
22  """
23  :py:class:`~adafruit_mcp3xxx.mcp3004.MCP3004`
24  ================================================
25  MCP3004 4-channel, 10-bit, analog-to-digital
26  converter instance.
27  
28  * Author(s): Brent Rubell
29  
30  For proper wiring, please refer to `Package Types diagram
31  <https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf#page=1>`_ and `Pin Description section
32  <https://cdn-shop.adafruit.com/datasheets/MCP3008.pdf#G1.1035093>`_ of the MCP3004/MCP3008
33  datasheet.
34  """
35  
36  from .mcp3xxx import MCP3xxx
37  
38  # MCP3004 Pin Mapping
39  P0 = 0
40  P1 = 1
41  P2 = 2
42  P3 = 3
43  
44  
45  class MCP3004(MCP3xxx):
46      """
47      MCP3004 Differential channel mapping. The following list of available differential readings
48      takes the form ``(positive_pin, negative_pin) = (channel A) - (channel B)``.
49  
50      - (P0, P1) = CH0 - CH1
51      - (P1, P0) = CH1 - CH0
52      - (P2, P3) = CH2 - CH3
53      - (P3, P2) = CH3 - CH2
54  
55      See also the warning in the `AnalogIn`_ class API.
56      """
57  
58      DIFF_PINS = {(0, 1): P0, (1, 0): P1, (2, 3): P2, (3, 2): P3}
59  
60      def __init__(self, spi_bus, cs, ref_voltage=3.3):
61          super(MCP3004, self).__init__(spi_bus, cs, ref_voltage=ref_voltage)
62          self._out_buf[0] = 0x01