Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # I2C writes =D0=0
- # MMA7455 I2C address 1D (3A ,3B) write , read
- # AN3745 app note for calibration
- # byte read , write 1D , write address, read 1D ,DATA
- # Byte write, write 1D , write address, write data.
- # addresses,
- # 06 XOUT8
- # 07 YOUT8
- # 08 ZOUT8
- # 09 STATUS D0 1=data ready
- # 0A detection source
- # 0F who am i
- # 16 Mode Control x1000101 measure 2gmode 0x45
- # 16 Mode Control x1000001 measure 8gmode 0x41
- # 16 Mode Control x1000100 standby 2gmode 0x84
- # 16 Mode Control x1010101 ston measure 2gmode 0x55
- # 18 Control1 D7 filter 0=62Hz,1=125Hz other 0
- # 19 Control2 default 0
- #!/usr/bin/python
- import smbus
- import time
- import os
- file= open('file.txt', 'w')
- # import graphics
- # Define a class called Accel
- class Accel():
- b = smbus.SMBus(0)
- def setUp(self):
- # Setup the Mode
- self.b.write_byte_data(0x1D,0x16,0x41)
- # Setup Calibration
- self.b.write_byte_data(0x1D,0x10,1)
- self.b.write_byte_data(0x1D,0x11,1)
- self.b.write_byte_data(0x1D,0x12,1)
- self.b.write_byte_data(0x1D,0x13,1)
- self.b.write_byte_data(0x1D,0x14,1)
- self.b.write_byte_data(0x1D,0x15,1)
- def getValueX(self):
- return self.b.read_byte_data(0x1D,0x06)
- def getValueY(self):
- return self.b.read_byte_data(0x1D,0x07)
- def getValueZ(self):
- return self.b.read_byte_data(0x1D,0x08)
- MMA7455 = Accel()
- MMA7455.setUp()
- print >> file , 'Time, X-axis, Y-axis, Z-axis'
- for a in range(10000):
- x = MMA7455.getValueX()
- y = MMA7455.getValueY()
- z = MMA7455.getValueZ()
- f = a, x, y , z
- print f
- print >> file,f
- time.sleep(0.1)
- os.system('clear')
- file.close()
Advertisement
Add Comment
Please, Sign In to add comment