@@ -37,17 +37,9 @@ def __init__(self,I2C,**args):
3737 self .params = {'powerUp' :None ,'setGyroRange' :[250 ,500 ,1000 ,2000 ],'setAccelRange' :[2 ,4 ,8 ,16 ],'KalmanFilter' :[.01 ,.1 ,1 ,10 ,100 ,1000 ,10000 ,'OFF' ]}
3838 self .setGyroRange (2000 )
3939 self .setAccelRange (16 )
40- '''
41- try:
42- self.I2C.configI2C(400e3)
43- except:
44- pass
45- '''
4640 self .powerUp ()
4741 self .K = None
4842
49-
50-
5143 def KalmanFilter (self ,opt ):
5244 if opt == 'OFF' :
5345 self .K = None
@@ -62,9 +54,8 @@ def KalmanFilter(self,opt):
6254 sd = std (noise [a ])
6355 self .K [a ] = KalmanFilter (1. / opt , sd ** 2 )
6456
65- def getVals (self ,addr ,bytes ):
66- vals = self .I2C .readBulk (self .ADDRESS ,addr ,bytes )
67- return vals
57+ def getVals (self ,addr ,numbytes ):
58+ return self .I2C .readBulk (self .ADDRESS ,addr ,numbytes )
6859
6960 def powerUp (self ):
7061 self .I2C .writeBulk (self .ADDRESS ,[0x6B ,0 ])
@@ -79,8 +70,7 @@ def setAccelRange(self,rs):
7970
8071 def getRaw (self ):
8172 '''
82- This method must be defined if you want GUIs to use this class to generate
83- plots on the fly.
73+ This method must be defined if you want GUIs to use this class to generate plots on the fly.
8474 It must return a set of different values read from the sensor. such as X,Y,Z acceleration.
8575 The length of this list must not change, and must be defined in the variable NUMPLOTS.
8676
@@ -151,8 +141,8 @@ def getMag(self):
151141
152142 def WhoAmI (self ):
153143 '''
154- Returns the ID .
155- It is 71 for MPU9250 .
144+ Returns the ID.
145+ It is 71 for MPU9250.
156146 '''
157147 v = self .I2C .readBulk (self .ADDRESS ,0x75 ,1 )[0 ]
158148 if v not in [0x71 ,0x73 ]:return 'Error %s' % hex (v )
@@ -164,8 +154,8 @@ def WhoAmI(self):
164154
165155 def WhoAmI_AK8963 (self ):
166156 '''
167- Returns the ID fo magnetometer AK8963 if found.
168- It should be 0x48.
157+ Returns the ID fo magnetometer AK8963 if found.
158+ It should be 0x48.
169159 '''
170160 self .initMagnetometer ()
171161 v = self .I2C .readBulk (self .AK8963_ADDRESS ,0 ,1 ) [0 ]
@@ -175,10 +165,9 @@ def WhoAmI_AK8963(self):
175165 def initMagnetometer (self ):
176166 '''
177167 For MPU925x with integrated magnetometer.
178- It's called a 10 DoF sensor, but technically speaking ,
179- the 3-axis Accel , 3-Axis Gyro, temperature sensor are integrated in one IC, and the 3-axis magnetometer is implemented in a
168+ It's called a 10 DoF sensor, but technically speaking ,
169+ the 3-axis Accel , 3-Axis Gyro, temperature sensor are integrated in one IC, and the 3-axis magnetometer is implemented in a
180170 separate IC which can be accessed via an I2C passthrough.
181-
182171 Therefore , in order to detect the magnetometer via an I2C scan, the passthrough must first be enabled on IC#1 (Accel,gyro,temp)
183172 '''
184173 self .I2C .writeBulk (self .ADDRESS ,[self .INT_PIN_CFG ,0x22 ]) #I2C passthrough
@@ -190,8 +179,8 @@ def initMagnetometer(self):
190179if __name__ == "__main__" :
191180 from PSL import sciencelab
192181 I = sciencelab .connect ()
193- A = connect (I .I2C )
194- t ,x ,y ,z = I .I2C .capture (A .ADDRESS ,0x43 ,6 ,5000 ,1000 ,'int' )
182+ A = connect (I .I2C )
183+ t ,x ,y ,z = I .I2C .capture (A .ADDRESS ,0x43 ,6 ,5000 ,1000 ,'int' )
195184 #print (t,x,y,z)
196185 from pylab import *
197186 plot (t ,x )
0 commit comments