import time import ue9 import os d = ue9.UE9() #convert takes in the 11bit response and converts it into an integer def convert(byte1, byte2): ans = 0 i = 128 j = 128 while i>0: if(byte1>i): ans = ans<<1 ans = ans+1 byte1 = byte1-i else: ans=ans<<1 i = i>>1 while j>0: if(byte2>j): ans = ans<<1 ans = ans+1 byte2 = byte2-i else: ans = ans<<1 j = j>>1 return ans #converts the resulting integer into a factor of G.... I'm not sure if this conversion is correct, but it results in a sensible answer, look at the datasheet for understanding the binary results. def normalize(value): ans =0 if(value>20000): ans = convert(255,255)-value return (-ans)*1.0/10000 else: return value*1.0/10000 while(True): results = d.spi([0x4<<2,0]) #gets information from LSBx register LSBx = results[1] results = d.spi([0x5<<2, 0]) #gets information from MSBx register MSBx = results[1] results = d.spi([0x6<<2,0]) #gets information from LSBy register LSBy=results[1] results = d.spi([0x7<<2,0]) #gets information from MSBy register MSBy=results[1] results = d.spi([0x8<<2,0]) #gets information from LSBz register LSBz=results[1] results = d.spi([0x9<<2,0]) #gets information from MSBz register os.system("clear") MSBz=results[1] print "x: "+str(normalize(convert(MSBx, LSBx)))+"g" print "y: "+str(normalize(convert(MSBy, LSBy)))+"g" print "z: "+str(normalize(convert(MSBz, LSBz)))+"g" time.sleep(.01)