Skip to main content

CircuitPython library for the MCP3xxx Analog-to-Digital converters.

Project description

Introduction

Documentation Status Discord Build Status Code Style: Black

CircuitPython library for the MCP3xxx series of analog-to-digital converters.

Currently supports:

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Installing from PyPI

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:

pip3 install adafruit-circuitpython-mcp3xxx

To install system-wide (this may be required in some cases):

sudo pip3 install adafruit-circuitpython-mcp3xxx

To install in a virtual environment in your current project:

mkdir project-name && cd project-name
python3 -m venv .venv
source .venv/bin/activate
pip3 install adafruit-circuitpython-mcp3xxx

Usage Example

MCP3008 Single Ended

import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)

print('Raw ADC Value: ', chan.value)
print('ADC Voltage: ' + str(chan.voltage) + 'V')

MCP3008 Differential

import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3008 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)

# create the mcp object
mcp = MCP.MCP3008(spi, cs)

# create a differential ADC channel between Pin 0 and Pin 1
chan = AnalogIn(mcp, MCP.P0, MCP.P1)

print('Differential ADC Value: ', chan.value)
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')

MCP3004 Single-Ended

import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3004 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)

# create the mcp object
mcp = MCP.MCP3004(spi, cs)

# create an analog input channel on pin 0
chan = AnalogIn(mcp, MCP.P0)

print('Raw ADC Value: ', chan.value)
print('ADC Voltage: ' + str(chan.voltage) + 'V')

MCP3004 Differential

import busio
import digitalio
import board
import adafruit_mcp3xxx.mcp3004 as MCP
from adafruit_mcp3xxx.analog_in import AnalogIn

# create the spi bus
spi = busio.SPI(clock=board.SCK, MISO=board.MISO, MOSI=board.MOSI)

# create the cs (chip select)
cs = digitalio.DigitalInOut(board.D5)

# create the mcp object
mcp = MCP.MCP3004(spi, cs)

# create a differential ADC channel between Pin 0 and Pin 1
chan = AnalogIn(mcp, MCP.P0, MCP.P1)

print('Differential ADC Value: ', chan.value)
print('Differential ADC Voltage: ' + str(chan.voltage) + 'V')

Documentation

API documentation for this library can be found on Read the Docs.

For information on building library documentation, please check out this guide.

Contributing

Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

adafruit-circuitpython-mcp3xxx-1.4.13.tar.gz (28.3 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file adafruit-circuitpython-mcp3xxx-1.4.13.tar.gz.

File metadata

File hashes

Hashes for adafruit-circuitpython-mcp3xxx-1.4.13.tar.gz
Algorithm Hash digest
SHA256 0c63e82ecaf825d33c2671efb1ed77f5f3802a44a683f82cf9f9457a63ea663f
MD5 cd51f287893dd166ad3495aecb12e024
BLAKE2b-256 00e7c27486aee354acbbe0df63139dec0e7ad16741ac3fd243fafc81dab3173b

See more details on using hashes here.

File details

Details for the file adafruit_circuitpython_mcp3xxx-1.4.13-py3-none-any.whl.

File metadata

File hashes

Hashes for adafruit_circuitpython_mcp3xxx-1.4.13-py3-none-any.whl
Algorithm Hash digest
SHA256 a2f1eb934aa89d5ead10b9efb75a2a0560ee8b1a3e5209ab42e502d2eb510453
MD5 ffa61562831fb3d014bb3086bcb30bc8
BLAKE2b-256 41a0aebf817f89c903cdedc75784008fd63c0534bd62e40c481a0292dbada010

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page