I2C
I2C is one of the protocols that is used widely in most sensors.
I2c.Write(address, arrayWrite, indexWrite, writeCount) - Write an array of data to an I2C slave
address: I2C slave address
arrayWrite: Array to send
indexWrite: Index of data in the array (optional, default is 0).
writeCount: The number of bytes to write (optional, default is length of array)I2c.Read(address, arrayRead, indexRead, readCount) - Read data from an I2C slave
address: I2C slave address
arrayRead: Array to read
indexRead: Index of data in the array (optional, default is 0)
readCount: The number of bytes to read (optional, default is length of array)I2c.WriteRead(address, arrayWrite, indexWrite, writeCount, arrayRead, indexRead, readCount) - Write and read data
address: I2C slave address
arrayWrite: Array to send
indexWrite: Index of data in the array
writeCount: The number of bytes to write
arrayRead: Array to read
indexRead: Index of data in the array
readCount: The number of bytes to read
# Write 11 and 22 to a slave at address 0x2C
dataWrite = [11,22]
duelink.I2c.Write(0x2C, dataWrite)
# Read 2 bytes from address 0x2C
dataRead = [0]*2
duelink.I2c.Read(0x2C, dataRead)
# WriteRead from address 0x2C
duelink.I2c.WriteRead(0x2C, dataWrite, 0, len(dataWrite), dataRead, 0, len(dataRead))