API¶
MCP3xxx
¶
CircuitPython Library for MCP3xxx ADCs with SPI
Author(s): ladyada, Brent Rubell
Implementation Notes¶
Hardware:
Adafruit MCP3008 8-Channel 10-Bit ADC with SPI (Product ID: 856)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://github.com/adafruit/circuitpython/releases
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
Note
The ADC chips’ input pins (AKA “channels”) are aliased in this library
as integer variables whose names start with “P” (eg MCP3008.P0
is channel 0 on the MCP3008
chip). Each module that contains a driver class for a particular ADC chip has these aliases
predefined accordingly. This is done for code readability and prevention of erroneous SPI
commands.
Important
The differential reads (comparisons done by the ADC chip) are limited to certain pairs of channels. These predefined pairs are referenced in this documentation as differential channel mappings. Please refer to the driver class of your ADC chip (MCP3008, MCP3004, MCP3002) for a list of available differential channel mappings.
- class adafruit_mcp3xxx.mcp3xxx.MCP3xxx(spi_bus: busio.SPI, cs: DigitalInOut, ref_voltage: float = 3.3)¶
This abstract base class is meant to be inherited by MCP3008, MCP3004, or MCP3002 child classes.
- Parameters:
spi_bus (SPIDevice) – SPI bus the ADC is connected to.
cs (DigitalInOut) – Chip Select Pin.
ref_voltage (float) – Voltage into (Vin) the ADC.
AnalogIn
¶
AnalogIn for single-ended and differential ADC readings.
Author(s): Brent Rubell
Warning
The ADC chips supported by this library do not use negative numbers. If the resulting
differential read is less than 0, then the returned integer value (and voltage value) is 0
.
If for some reason the voltage on a channel is greater than the reference voltage or
less than 0, then the returned integer value is 65535
or 0
respectively.
- class adafruit_mcp3xxx.analog_in.AnalogIn(mcp: MCP3xxx, positive_pin: int, negative_pin: int | None = None)¶
AnalogIn Mock Implementation for ADC Reads.
- Parameters:
MCP3008
¶
MCP3008 8-channel, 10-bit, analog-to-digital converter instance.
Author(s): Brent Rubell
For proper wiring, please refer to the Package Types diagram and Pin Description section of the MCP3004/MCP3008 datasheet.
- class adafruit_mcp3xxx.mcp3008.MCP3008(spi_bus: busio.SPI, cs: DigitalInOut, ref_voltage: float = 3.3)¶
Bases:
MCP3xxx
MCP3008 Differential channel mapping. The following list of available differential readings takes the form
(positive_pin, negative_pin) = (channel A) - (channel B)
.(P0, P1) = CH0 - CH1
(P1, P0) = CH1 - CH0
(P2, P3) = CH2 - CH3
(P3, P2) = CH3 - CH2
(P4, P5) = CH4 - CH5
(P5, P4) = CH5 - CH4
(P6, P7) = CH6 - CH7
(P7, P6) = CH7 - CH6
See also the warning in the AnalogIn class API.
MCP3004
¶
MCP3004 4-channel, 10-bit, analog-to-digital converter instance.
Author(s): Brent Rubell
For proper wiring, please refer to Package Types diagram and Pin Description section of the MCP3004/MCP3008 datasheet.
- class adafruit_mcp3xxx.mcp3004.MCP3004(spi_bus: busio.SPI, cs: DigitalInOut, ref_voltage: float = 3.3)¶
Bases:
MCP3xxx
MCP3004 Differential channel mapping. The following list of available differential readings takes the form
(positive_pin, negative_pin) = (channel A) - (channel B)
.(P0, P1) = CH0 - CH1
(P1, P0) = CH1 - CH0
(P2, P3) = CH2 - CH3
(P3, P2) = CH3 - CH2
See also the warning in the AnalogIn class API.
MCP3002
¶
MCP3002 2-channel, 10-bit, analog-to-digital converter instance.
Author(s): Brent Rubell, Brendan Doherty
For proper wiring, please refer to Package Type diagram and Pin Description section of the MCP3002 datasheet.
- class adafruit_mcp3xxx.mcp3002.MCP3002(spi_bus: busio.SPI, cs: DigitalInOut, ref_voltage: float = 3.3)¶
Bases:
MCP3xxx
MCP3002 Differential channel mapping. The following list of available differential readings takes the form
(positive_pin, negative_pin) = (channel A) - (channel B)
.(P0, P1) = CH0 - CH1
(P1, P0) = CH1 - CH0
See also the warning in the AnalogIn class API.