I have managed to get some sensible data trough the ADC(MCP3008), but I'm struggling to find out how to set the SPI-Clock. The ADC (MCP3008) uses 24 clock-pulses to make one sample therefore I calculated that to get 200ksample/sek the clock should be at least 4,8MHz. I cant find any documentation of the module in use. I'm now using the py-spidev module the link shows the only documentation I can find. I have read at Gordons Projects that the clock has some jumps so i suppose 8MHz should be the right speed. I have measured the speed on the spi clock, on a scope. The default speed is 500kHz.
The code:
import spidev
import time
import os
import sys
DEBUG = 0
spi = spidev.SpiDev()
spi.open(0,0)
spi.max_speed_hz=(16000000)
#read SPI from MCP3008 chip, 8 possible chanels
def readadc(adcnum):
if((adcnum > 7) or (adcnum < 0)):
return -1
r = spi.xfer2([1,(8+adcnum)<<4,0])
adcout = ((r[1]&3 << 8) + r[2]
return adcout
#chanel input on ADC
ch0 = 0;
while true:
#read chanel
pc_value = readadc(ch0)
#print data from ADC
#print pc_value
#wait do nothing for 0.20 sek
#time.sleep(0.2)