I wrote a program to run a stepper motor with arduino. There are buttons to change the speed and direction in the program and a I2C display to display the running parameters. But the program freezes randomly when I press the button. The issue is very common and occurs only when I change the running parameters.
What could be the reasons for freezing? How can I fix the issue?
Your picture is missing some major things such as power to the stepper motor. Also you need to post links to the motor, motor driver, display module. If that picture is exactly as you have wired it I highly recommend getting some spare Arduinos and motor drivers as you will be frying them.
Sorry for not mentioning that the link i shared shows only the high level of the program. The Nema 34 stepper motor that i use actually has a controller and a power source. I have attached the images for your reference.
You are most likely having EMI problems with all the power and logic is close proximity. I will take a SWAG and expect your box to get overly warm when operating. Powering via the Vin is helping you but apparently not enough. We need the other parameters requested to hopefully solve your problem. EMI can be an extremely difficult problem to solve when there with the hardware, even worse at a distance.