Skip to content
Merged
Prev Previous commit
Next Next commit
code golfing; docs give priority to MCP3008
  • Loading branch information
2bndy5 committed Oct 20, 2019
commit 1173ea8b4bd23ff0e28547affc2e13acb3732741
2 changes: 0 additions & 2 deletions adafruit_mcp3xxx/mcp3002.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,7 @@ class MCP3002(MCP3xxx):

def read(self, pin, is_differential=False):
self._out_buf[0] = 0x40 | ((not is_differential) << 5) | (pin << 4)
# print([bin(x) for x in self._out_buf])
with self._spi_device as spi:
#pylint: disable=no-member
spi.write_readinto(self._out_buf, self._in_buf, out_end=2, in_end=2)
# print([bin(x) for x in self._in_buf])
return ((self._in_buf[0] & 0x03) << 8) | self._in_buf[1]
4 changes: 4 additions & 0 deletions adafruit_mcp3xxx/mcp3004.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,7 @@ class MCP3004(MCP3xxx):
(2, 3) : P2,
(3, 2) : P3
}

def __init__(self, spi_bus, cs, ref_voltage=3.3):
super(MCP3004, self).__init__(spi_bus, cs, ref_voltage=ref_voltage)
self._out_buf[0] = 0x01
4 changes: 4 additions & 0 deletions adafruit_mcp3xxx/mcp3008.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,7 @@ class MCP3008(MCP3xxx):
(6, 7) : P6,
(7, 6) : P7
}

def __init__(self, spi_bus, cs, ref_voltage=3.3):
super(MCP3008, self).__init__(spi_bus, cs, ref_voltage=ref_voltage)
self._out_buf[0] = 0x01
3 changes: 0 additions & 3 deletions adafruit_mcp3xxx/mcp3xxx.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,11 +74,8 @@ def read(self, pin, is_differential=False):
:param int pin: individual or differential pin.
:param bool is_differential: single-ended or differential read.
"""
self._out_buf[0] = 0x01
self._out_buf[1] = ((not is_differential) << 7) | (pin << 4)
print([bin(x) for x in self._out_buf])
with self._spi_device as spi:
#pylint: disable=no-member
spi.write_readinto(self._out_buf, self._in_buf)
print([bin(x) for x in self._in_buf])
return ((self._in_buf[1] & 0x03) << 8) | self._in_buf[2]
6 changes: 3 additions & 3 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ API
.. automodule:: adafruit_mcp3xxx.mcp3xxx
:members:

.. automodule:: adafruit_mcp3xxx.mcp3002
.. automodule:: adafruit_mcp3xxx.mcp3008
:members:
:exclude-members: read
:show-inheritance:

.. automodule:: adafruit_mcp3xxx.mcp3004
:members:
:show-inheritance:

.. automodule:: adafruit_mcp3xxx.mcp3008
.. automodule:: adafruit_mcp3xxx.mcp3002
:members:
:exclude-members: read
:show-inheritance:

.. automodule:: adafruit_mcp3xxx.analog_in
Expand Down
10 changes: 9 additions & 1 deletion docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,18 @@ Ensure your device works with this simple test.
:caption: examples/mcp3xxx_mcp3004_single_ended_simpletest.py
:linenos:

.. literalinclude:: ../examples/mcp3xxx_mcp3002_single_ended_simpletest.py
:caption: examples/mcp3xxx_mcp3002_single_ended_simpletest.py
:linenos:

.. literalinclude:: ../examples/mcp3xxx_mcp3008_differential_simpletest.py
:caption: examples/mcp3xxx_mcp3008_differential_simpletest.py
:linenos:

.. literalinclude:: ../examples/mcp3xxx_mcp3004_differential_simpletest.py
:caption: examples/mcp3xxx_mcp3004_differential_simpletest.py
:linenos:
:linenos:

.. literalinclude:: ../examples/mcp3xxx_mcp3002_differential_simpletest.py
:caption: examples/mcp3xxx_mcp3002_differential_simpletest.py
:linenos: