I have a MCP23017 GPIO expansion chip connected to a Pi via the I2C bus.
I want to be able to treat the pins of the chip like the GPIO pins of the PI – turning them on and off individually. Unfortunately I haven't been able to find a method in the Python smbus2 (or any other) library that allows me to set the value of a single pin. Instead I'm forced to read the value of an entire register (read_byte_data
), save it to a variable, change the bit in question, and then write the entire byte (write_byte_data
) back.
The problem is that when the value of other pins have changed between the reading and the writing, these changes then get overwritten. Does anyone know of a way to simply set the value of a single bit while disregarding the rest of the byte?