Strange results from encoder in main program but not in test environment.

Hi There,

I am currently building a machine to assist me cutting fabric from a roll to desired lengths in my small canvas shop. I have done several other Arduino projects but am just still figuring a lot of things out. This project has been my most ambitious and have it nearly completed but I have a few nagging issues I have tried hard, but failed to resolve. The main one I am currently dealing with is in regards to an encoder closing the loop on the main drive pinch rollers. A closed loop is more desirable than simply relying on the steppers because the material can slip as its being pulled through.

How the machine works:

The main chassis is an old large format fabric printer (like a vinyl cutter). I have a Large Stepper driving the main pinch rollers and a smaller stepper attached to the gantry with an electric saw on it. I has a Rasperry pi GUI screen where I can enter values and then when I hit start it sends a command to the main Arduino Uno. The Arduino runs the main driver via Accel Stepper to the length. BUT THEN: it checks via i2C with an Arduino Nano(slave) connected to an Encoder wheel that has been running on the fabric. It gets the value and corrects for the length before running the cut sequence.

This whole thing works properly until I get to 6.1 inches which is one revolution of the encoder (could be a red herring). After that it says it traveled 6.1 inches. Once it hits about 10 inches it sends back zero.

The weird thing is that I have the encoder sending and receiving properly in a test code. Thank you, JB

Jack_the_Splitter_1.3.ino (16 KB)

JTS_ENC_SLV.ino (3.21 KB)