I would like to write 16 bits of data to an I2C bus. Considering that the data to be transferred is not in a list, I am using the pi.i2c_write_device()
function, however I get the following error:
in i2c_write_device
if len(data):
TypeError: object of type 'int' has no len()
I am passing in a 16 bit value, hence the error. Here is the code I am working with:
import pigpio
import time
##########################################
## I2C Initilization
##########################################
channel = 1
i2c_addr = 0b0001110
pi=pigpio.pi()
j = pi.i2c_open(channel, i2c_addr) # open device at address i2c_addr on bus 1
###########################################
transfer_data = 2096
data = transfer_data << 4 #(16 bits needed for DAC)
pi.i2c_write_device(j, data)
sleep(3)
pi.i2c_close(j)
I appreciate any help with figuring this out. Please let me know if you have any questions, thank you!