Methods to interact with the I2C port. An instance of Labtools.Packet_Handler must be passed to the init function
>>> ADDRESS = 0x1E
>>> from Labtools import interface
>>> I = interface.Interface()
>>> # Alternately, you may skip using I2C as a child instance of Interface,
>>> # and instead use I2C=Labtools.I2C_class.I2C(Labtools.packet_handler.Handler())
>>> I.I2C.bulkWrite(self.ADDRESS,[0x01,0<<5]) # writing to 0x1E, set gain(0x01) to smallest(0)
>>> I.I2C.bulkWrite(self.ADDRESS,[0x02,0]) # writing to 0x1E, set mode conf(0x02), continuous measurement(0)
>>> vals = I.I2C.bulkRead(self.ADDRESS,addr,6) # read 6 bytes from addr register on I2C device located at ADDRESS
>>> from numpy import int16
>>> x=int16((vals[0]<<8)|vals[1]) #conversion to signed datatype
>>> y=int16((vals[2]<<8)|vals[3])
>>> z=int16((vals[4]<<8)|vals[5])
>>> print x,y,z
Initiates I2C transfer to address via the I2C port
Arguments | |
---|---|
address | I2C slave address |
rw | Read/write. * 0 for writing * 1 for reading. |
SENDS data over I2C. The I2C bus needs to be initialized and set to the correct slave address first. Use I2C.start(address) for this.
Arguments | |
---|---|
data | Sends data byte over I2C bus |
Returns: | Nothing |
---|
SENDS data over I2C. The function does not wait for the I2C to finish before returning. It is used for sending large packets quickly. The I2C bus needs to be initialized and set to the correct slave address first. Use start(address) for this.
Arguments | |
---|---|
data | Sends data byte over I2C bus |
Returns: | Nothing |
---|
Initiates I2C transfer to address
Arguments | |
---|---|
address | I2C slave address |
rw | Read/write. * 0 for writing * 1 for reading. |