The 3002 is inherently capable of such rates - but I can get nowhere near them with Python on the RPi.
I started with "bit-banging", but could only achieve around 1k samples per second.
Then I switched to SPI, using 'spidev' - my code is here...
Code: Select all
#!/usr/local/bin/python
# MCP3002_SPI2.py
# learning to drive the MCP3002 Analog to Digital Converter...
import spidev
import os
spi=spidev.SpiDev()
spi.open(0, 0)
spi.max_speed_hz=4000000
a=[0]*1024
r=[0]*1024
# grab a block of 1024 samples (from channel 0)...
for j in range (0,1024):
r[j]=spi.xfer2([0x60,0])
# now convert the raw sample tuples into useful numbers...
for j in range (0,1024):
rj=r[j]
a[j]=((rj[0] & 3)<< 8) + rj[1]
print(a)
It works - but I still only achieve approximately 7k samples per second.
Changing the value of 'spi.max_speed_hz' does little to influence the conversion rate - so I conclude that I'm not limited by the SPI clock.
So - can anybody help me by explaining...
i) what is the origin of my speed limit? Is it Python? Is it the latency of calls to spidev? Is it RPi? Or is there some other fundamental limit?
ii) what speed might I realistically hope for?
and - perhaps most importantly -
iii) where do I find decent, usable documentation for spidev?
Thanks,
m0xpd