Latest version

Released:

Sep 21, 2016  MCP3208 SPI ADC Interfacing with Raspberry Pi. September 21, 2016 November 14, 2017 Bikash Panda. The MCP3208 12-bit Analog-to-Digital Converter (ADC) combines high performance and low power consumption in a small package, making it ideal for embedded control applications. IC features a successive approximation register (SAR) architecture.

A python library for MCP3208

Project description

MCP3208

This is a python library designed to work with the MCP3208 ADC using SPI on a Raspberry Pi. The MCP3208 is capable of:

Maui meta 3g imei change download. The yellow color will appear in the circle if the device is successfully connected. Next switch off your phone and connect it with your computer using USB cable.

  • 12-bit resolution
  • ±1 LSB max DNL
  • ±1 LSB max INL (MCP3204/3208-B)
  • ±2 LSB max INL (MCP3204/3208-C)
  • 4 (MCP3204) or 8 (MCP3208) input channels
  • Analog inputs programmable as single-ended or pseudo-differential pairs
  • On-chip sample and hold
  • SPI serial interface (modes 0,0 and 1,1)
  • Single supply operation: 2.7V-5.5V
  • 100ksps max.sampling rate at VDD = 5V
  • 50ksps max. sampling rate at VDD = 2.7V
  • Low power CMOS technology
    • 500 nA typical standby current, 2 μA max.
    • 400 μA max. active current at 5V
  • Industrial temp range: -40°C to +85°C

For more information, see the datasheet.

Usage

SPI Interface

This chip uses SPI to interface with the Raspberry Pi. Basically, the chipreturns 12 bits contained in 3 bytes. You are able to read the MCP3208either LSB or MSB first.

MIT License

Copyright (c) 2017 Kevin J. Walchko

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the “Software”), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in allcopies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THESOFTWARE.

Release historyRelease notifications

0.0.6

With

0.0.5

0.0.4

0.0.3

0.0.2

0.0.1

Download files

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

Files for mcp3208, version 0.0.6
Filename, sizeFile typePython versionUpload dateHashes
Filename, size mcp3208-0.0.6-py2-none-any.whl (6.8 kB) File type Wheel Python version py2 Upload dateHashes
Filename, size mcp3208-0.0.6-py3-none-any.whl (6.8 kB) File type Wheel Python version py3 Upload dateHashes
Filename, size mcp3208-0.0.6.tar.gz (3.8 kB) File type Source Python version None Upload dateHashes
Close

Hashes for mcp3208-0.0.6-py2-none-any.whl

Hashes for mcp3208-0.0.6-py2-none-any.whl
AlgorithmHash digest
SHA256bc5a116390669eb358d6004bf2cf72bf24d0c166c79caae813143fe940fe7c6b
MD55640a99d44f7e626b41f807d61849b1b
BLAKE2-256aa5d9e30d543d2b1ef521fd0bd45cb0009a5cfe0985a7306a37c32de68948452
Close

Hashes for mcp3208-0.0.6-py3-none-any.whl

Hashes for mcp3208-0.0.6-py3-none-any.whl
AlgorithmHash digest
SHA256207068b4ba7779bd44b572b1ee69b0657dee49e1dd782e36dbcb8ed1b58ef1aa
MD5598bf377656bdeb13930a85713320abd
BLAKE2-2566340e86c28e68edb062e3c7c5e5e8047f1864c9694b91b31bb4163693c33956c
Close

Hashes for mcp3208-0.0.6.tar.gz

Hashes for mcp3208-0.0.6.tar.gz
AlgorithmHash digest
SHA25625249c16aefd460b1ffcbe281df3fddef21866970d1c5247b72c74b7dcb2f2be
MD58968d12beb4fe37a672413b7860207b1
BLAKE2-25658fbad4836951de44aea7c8865e84bdf68b255d7bf14f87ffaea3c5dd9360f18

Page Contents

Overview

The Raspberry Pi is equipped with one SPI bus that has 2 chip selects.

The SPI master driver is disabled by default on Raspbian. To enable it, use raspi-config, or ensure the line dtparam=spi=on isn't commented out in /boot/config.txt, and reboot. If the SPI driver was loaded, you should see the device /dev/spidev0.0.

The SPI bus is available on the P1 Header:

Software

WiringPi

WiringPi includes a library which can make it easier to use the Raspberry Pi's on-board SPI interface. Accesses the hardware registers directly.

bcm2835 library

This is a C library for Raspberry Pi (RPi). It provides access to GPIO and other IO functions on the Broadcom BCM 2835 chip. Accesses the hardware registers directly.

Use spidev from C

There's a loopback test program in the Linux documentation that can be used as a starting point. See the Troubleshooting section. Uses the Linux spidev driver to access the bus.

Shell

Hardware

The BCM2835 on the Raspberry Pi has 3 SPI Controllers. Only the SPI0 controller is available on the header.Chapter 10 in the BCM2835 ARM Peripherals datasheet describes this controller.

With

Master modes

Signal name abbreviations

Standard mode

In Standard SPI master mode the peripheral implements the standard 3 wire serial protocol (SCLK, MOSI and MISO).

Bidirectional mode

In bidirectional SPI master mode the same SPI standard is implemented, except that a single wire is used for data (MOMI) instead of the two used in standard mode (MISO and MOSI). In this mode, the MOSI pin serves as MOMI pin.

LoSSI mode (Low Speed Serial Interface)

The LoSSI standard allows issuing of commands to peripherals (LCD) and to transfer data to and from them. LoSSI commands and parameters are 8 bits long, but an extra bit is used to indicate whether the byte is a command or parameter/data. This extra bit is set high for a data and low for a command. The resulting 9-bit value is serialized to the output. LoSSI is commonly used with MIPI DBI type C compatible LCD controllers.

Note:

Some commands trigger an automatic read by the SPI controller, so this mode can't be used as a multipurpose 9-bit SPI.

Transfer modes

  • Polled
  • Interrupt
  • DMA

Speed

The CDIV (Clock Divider) field of the CLK register sets the SPI clock speed:

Errata: 'must be a power of 2' probably should be 'must be a multiple of 2'

See the Linux driver section for more info.

Chip Select

Setup and Hold times related to the automatic assertion and de-assertion of the CS lines when operating in DMA mode are as follows:

  • The CS line will be asserted at least 3 core clock cycles before the msb of the first byte of the transfer.
  • The CS line will be de-asserted no earlier than 1 core clock cycle after the trailing edge of the final clock pulse.

Linux driver

The default Linux driver is spi-bcm2708.

The following information was valid 2014-07-05. 20 crackling balls.

Speed

The driver supports the following speeds:

When asking for say 24 MHz, the actual speed will be 15.6 MHz.

Forum post: SPI has more speeds

Supported Mode bits

Bidirectional or '3-wire' mode is supported by the spi-bcm2835 kernel module. Please note that in this mode, either the tx or rx field of the spi_transfer struct must be a NULL pointer, since only half-duplex communication is possible. Otherwise, the transfer will fail. The spidev_test.c source code does not consider this correctly, and therefore does not work at all in 3-wire mode.

Supported bits per word

  • 8 - Normal
  • 9 - This is supported using LoSSI mode.

Transfer modes

Only interrupt mode is supported.

Deprecated warning

The following appears in the kernel log:

SPI driver latency

This thread discusses latency problems.

DMA capable driver

This is a fork of spi-bcm2708 which enables DMA support for SPI client drivers that support DMA.

https://github.com/notro/spi-bcm2708 (wiki)

Troubleshooting

Loopback test

This can be used to test SPI send and receive. Put a wire between MOSI and MISO. It does not test CE0 and CE1.