Skip to main content

To use MCP3008 with pigpio.

Project description

# Installing

Stable library from PyPi:

  • Just run pip install pimcp3008

# PiMcp3008’s Methods

## Constructor(config={})

‘config’ is dictionary type.

### ‘channel’

Configure SPI chip selects of Raspberry Pi.

  • Channel.CE0.value
    • CE0 is used for MCP3008

    • Default

  • Channel.CE1.value
    • CE1 is used for MCP3008

  • Channel.CE2.value
    • CE2 is used for MCP3008

    • Only Auxiliary Mode

### ‘clock’

Configure SPI clock of Raspberry Pi.

  • Integer value
    • Default: 1000000

### ‘device’

Configure MCP3008 compatible devices.

  • Device.MCP3008.value
    • Use MCP3008

    • Default

  • Device.MCP3004.value
    • Use MCP3004

## read(channels)

Read A/D convert value. Argument channels that enumerate integer value is valiable length. Return value has include selected channel’s value.

  • MCP3008: 0 to 7

  • MCP3004: 0 to 3

If argument channels is not exist, return value has include all channel’s value.

Return value is dictionary type. Key is channels value that type is int. Value is integer value.

# Sample

Run sudo pigpiod before running the sample.

## Simple

# -*- coding: utf-8 -*-
import pimpc3008 as MPC3008
import time

obj = MPC3008.PiMpc3008()

try:
    while True:
        values = obj.read()
        print(values)
        time.sleep(10)
except KeyboardInterrupt:
    pass

## Modify config

‘clock’ is 100kHz.

# -*- coding: utf-8 -*-
import pimpc3008 as MPC3008
import time

config = {
    'clock' : 100000
}

# pigpioを初期化する
obj = MPC3008.PiMpc3008(config)

try:
    while True:
        values = obj.read()
        print(values)
        time.sleep(10)
except KeyboardInterrupt:
    # Ctrl + C で終了する
    pass

## Select Channel

Get 0ch, 2ch and 4ch values.

# -*- coding: utf-8 -*-
import pimpc3008 as MPC3008
import time

obj = MPC3008.PiMpc3008()

try:
    while True:
        values = obj.read(0, 2, 4)
        print(values)
        time.sleep(10)
except KeyboardInterrupt:
    pass

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

pimcp3008-1.0.1.tar.gz (4.7 kB view details)

Uploaded Source

Built Distribution

pimcp3008-1.0.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pimcp3008-1.0.1.tar.gz.

File metadata

  • Download URL: pimcp3008-1.0.1.tar.gz
  • Upload date:
  • Size: 4.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for pimcp3008-1.0.1.tar.gz
Algorithm Hash digest
SHA256 bb45eeb1dfe2168faf5d27c80892a68c2b3287af2fc6b502c49d1c60eb38a7ab
MD5 93961a6af11aa4a07559d510234f8fe9
BLAKE2b-256 1e3adabc32a7dcdbe0fbef86038a00b9407541ffc86c5bf80101885c716932cd

See more details on using hashes here.

File details

Details for the file pimcp3008-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: pimcp3008-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.5.0 importlib_metadata/4.8.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.9

File hashes

Hashes for pimcp3008-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 6d64d73d80be5c2c074e4204be8786b4408cdf918aadf1f398ef6aa87721ee87
MD5 8dfca2548fa19bcae99a3da08ba89760
BLAKE2b-256 76ff4b8116d5b519d41b52f05f35ffa73ff1eaa1461e6d73247c7632b28d1f97

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