Thanks for the code.
Can You post the schematics especially showing the motor area? I can't see what circuits You use, what pins You use from the picture. Pictures like that are never used among engineers.
Schematics tell pin designation, powering, voltages....