I've run into an issue where i need roughly 4 more digital inputs and I've been looking into a MCP23017 port expander but i see that uses analog 4 & 5 for I2C. Problem is, I am also using all 8 of my analog pins for measuring voltage every 5 seconds.
Could I somehow still use the expander during the 5 second window where I'm not measuring voltages?
I have never worked with such devices so I'm confused as to how exactly they will work in my situation
I forgot to mention I'm using an SPI display too so if I was to use an SPI expander I would just drive the expanders slave select low to use the extra pins while driving the display's slave select high (and vice versa to send data to the display)?
Thanks
To answer your original question, no you can't use pins A4 & A5 as both analog inputs and i2c in the same circuit. When used as i2c, the pins become outputs, and if they are connected to an external voltage, a damaging short circuit could happen. At the very least, the external voltage would disrupt the i2c signals.
You could add extra analog inputs to your circuit with an i2c adc module such as ads1115, replacing the two you loose by using i2c (and adding 2 more). But in this case, the SPI I/o expander suggested by Delta_g seems the easier option.
Why have you run out of pins? If you share your circuit diagram, perhaps we can suggest ways to free up other digital pins, maybe even without using an extra chip.
Maybe a shift register will be a cheaper alternative to the port expander if you don't need a true I/O. For outputs you may use 74HC595 to drive LEDs or something similar which does not change too often.