MCP23017 to read hall sensors

Wait. Are you trying to use I2C?

Then you have to hook SCL and SDA to specific pins on the Mega.

a7