I am working on an application transferring data from an Arduino (slave) to a Raspberry Pi (master) over an I²C bus. I was in the middle of writing the code, when suddenly the transfer quit working, and I cannot figure out why. I tried re-installing SMBus2, but the problem persists.
Here is some test code, attempting the transfer of 7 bytes from the Arduino:
#! /usr/bin/python3
from smbus2 import SMBus
slaveAddress = 10
blockSize = 7
with SMBus(1) as bus:
# Read a block of blockSize bytes from address slaveAddres, offset 0
block = bus.read_i2c_block_data(slaveAddress, 0, blockSize)
# Returned value is a list of slaveAddress bytes
print(block)
I have tried several variations, but no matter what I get the following:
[255, 255, 255, 255, 255, 255, 255]
If I issue the command
i2ctransfer -y -v 1 r7@0x0a
I get an expected result of
msg 0: addr 0x0a, read, len 7, buf 0x32 0x01 0x00 0x00 0x00 0x01 0x00
Which means the code on the Arduino and the I²C bus are behaving as expected. What can be wrong and how can I fix it?
Leslie Rhorer is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.