I was wondering if someone could look at my code and let me know if there's anything that I can adjust to give me better values.
Also, I wasn't sure which of the 16 bits collected counted toward the data. If anyone could shed some light on this as well, it would be greatly appreciated.
Code: Select all
import RPi.GPIO as GPIO from time import sleep # set up pins GPIO.setmode(GPIO.BCM) GPIO.setup(11, GPIO.OUT) GPIO.setup(9,GPIO.IN) GPIO.setup(8,GPIO.OUT) # name pins clock = 11 miso = 9 cs = 8 # bring clock and cs high GPIO.output(clock,True) GPIO.output(cs,True) # begin loop to print a stream of data while True: # bring cs low GPIO.output(cs,False) # create a string to store the bits data = str() # begin loop to take in data for i in range(16): # bring clock low GPIO.output(clock, False) # read miso pin if GPIO.input(miso): data += "1" else: data += "0" # bring clock high GPIO.output(clock, True) # remove the first 4 bits from the data data = data.replace(' ','')[4:15] # convert the data from binary to decimal data = int(data,2)*(3.3/2045) data = str(data) # print data print data # bring cs high GPIO.output(cs, True) sleep(1)