For a chemistry research project at my school, we are using the ADS8320 data sheet found: here, to take in volatage readings from a potentiometer at a very fast rate. We are working off of a raspberry Pi 3 and are trying to take the data in through the GPIO and SPI pins on the Pi. I was able to do this using this code in python:
import time
import os
import RPi.GPIO as GPIO
GPIO.setmode(GPIO.BCM)
GPIO.setwarnings(False)
start = time.time()
PIN_CLK = 11
PIN_DO = 9
PIN_DI = 10
PIN_CS = 8
GPIO.setup(PIN_DI, GPIO.OUT)
GPIO.setup(PIN_DO, GPIO.IN)
GPIO.setup(PIN_CLK, GPIO.OUT)
GPIO.setup(PIN_CS, GPIO.OUT)
def getADC(channel):
GPIO.output(PIN_CS, True) #used to clear last transmission
GPIO.output(PIN_CS, False) #Bringing cs to low
GPIO.output(PIN_CLK, False) #starting the clock
for i in [1,1,channel]: #start of a new bit assignment
if (i==1):
GPIO.output(PIN_DI, True)
else:
GPIO.output(PIN_DI,True)
GPIO.output(PIN_CLK, True)
GPIO.output(PIN_CLK, False)
ad = 0
for i in range (18):
GPIO.output(PIN_CLK, True)
GPIO>output(PIN_CLK, False)
ad <<= 1
if (GPIO.input(PIN_DO)):
ad |= 0x1
GPIO.output(PIN_CS, True) #reset
return ad
if __name__ == "__main__":
while True:
bitReading = getADC(0)
Data = float(bitReading/65535.0*3.3)
getTime = float(time.time() - start)
print ("%.5f" % getTime + "," + "%.5f" % Data)
time.sleep(0)
The main issue with this code is that while I am able to take in data, it is much slower than what I would expect. From the data sheet it says that it runs at around 100Khz, but the issue is that currently it is taking in in milliseconds. How would I speed up this code? I am a complete beginner to coding and most of the working code I have is taken from sites I found from googling. I've seen things about spidev, but I'm not sure how to implement them. Any help on this would be great, as I'm a chem major not a comp sci major so I am wayyyyyyy out in the deep end for this problem. If you have any questions or if I'm missing any crucial information please let me know!