After many hours tinkering, pulling things apart, testing them and re-assembling them, it turned out that the problem was a broken wire for the X_Min endstop. This has now been replaced and the problem is resolved.