# Envirobit support (python I/O)

**URL:** <https://forums.pimoroni.com/t/envirobit-support-python-i-o/12194>\
**Category:** BBC Micro:Bit\
**Created:** [November 17, 2019, 12:42pm UTC](https://forums.pimoroni.com/t/envirobit-support-python-i-o/12194 "2019-11-17T12:42:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![hojland93](https://avatars.discourse-cdn.com/v4/letter/h/df705f/32.png) [@hojland93](https://forums.pimoroni.com/u/hojland93)\
**Post date:** [November 17, 2019, 12:42pm UTC](https://forums.pimoroni.com/t/envirobit-support-python-i-o/12194/1 "2019-11-17T12:42:00Z")

</div>

Hello,

Im trying to add I/O capabilities to my envirobit. The envirobit is connected to my raspberry pi 4 via a microbit, and I am building on [https://github.com/whaleygeek/bitio](https://github.com/whaleygeek/bitio).

I am also using pimoroni/bme280-python to better structure the code, and then I added my own changes to i2cdevice-python.

Now, in this code I changed the write\_i2c\_block\_data and read\_i2c\_block\_data functions to be getting I/O data from the microbit.

The problem is that the bytes are printed as strings, and I have to change them back to bytes - which I think I have succeeded in.  
But the length of the byte output is longer than prescribed, which might be wrong. In particular, the first calibration should be length 26, but I get 38 bytes.

I don’t know how to move forward, or how to correctly limit the length of the received bytes (or send correct write to limit it).

My read\_i2c\_block\_data looks like this

def read\_i2c\_block\_data(self, i2c\_address, register, length=1):  
microbit.cmd(f"i2c.write({i2c\_address}, {bytes([register])}, repeat=True)")  
read = microbit.cmd(f"print(i2c.read({i2c\_address}, {length}))")  
read = re.sub(r’("|’)$’, ‘’, read)  
read = re.sub(r’^b("|’)’, ‘’, read)  
read = read.encode().decode(‘unicode-escape’).encode(‘utf-8’)  
return read

Would anybody mind checking my setup and forking my code to how it could be done?

I have very limited knowledge on i2cbus communication and bytes.

The repo is here: [https://github.com/Hojland/bitio](https://github.com/Hojland/bitio)

---

<div class="post-metadata">

**Author:** ![PaulWebster](https://sea2.discourse-cdn.com/flex016/user_avatar/forums.pimoroni.com/paulwebster/32/6045_2.png) [@PaulWebster](https://forums.pimoroni.com/u/PaulWebster)\
**Post date:** [November 18, 2019, 2:12pm UTC](https://forums.pimoroni.com/t/envirobit-support-python-i-o/12194/2 "2019-11-18T14:12:46Z")

</div>

Just a guess but 26 in Hex is 38 in decimal
