MCP-3903 is a 6-channel synchronous 16-bit ADC.I have done the wiring of MCP-3903 i.e connected SCK,SDO & SDI with SPI_CLCK,SPI_MISO , SPI_MOSI of R pi, now I wanted to write a python program to read data from this 16-Bit ADC. Kindly help in finding the appropriate Python library for SPI interfacing of this IC.
There doesn't appear to be a great deal of choice on the Pi.
The Python spidev module is the obvious choice for Python. https://github.com/doceme/py-spidev seems to be the one mainly used on the Pi.
An advantage of my module is that it supports both the standard (2 channels) and auxiliary (3 channels) SPI peripherals on the recent Pis, and it works over the network.
There are two popular approaches to using the Raspberry Pi to drive a SPI interface: you can either use Hardware SPI, or you could use bit-banged SPI.
No matter whether you use Hardware SPI or bit-banged SPI, you'll need to connect some pins of the MCP3903 to your processor. As you've probably already figured out, you need to connect several pins of that chip to the Raspberry Pi:
- MCP3903 pin 17 and pin 18 to Rasp GND -- "AGND ... must be connected to the same ground as DGND"; p. 15.
- MCP3903 pin 26 SDI to Rasp SPI_MOSI
- MCP3903 pin 25 SDO to Rasp SPI_MISO
- MCP3903 pin 24 SCK to Rasp SPI_CLK
- MCP3903 pin 23 nCS to some Rasp GPIO pin, perhaps "CE0_N" (some SPI devices work with their nCS tied to ground, but it appears that at least some features of the MCP3903 require a processor to drive the nCS high and low at the appropriate times)
- MCP3903 pin 28 DVDD to Rasp 3V3 (or some other 3.3 V power)
- MCP3903 pin 1 AVDD to Rasp 5V Power (or some other 5 V power) -- "Proper decoupling capacitors (0.1 µF ceramic and 10 µF tantalum) should be mounted as close as possible to the AVDD pin" p. 28
- MCP3903 pin nRESET to some Rasp GPIO pin (it is unclear if tying this pin to GND will work)
- (optional) MCP3903 pin 18 nDRA to some Rasp GPIO pin to detect the data ready status (apparently you could leave nDRA unconnected, and read the same status bit through SPI communications).
You'll want to read the MCP3903 datasheet to see if I got any of the above wrong, and for many other tips.
In principle, any one of these tutorials should have all the information you need. In practice, different people find different tutorials more or less understandable.
- "Simple SPI on Raspberry Pi"
- "Enabling The SPI Interface On The Raspberry Pi"
- "SpiDev Documentation for Raspberry Pi"
- "Python, SPI and spidev"
- "Introduction to Raspberry Pi: Serial Peripheral Interface"
While it's far more complicated than what you need, you might like to check out how people drive other SPI devices using Python on a Raspberry Pi -- many programmers find it easier to start with code does a lot more that more than they want, and then trim it down:
- "SSD1306 OLED Displays with Raspberry Pi and BeagleBone Black" and in particular the SSD1306.py source code
- "User-space SPI TFT Python Library - ILI9341" and in particular the ILI9341.py source code