Пример #1
0
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"
Пример #2
0
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"
Пример #4
0
def main(argv):
	print "========= MPL3115A2 Sensor demo ==========" 
	print "******************************************" 
	
	height = GLCD.TFT_HEIGHT
	width = GLCD.TFT_WIDTH

	disp = GLCD.TFT()		# Create TFT LCD display class.
	disp.initialize()		# Initialize display.
	disp.clear()			# Alternatively can clear to a black screen by calling:
	draw = disp.draw()		# Get a PIL Draw object to start drawing on the display buffer
	font = ImageFont.truetype('/usr/share/fonts/droid/DroidSans.ttf', 14)		# use a truetype font

	time.sleep(1)
	channel1 = AmbientLight.readChannel(1)				#Take a reading from channel one
	print "Channel 1 value: %d." % channel1		
	channel2 = AmbientLight.readChannel(0)				#Take a reading from channel two
	print "Channel 2 value: %d" % channel2
	Lux = AmbientLight.getLuxLevel(channel1,channel2)
	print "Lux output: %d." % Lux
	
	button = NoPress							#reset button
	button = CapTouch.readPressedButton()		#poll for new press
	if (button != NoPress):
		print "Button B%d pressed.\r\n"  % int(button)
			
	
	ser = serial.Serial('/dev/ttyS0',115200,timeout=3) 	# Open the serial port
	ser.write("X-shield UART Demo\r\n")					# Write a serial string to the serial port
	for num in range(1,10):
		ser.write("Number" + str(num) + "\r\n") 					# Write a serial string to the serial port
	
	print "Serial closed"
	ser.close()	
	imuSens = imuSens.FXOS8700CQR1()				#Configure chip in hybrid mode
	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()
	
	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)
			
		press =  AltiBar.ReadBarometricPressure()		#Take a pressure reading
		time.sleep(1)
		draw.text((30, 10), "Pressure (Pa)", font=font)
		draw.text((30, 30), str(press), font=font)		
		disp.display()
		time.sleep(5)
		disp.clear()