9 A class to passively monitor activity on an I2C bus. This should 10 work for an I2C bus running at 100kbps or less. You are unlikely 11 to get any usable results for a bus running any faster. 14 def __init__(self, pi, SCL, SDA, set_as_inputs=True):
16 Instantiate with the Pi and the gpios for the I2C clock 19 If you are monitoring one of the Raspberry Pi buses you 20 must set set_as_inputs to False so that they remain in 23 The pigpio daemon should have been started with a higher 24 than default sample rate. 26 For an I2C bus rate of 100Kbps sudo pigpiod -s 2 should work. 28 A message is printed for each I2C transaction formatted with 30 "XX" two hex characters for each data byte 31 "+" if the data is ACKd, "-" if the data is NACKd 34 E.g. Reading the X, Y, Z values from an ADXL345 gives: 37 [A7+01+FF+F2+FF+06+00-] 57 self.pi.set_mode(SCL, pigpio.INPUT)
58 self.pi.set_mode(SDA, pigpio.INPUT)
60 self.
cbA = self.pi.callback(SCL, pigpio.EITHER_EDGE, self.
_cb)
61 self.
cbB = self.pi.callback(SDA, pigpio.EITHER_EDGE, self.
_cb)
65 Accumulate all the data between START and STOP conditions 66 into a string and output when STOP is detected. 119 def _cb(self, gpio, level, tick):
121 Check which line has altered state (ignoring watchdogs) and 122 call the parser with the new state. 127 if gpio == self.
gSCL:
133 if gpio == self.
gSDA:
142 """Cancel the I2C callbacks.""" 146 if __name__ ==
"__main__":
def _parse(self, SCL, SDA)
def __init__(self, pi, SCL, SDA, set_as_inputs=True)
def _cb(self, gpio, level, tick)