Skip to content

Commit 43bb1b7

Browse files
authored
Merge pull request #14 from brentru/update-examples
Updating README and RTD examples
2 parents 7da1a49 + e21fa0a commit 43bb1b7

File tree

3 files changed

+80
-15
lines changed

3 files changed

+80
-15
lines changed

README.rst

Lines changed: 67 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ Usage Example
3535
=============
3636

3737

38-
Single Ended
39-
------------
38+
MCP3008 Single Ended
39+
---------------------
4040

4141
.. code-block:: python
4242
4343
import busio
4444
import digitalio
4545
import board
46-
from adafruit_mcp3xxx.mcp3008 import MCP3008
46+
import adafruit_mcp3xxx.mcp3008 as MCP
4747
from adafruit_mcp3xxx.analog_in import AnalogIn
4848
4949
# create the spi bus
@@ -52,42 +52,95 @@ Single Ended
5252
# create the cs (chip select)
5353
cs = digitalio.DigitalInOut(board.D5)
5454
55-
# create the mcp object from MCP3008 class
56-
mcp = MCP3008(spi, cs)
55+
# create the mcp object
56+
mcp = MCP.MCP3008(spi, cs)
5757
5858
# create an analog input channel on pin 0
59-
chan = AnalogIn(mcp, MCP3008.pin_0)
59+
chan = AnalogIn(mcp, MCP.P0)
6060
6161
print('Raw ADC Value: ', chan.value)
6262
print('ADC Voltage: ' + str(chan.voltage) + 'V')
6363
6464
65-
Differential
66-
------------
65+
MCP3008 Differential
66+
--------------------
6767

6868
.. code-block:: python
6969
7070
import busio
7171
import digitalio
7272
import board
73-
from adafruit_mcp3xxx.mcp3008 import MCP3008
74-
from adafruit_mcp3xxx.differential_analog_in import DifferentialAnalogIn
73+
import adafruit_mcp3xxx.mcp3008 as MCP
74+
from adafruit_mcp3xxx.analog_in import AnalogIn
7575
7676
# create the spi bus
7777
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
7878
7979
# create the cs (chip select)
8080
cs = digitalio.DigitalInOut(board.D5)
8181
82-
# create the mcp object from MCP3008 class
83-
mcp = MCP3008(spi, cs)
82+
# create the mcp object
83+
mcp = MCP.MCP3008(spi, cs)
8484
85-
# create a differential analog input channel with pin 0 and pin 1
86-
chan = DifferentialAnalogIn(mcp, MCP3008.pin_0, MCP3008.pin_1)
85+
# create a differential ADC channel between Pin 0 and Pin 1
86+
chan = AnalogIn(mcp, MCP.P0, MCP.P1)
8787
8888
print('Differential ADC Value: ', chan.value)
8989
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')
9090
91+
MCP3004 Single-Ended
92+
---------------------
93+
94+
.. code-block:: python
95+
96+
import busio
97+
import digitalio
98+
import board
99+
import adafruit_mcp3xxx.mcp3004 as MCP
100+
from adafruit_mcp3xxx.analog_in import AnalogIn
101+
102+
# create the spi bus
103+
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
104+
105+
# create the cs (chip select)
106+
cs = digitalio.DigitalInOut(board.D5)
107+
108+
# create the mcp object
109+
mcp = MCP.MCP3004(spi, cs)
110+
111+
# create an analog input channel on pin 0
112+
chan = AnalogIn(mcp, MCP.P0, MCP.P1)
113+
114+
print('Raw ADC Value: ', chan.value)
115+
print('ADC Voltage: ' + str(chan.voltage) + 'V')
116+
117+
MCP3004 Differential
118+
--------------------
119+
120+
.. code-block:: python
121+
122+
import busio
123+
import digitalio
124+
import board
125+
import adafruit_mcp3xxx.mcp3004 as MCP
126+
from adafruit_mcp3xxx.analog_in import AnalogIn
127+
128+
# create the spi bus
129+
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)
130+
131+
# create the cs (chip select)
132+
cs = digitalio.DigitalInOut(board.D5)
133+
134+
# create the mcp object
135+
mcp = MCP.MCP3004(spi, cs)
136+
137+
# create a differential ADC channel between Pin 0 and Pin 1
138+
chan = AnalogIn(mcp, MCP.P0, MCP.P1)
139+
140+
print('Differential ADC Value: ', chan.value)
141+
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')
142+
143+
91144
92145
Contributing
93146
============

docs/api.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ API
22
------------
33

44
.. automodule:: adafruit_mcp3xxx
5-
:members:
5+
:members:

docs/examples.rst

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,15 @@ Ensure your device works with this simple test.
66
.. literalinclude:: ../examples/mcp3008_single_ended_simpletest.py
77
:caption: examples/mcp3008_single_ended_simpletest.py
88
:linenos:
9+
10+
.. literalinclude:: ../examples/mcp3004_single_ended_simpletest.py
11+
:caption: examples/mcp3004_single_ended_simpletest.py
12+
:linenos:
13+
14+
.. literalinclude:: ../examples/mcp3008_differential_simpletest.py
15+
:caption: mcp3008_differential_simpletest.py
16+
:linenos:
17+
18+
.. literalinclude:: ../examples/mcp3004_differential_simpletest.py
19+
:caption: mcp3004_differential_simpletest.py
20+
:linenos:

0 commit comments

Comments
 (0)