I2C multiple writes instead of individual writes

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
yoLo_
Posts: 9
Joined: Fri Mar 24, 2017 2:34 am

I2C multiple writes instead of individual writes

Post by yoLo_ » Wed Nov 22, 2017 11:41 pm

So.. I'm trying to do multiple writes to the module with the I2C
1 # sensor starts
2 def begin(self):
3 data = [0x11, 0xE5, 0x72, 0x8A] # for multiple writes
4 self._write(data, self.ccs811_addr, CSS811_SW_RESET, timeout=self.timeout)
5 pyb.millis(500)

THIS IS THE METHOD/OPERATION BELOW

def _write(self, data, memaddr, addr):

self._ccs811_i2c.mem_write(data, addr, memaddr, timeout=self.timeout)

is line 3 the right way to prepare the data to be safely written ??
should i pack the data into bytearray ??
because i would prefer a more concise way to doing it instead
of doing individual writes for each data.

Thanks

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: I2C multiple writes instead of individual writes

Post by pythoncoder » Sat Nov 25, 2017 10:23 am

For reading data you need a bytearray. For data which is only for writing you can use an (immutable) bytes object:

Code: Select all

data = b'\x11\xE5\x72\x8A'
Peter Hinch
Index to my micropython libraries.

Post Reply