import time import ue9 import os try: d = ue9.UE9() d.spi([((0x14<<1)+1)<<1,0xC0])#This sets up the sensor into 8bit ring buffer mode while(True): n = d.spi([0x15<<2, 0x0]) #this reads how many results are available in the buffer getResults = [0]*n[1] #create an array getResults that is filled with n 0's which happens to be (#results in buffer)*3+1 getResults[0]=0xF<<2 #edit the first number in the array to prepare the array to be sent over SPI and get the results print d.spi(getResults) #print out the results array, the first is a bogus variable, but after its x,y,z,x,y,z..... time.sleep(.001) os.system("clear") #this function only works on mac and maybe linux, probably not for windows... It clears the command line to make the results easier to read/understand except KeyboardInterrupt: #this allows the program to quit when you press "ctrl C", it takes the sensor out of ring buffer mode and turns off the interrupt. print " ctrl C received, shutting down program" d.spi([((0x14<<1)+1)<<1,0x0]) #take sensor out of ring buffer mode d.spi([0x16<<2,0]) #re-set interrupt d.close() #close the device spi(self, SPIBytes, AutoCS=True, DisableDirConfig = False, SPIMode = 'A', SPIClockFactor = 0, CSPINNum = 1, CLKPinNum = 0, MISOPinNum = 3, MOSIPinNum = 2)