def main(argv):	
	id = imuSens.getID()					#Verify chip ID
	print "Chip ID: 0x%02X. \r\n" % id	
	imuSens.standbyMode()	
	imuSens.activeMode()
		
	id = imuSens.getChipMode()			#Configure sensor as accelerometer
	print "Chip Mode: 0x%02X. \r\n" % id
		
	id = imuSens.getTemperature()
	print "Chip Temperature: 0x%02X. \r\n" % id
		
		
	imuSens.configureAccelerometer()
	imuSens.configureMagnetometer()

	while True:
		if(imuSens.readStatusReg() & 0x80):
			x,y,z = imuSens.pollAccelerometer()
			print "Accelerometer data x: %d, y: %d, z: %d \r\n"  % (x, y, z)
			pitch,roll  = pitchAndroll(x,y,z)
			
			print "pitch %f, roll %f \r\n" % (pitch,roll)
			mx,my,mz = imuSens.pollMagnetometer() 
			print "Magnetometer data mx: %d, my: %d, mz: %d \r\n" % (mx, my, mz)
			angle = mag_to_tilt_compensated_heading(mx, my, mz,pitch,roll)
			print "Angle:  %f" % angle			
			print "Heading :  %f" % imuSens.getHeading()
			
	print "Shutting down"	
def main(argv):
    id = imuSens.getID()  #Verify chip ID
    print "Chip ID: 0x%02X. \r\n" % id
    imuSens.standbyMode()
    imuSens.activeMode()

    id = imuSens.getChipMode()  #Configure sensor as accelerometer
    print "Chip Mode: 0x%02X. \r\n" % id

    id = imuSens.getTemperature()
    print "Chip Temperature: 0x%02X. \r\n" % id

    imuSens.configureAccelerometer()
    imuSens.configureMagnetometer()

    while True:
        if (imuSens.readStatusReg() & 0x80):
            x, y, z = imuSens.pollAccelerometer()
            print "Accelerometer data x: %d, y: %d, z: %d \r\n" % (x, y, z)
            pitch, roll = pitchAndroll(x, y, z)

            print "pitch %f, roll %f \r\n" % (pitch, roll)
            mx, my, mz = imuSens.pollMagnetometer()
            print "Magnetometer data mx: %d, my: %d, mz: %d \r\n" % (mx, my,
                                                                     mz)
            angle = mag_to_tilt_compensated_heading(mx, my, mz, pitch, roll)
            print "Angle:  %f" % angle
            print "Heading :  %f" % imuSens.getHeading()

    print "Shutting down"
def main():	
	id = imuSens.getID()					#Verify chip ID
	print "Chip ID: 0x%02X. \r\n" % id
	imuSens.standbyMode()	
	# imuSens.writeByte(0x0B,0x01)		#Set to wake up 	
	imuSens.activeMode()
		
	id = imuSens.getChipMode()			#Configure sensor as accelerometer
	print "Chip Mode: 0x%02X. \r\n" % id
		
	id = imuSens.getTemperature()
	print "Chip Temperature: 0x%02X. \r\n" % id
		
	#id = imuSens.readByte(PL_BF_ZCOMP)
	#print "PL_BF_ZCOMP: 0x%02X. \r\n" % id
		
	imuSens.configureAccelerometer()
	imuSens.configureMagnetometer()
	while True:
		if(imuSens.readStatusReg() & 0x80):
			x,y,z = imuSens.pollAccelerometer()
			print "Accelerometer data x: %d, y: %d, z: %d \r\n"  % (x, y, z)
			# mx,my,mz = imuSens.pollMagnetometer()
			# print "Magnetometer data mx: %d, my: %d, mz: %d \r\n" % (mx, my, mz)
	print "Shutting down"
def main(argv):
	id = imuSens.getID()					#Verify chip ID
	print "Chip ID: 0x%02X. \r\n" % id	
	imuSens.standbyMode()	
	imuSens.activeMode()
		
	id = imuSens.getChipMode()			#Configure sensor as accelerometer
	print "Chip Mode: 0x%02X. \r\n" % id
		
	id = imuSens.getTemperature()
	print "Chip Temperature: 0x%02X. \r\n" % id

	def L1():
		print "Landscape right.\r\n"
		
	def L2():
		print "Landscape left. \r\n"
			
	def P1():
		print "Portrait down.\r\n"
			
	def P2():
		print "Portrait up.\r\n" 
		
	options = {0 : L1,
				1 : L2,
				2 : P1,
				3 : P2
			}

	imuSens.configureAccelerometer()
	imuSens.configureMagnetometer()
	imuSens.configureOrientation();
	modeprevious = 0

	while True:
		if(imuSens.readStatusReg() & 0x80):	
			orienta = imuSens.getOrientation()
			mode = (orienta >> 1) & 0x03	
			
			if (mode != modeprevious):
				options[mode]()
				
			modeprevious = mode
			
	print "Shutting down"	
def main(argv):
    id = imuSens.getID()  # Verify chip ID
    print "Chip ID: 0x%02X. \r\n" % id
    imuSens.standbyMode()
    imuSens.activeMode()

    id = imuSens.getChipMode()  # Configure sensor as accelerometer
    print "Chip Mode: 0x%02X. \r\n" % id

    id = imuSens.getTemperature()
    print "Chip Temperature: 0x%02X. \r\n" % id

    def L1():
        print "Landscape right.\r\n"

    def L2():
        print "Landscape left. \r\n"

    def P1():
        print "Portrait down.\r\n"

    def P2():
        print "Portrait up.\r\n"

    options = {0: L1, 1: L2, 2: P1, 3: P2}

    imuSens.configureAccelerometer()
    imuSens.configureMagnetometer()
    imuSens.configureOrientation()
    modeprevious = 0

    while True:
        if imuSens.readStatusReg() & 0x80:
            orienta = imuSens.getOrientation()
            mode = (orienta >> 1) & 0x03

            if mode != modeprevious:
                options[mode]()

            modeprevious = mode

    print "Shutting down"
	print "Portrait down.\r\n"
	image = image1.rotate(0).resize((128, 160))
	graphicDisplay.display(image)
		
def P2():
	print "Portrait up.\r\n" 
	image = image1.rotate(180).resize((128, 160))
	graphicDisplay.display(image)
	
options = {0 : L1,
			1 : L2,
			2 : P1,
			3 : P2
		}

imuSens.configureAccelerometer()
imuSens.configureMagnetometer()
imuSens.configureOrientation();
modeprevious = 0

while True:
	if(imuSens.readStatusReg() & 0x80):	
		orienta = imuSens.getOrientation()
		mode = (orienta >> 1) & 0x03	
		
		if (mode != modeprevious):
			options[mode]()
			
		modeprevious = mode
		
print "Shutting down"	
Exemple #7
0
def P1():
    print "Portrait down.\r\n"
    image = image1.rotate(0).resize((128, 160))
    graphicDisplay.display(image)


def P2():
    print "Portrait up.\r\n"
    image = image1.rotate(180).resize((128, 160))
    graphicDisplay.display(image)


options = {0: L1, 1: L2, 2: P1, 3: P2}

imuSens.configureAccelerometer()
imuSens.configureMagnetometer()
imuSens.configureOrientation()
modeprevious = 0

while True:
    if (imuSens.readStatusReg() & 0x80):
        orienta = imuSens.getOrientation()
        mode = (orienta >> 1) & 0x03

        if (mode != modeprevious):
            options[mode]()

        modeprevious = mode

print "Shutting down"