From: ladyada Date: Sat, 30 Jun 2018 22:12:20 +0000 (-0400) Subject: politely cope with strings of bytes X-Git-Tag: 0.2^2~1 X-Git-Url: https://git.ayoreis.com/Adafruit_Blinka-hackapet.git/commitdiff_plain/d11b3854670343e9b9e397a95ca4e1b049ef58ec politely cope with strings of bytes --- diff --git a/src/busio.py b/src/busio.py index 3523acd..0d23b33 100755 --- a/src/busio.py +++ b/src/busio.py @@ -53,6 +53,8 @@ class I2C(Lockable): return self._i2c.readfrom_into(address, buffer, stop) def writeto(self, address, buffer, start=0, end=None, stop=True): + if isinstance(buffer, str): + buffer = bytes([ord(x) for x in buffer]) if start is not 0 or end is not None: if end is None: return self._i2c.writeto(address, memoryview(buffer)[start:], stop)