• You're one step from joining CNC Machining Forum – G-Code, Tooling, Automation & Pro Techniques.
    Create a free account to post, follow threads, and never miss an update.  Sign up free →

G-code help for foot-pedalled repetitive task

braunmann05

New member
Joined
Sep 7, 2025
Messages
2
I'm a bit of newbie to CNC and not even sure if my concern belongs here but I'm hoping you can help me with a project I'm working on with my brother. We're building a jig to help with some light woodworking. Essentially, it's a stepping mpotor attached to a small sanding drum. The idea is for the drum to spin a certain amount, stop at the same exact position, and then repeat this cycle with a foot pedal press.

We've got all the hardware hooked up, a Nema 17 1.2A 17CA02A-120 stepping motor, a DM556 driver, a Mach 3 breakout board and a foot pedal. We're using DrufelCNC for the software. We can get the software to communicate with the hardware, but it only seems to respond to G-code. I've done some reading on G-code, but I can't figure out how to program this specific sequence. How can I get the motor to start and stop at the same spot repeatedly with each pedal press?

Any advice on how to write the code for this or where to find more information would be a huge help! Thanks in advance!
 
To rotate something a full 360°, just set your machine to relative mode with G91 and then use a command like G01 A360 F100. Also, in DrufelCNC, make things even easier by setting your foot pedal to Cycle Start in the input settings, that way, each press gets the code running.
 
One thing to add is that if you want the motor to return to the same spot reliably over time, it's worth checking whether your stepper driver is set to microstepping and whether the motor has enough torque to avoid missed steps under load. Even small sanding resistance can cause drift if the motor stalls or skips.

DrufelCNC supports G04 for dwell, so if you want a pause between rotations, you can add something like G04 P1 to hold for one second before the next cycle. Also, make sure your G-code file ends cleanly with M30 to reset the program for the next pedal press. Have you tested how consistent the stop position is after several cycles or are you still in the early stages of tuning the motion?
 
Microstepping and torque are things you have to get right, you will quickly see skipped steps when running under load. Great reminders about G04 and M30. Clean cycles really do help
 
G-code will run it, sure, but you'll fight with sync unless you set exact step counts. A NEMA 17 on a DM556 is easy to overshoot if accel/decels aren't tuned. Start with really low feed rates so it always stops at the same spot. Once it's solid, bump the speed.
 
Back
Top