I'm not familiar enough with steppers and the gshield to write a sketch to that. Maybe it's easy, I'm not sure.
When I first installed the limit switches, I had the shields from the limit switch wires and the shields from the stepper motor wires all connected to the Arduino ground. When I turned everything on, it immediately went into alarm mode because it thought a limit switch had been tripped. If I reset the alarm, it would just go right back into alarm mode for a limit switch.
The next thing I did was disconnect the motor shield from ground and just let it float. This helped a lot, the machine didn't go into alarm mode as before.
I put my scope on the input as shown in a previous photo and I looked at the signal under both scenarios above. With the motor shield connected to ground I had big oscillations, ringing or something. It was a couple volts p-p. When I had the shield floating, it was much better. A number of people who have the same CNC router (a ShapeOko) report that they have problems with noise and the limit switches. What I'm trying to do now is just decrease the noise as much as possible to minimize the chance of false limit switch triggers.