Moderators: adafruit_support_bill, adafruit
import smbus
import time
def twoscomp( x ) :
"This returns a 16-bit signed number (two's complement)"
if (0x8000 & x):
x = - (0x010000 - x)
return x
bus = smbus.SMBus(1)
address = 0x6b
print "Time, deltaT, temp, status, x, y, z"
bus.write_i2c_block_data(address, 0x20, [0x0F])
tlast = 0
while True:
temp,status = bus.read_i2c_block_data(address, 0xA6, 2)
if (status & 0x08):
xlow,xhi,ylow,yhi,zlow,zhi = bus.read_i2c_block_data(address, 0xA8, 6)
x = (xhi*256 + xlow)
y = (yhi*256 + ylow)
z = (zhi*256 + zlow)
tim = time.time()
t = ["%20.6f"%tim, "%20.6f"%(tim - tlast)]
tlast = tim
a = ["%2d" % temp]
s = ["%03x" % status ] #[hex(status)]
b = ["%5d"%i for i in [twoscomp(x), twoscomp(y), twoscomp(z)]]
print t+a+s+b
Return to Adafruit Raspberry Pi® accessories
Users browsing this forum: No registered users and 1 guest