I2C LCD pins interfere with Interrupt limit switches

I got a problem with my Arduino AG Board Mega 2560 (https://www.voelkner.de/products/304449/Arduino-AG-Board-Mega-2560.html?offer=49082ba34f74056f0b7fa8018f4ede3a). I’m building a machine with four stepper motors and a Geekcreit® IIC I2C 2004 (https://de.banggood.com/Geekcreit-IIC-I2C-2004-204-20-x-4-Character-LCD-Display-Screen-Module-Blue-Geekcreit-for-Arduino-products-that-work-with-official-Arduino-boards-p-908616.html?akmClientCountry=DE&rmmds=search&p=X0110142748584201912&custlixnkid=723808&cur_warehouse=CN), that needs four limit switches accordingly.

I only have four pins that work with interrupt and two of them are SDA and SCL. These four switches are connected to D19 to D21, where D20 and D21 are apparently parallel to the SCL and SDA pins next to the reset button. As soon as I plug in the limit switches the LCD stops working.

Does anyone have an idea how I cloud isolate the pins next to the reset button in the software or are they physically hooked?

Problem_mit_den_Interruptpins_2.ino (1.43 KB)

You can also use pins 2 and 3 with attachInterrupt() on a Mega. Can you change the connections from 20 & 21 to 2 & 3?

2 and 3 are blocked by the CNC shield.

OK. So another thought:

Generally speaking, limit switches and -- especially -- e-stops should act on hardware. They should not rely on firmware seeing a limit event and halting a motor. That should happen by the switch acting on, say, the enable of a motor driver (e.g. L298A). The CNC shield I've seen has "end stop" inputs to which, I presume, the limit switches would be wired.

For emergency stops, all power should be cut to the motor(s) to prevent the possibility of a motor turning in a hazardous situation. This means a contactor in the power path to the motor driver. E-stops, if you want to use that term, really should be dual-channel for redundancy. Again, the CNC shield I've seen also has an e-stop input. I doubt it cuts power but it's there.

Running limit switches and e-stops to the MCU for the purposes of monitoring and reporting are ok but you shouldn't really rely on firmware for safety.

Having said that, are you sure you need interrupts for these input or can you simply monitor them by polling? With well-crafted code the monitoring interval should be small...