Issue with I2C communication #11756
-
Hi, I've be rewriting the BNO085 circuitpython library in micropython in order to fullfill a project I made with a Pico Pi W. I'm struggling with Buffer and I2c communication. I believe I miss something when adapting circuitpython I2C behaviour to micropython i2c behaviour. Here's the commented code :
And here's the output With self.bus_device_obj.readfrom_into(self.bno_address, self._data_buffer)
With self.bus_device_obj.readfrom_into(self.bno_address, self._data_buffer[0:4])
It seems that when reading self._data_buffer[0:4] the buffer is not updated with the readings I have with self._data_buffer I think using "partial" buffer might be a wrong way, everything acts as if the global buffer was not updated. Any suggestion ? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
self._data_buffer[0:4] creates a new bytearray object, which is different form buffer. So it you read into that one, buffer is not changed. It should work using memoryview, which creates an object which effectively is part of buffer. Not tested: mv = memoryview(buffer) |
Beta Was this translation helpful? Give feedback.
-
Thank you very much Robert, that did the job ! I was thinking of a local vs global issue, but I miss practice => I didn't realized that I was working on a new bytearray object ! My BNO085X library inspired by CircuitPython Orginal Library is fully working right now ! |
Beta Was this translation helpful? Give feedback.
self._data_buffer[0:4] creates a new bytearray object, which is different form buffer. So it you read into that one, buffer is not changed. It should work using memoryview, which creates an object which effectively is part of buffer. Not tested:
mv = memoryview(buffer)
then use readinto with mv[0:4] as argument.