import smbus
import time,timeit
#import RPi.GPIO as GPIO

# Global varible
i2c = smbus.SMBus(1)
addr = 0x68

c_t0 = time.clock()
t_t0 = time.time()

try:
	device_id = i2c.read_byte_data(addr,0x75)
	print "Device ID:" + str(hex(device_id))
	print "MPU9250 I2C Connected."
except:
	print "Connect failed"


i2c.write_byte_data(0x68, 0x6a, 0x00)
i2c.write_byte_data(0x68, 0x37, 0x02)
i2c.write_byte_data(0x0c, 0x0a, 0x16)


# Open File
f = open("IMU_LOG_9axis.txt", "w")


# Loop area
def read_write_mpu9250():
	count = 1

	while True:
		if count <= 500:

			def smbus_data_get():
				i2c.write_byte_data(0x0c, 0x0a, 0x16)
				#temp_out = i2c.read_i2c_block_data(addr, 0x41, 2)
				xyz_g_offset = i2c.read_i2c_block_data(addr, 0x13, 6)
				xyz_a_out = i2c.read_i2c_block_data(addr, 0x3B, 6)
				xyz_g_out = i2c.read_i2c_block_data(addr, 0x43, 6)
				xyz_a_offset = i2c .read_i2c_block_data(addr, 0x77, 6)

				xyz_mag  = i2c.read_i2c_block_data(0x0c, 0x03, 6)

				c_t1 = time.clock() - c_t0
				t_t1 = time.time() - t_t0


			smbus_data_get()	

			print >> f, count
			print >> f, c_t1, t_t1
			print >> f, xyz_a_out
			print >> f, xyz_a_offset
			print >> f, xyz_g_out
			print >> f, xyz_g_offset
			print >> f, xyz_mag

			count += 1
		else:
			f.close()
			i2c.write_byte_data(addr, 0x6A, 0x07)
			break

print timeit.timeit(read_write_mpu9250, number = 1)
print "Process End"

@@ -467,47 +467,10 @@
 )%0A%0A%0A
-# Loop area%0Adef read_write_mpu9250():%0A%09
+%0A%0A
 coun
@@ -476,17 +476,16 @@
 nt = 1%0A%0A
-%09
 while Tr
@@ -488,17 +488,16 @@
 e True:%0A
-%09
 %09if coun
@@ -511,35 +511,13 @@
 0:%0A%0A
+%0A
 %09%09%09
-def smbus_data_get():%0A%09%09
+%0A
 %09%09i2
@@ -556,65 +556,8 @@
 16)%0A
-%09%09%09%09#temp_out = i2c.read_i2c_block_data(addr, 0x41, 2)%0A%09%09
 %09%09xy
@@ -604,26 +604,24 @@
 r, 0x13, 6)%0A
-%09%09
 %09%09xyz_a_out 
@@ -659,26 +659,24 @@
  0x3B, 6)%0A%09%09
-%09
-%09
 xyz_g_out = 
@@ -714,18 +714,16 @@
 x43, 6)%0A
-%09%09
 %09%09xyz_a_
@@ -774,18 +774,16 @@
 , 6)%0A%0A%09%09
-%09
-%09
 xyz_mag 
@@ -825,18 +825,16 @@
 03, 6)%0A%0A
-%09%09
 %09%09c_t1 =
@@ -854,18 +854,16 @@
  - c_t0%0A
-%09%09
 %09%09t_t1 =
@@ -888,31 +888,8 @@
 0%0A%0A%0A
-%09%09%09smbus_data_get()%09%0A%0A%09
 %09%09pr
@@ -904,17 +904,16 @@
 , count%0A
-%09
 %09%09print 
@@ -929,17 +929,16 @@
 1, t_t1%0A
-%09
 %09%09print 
@@ -951,25 +951,24 @@
 xyz_a_out%0A%09%09
-%09
 print %3E%3E f, 
@@ -974,33 +974,32 @@
  xyz_a_offset%0A%09%09
-%09
 print %3E%3E f, xyz_
@@ -1004,17 +1004,16 @@
 z_g_out%0A
-%09
 %09%09print 
@@ -1033,17 +1033,16 @@
 ffset%0A%09%09
-%09
 print %3E%3E
@@ -1056,17 +1056,16 @@
 _mag%0A%0A%09%09
-%09
 count +=
@@ -1067,17 +1067,16 @@
 nt += 1%0A
-%09
 %09else:%0A%09
@@ -1076,17 +1076,16 @@
 else:%0A%09%09
-%09
 f.close(
@@ -1086,17 +1086,16 @@
 close()%0A
-%09
 %09%09i2c.wr
@@ -1132,67 +1132,15 @@
 )%0A%09%09
-%09
 break%0A%0A
-print timeit.timeit(read_write_mpu9250, number = 1)
 %0Apri

Modify some comment code.