How to write bytes object to i2c memory (using i2c.writeto_mem() operation)? #12067
cole-morrel
started this conversation in
General
Replies: 1 comment
-
I can imagine something like OV2640_B = (b'\xff\x05\xda\xd7\xdf\x33\x3c\xe1\x00\xff',
b'\x00\x00\x10\x03\x00\x80\x40\x77\x00\xff')
for maddr, data in zip(OV2640_B[0], OV2640_B[1]):
if maddr == data == 0xff:
break
self.i2c.writeto_mem(iaddr, maddr, bytes(data)) If you should find out that the \xff bytes combo is only found at the end of the data then you may omit the test for it with the break statement (and the pair of \xff's), as the for loop is terminating anyway. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello,
I am trying to optimize some older code for memory usage. On an earlier post I made about this I received the suggestion to replace lists in the code like:
with a bytes object like
OV2640_YUV422 = b'\xff\x00\x05\x00...'
as it would significantly cut down on the memory size. The lists like OV2640_YUV422 are currently being used in this function:where set is something like OV2640_YUV422, addr is SENSORADDR = 0x30, and i is self.i2c. If I understand this function correctly this means that the left column of OV2640_YUV422 is being stored as raddr, and serving as the memory address in the writeto_mem operation, while the right column is being converted to bytes and stored as val, serving as buf in the writeto_mem operation, and that the function iterates through the list until it reaches the final entry (where raddr == 0xff and val == b'\xff'). So what I'm asking is how to do the same thing (or something similar) when OV2640_YUV422 is in the form
b'\xff\x00\x05\x00...'
(if that is possible). Please forgive me if this wasn't the clearest, I'm still fairly new to Python and trying to learn.Beta Was this translation helpful? Give feedback.
All reactions