Just to start out, i am new to the arduino world. I have designed a cnc pen plotter that uses a stepper motor for the X & Y axis and i would like to use a servo to control the Z axis. Im using UGS to control this thing. The board im using is an Arduino Uno R3 with a protoneer cnc sheild Ver. 3.0 with d4988 drivers.
The problem im having is I cant find a code that will allow me to do what im trying to do. I need a simple code to upload to my Uno so i can just control the machine. If anymore info is needed I'll give it. I have tried the Grbl 1.1. Please help
Hello
Take some time and get a look here:
https://create.arduino.cc/projecthub
Have a nice day and enjoy programming in C++ and learning.
I think UGS means "Universal GCode Sender". That means you need a GCode interpreter on your Arduino. Protoneer.co.nz says their Arduino CNC Shield V3.0 is "100% Grbl compatible".
What happened when you tried?
I can move the x and y axis with the UGS software, but I can not figure out how to control the servo for the z axis. Also when I hook the limit switches up and enable them I get an alarm for the z axis. I'm probably not doing something right. I built this pen plotter for my boy and I. It has been 3 weeks trying to figure out how to get this thing working. When I get home I'll get a few pictures of it and how it is wired up. Am I supposed to go into the library and change a setting before I load it on the Arduino Uno?
The servos that I am using are the SG90 servos off of Amazon. Nema 17 stepper motors.
I've played around with the Arduino Uno a little bit before I tried loading the GRBL library on it. I practiced with the blink code a little bit, also played around with a joystick and servo, and the temp/humidity sensor. I got the sensor kit off of Amazon to play around with. I was able to get those working no problem, but this CNC has me aggravated right now.
Another thing I got is a KEYESTUDIO MEGA 2560 off of Amazon so I could have the Uno R3 for the CNC. I am trying to learn as much as I can about the Arduino as I can because I find it interesting.
Thanks for the help!
That sounds reasonable. On a 3-axis CNC machine the Z axis would usually be a stepper motor and, by default, GRBL will send step and direction commands to the third stepper driver to move the Z axis.
I don't see an easy way to tell GRBL that you want to use a servo as the Z axis. Maybe you can treat the servo as a spindle (router motor) or a coolant pump and change those parts of GRBL to move the servo.
That's my problem, I don't quite know how to do that. I have been trying to figure it out, but haven't yet.
My guess is that you have to modify libraries/grbl/spindle_control.c
Things are going to get funky since "Servo" is a C++ object so you can't use it in a "C" source file. I wonder what would happen if you rename all of the .c files to .cpp. Give that a try. C++ is almost completely backward compatible with C. 
As promised, a few pictures of my setup. Been thinking about it and I may just make a new z axis with a stepper motor and lead screw.
Somewhere in the library there's a function that steps the Z stepper motor, right? It should hold a step count variable, which tells the Z coordinate of the tool tip or the pen tip or whatever the CNC machine is about. I guess you should find that function, hijack it and convert the step count to a servo angle. Also there's a calibration routine or a zeroing routine. My idea is that most of the GRBL lib could run normally, "thinking" there's a stepper motor for the Z axis, too. So when your G-code says something like:
G00 Z5.000000
G00 X37.043198 Y3.023990
G01 Z-0.100000 F80.0(Penetrate)
... the servo lifts the pen to 5 mm above paper (whatever angle that translates to), steps the X and Y steppers to the given coordinate, then the servo presses the pen tip to 0.1 mm below paper (while a spring prevents that from actually happen).
I still haven't figured out what im doing wrong. There are numerous people that have built the XY core plotters that use a servo as the Z. I have found a library that uses the d11 pin to control the servo. My question now is, the instructions say to replace the repo grbl.h file in the arduino library with the modified version. Am i just supposed to overwrite the file that is in the ide files? Help is appreciated.
Here are is the link to the page I am referring to. Also this post has a link to the modified GRBL files.
This build is similar to what I have, but mine doesn't included a RasberryPI.
That GitHub project contains a complete replacement for the entire 'grbl' library. Just replace the original 3-Stepper version with this 2-steppers and a servo version.
If you need the original 'grbl' for anything you are going to have name conflicts. It might be possible to rename the plotter version so it doesn't conflict but that will take some work.
Could I possibly same the replacement file as grblb.h? I do plan on building a cnc router using pretty much this same setup, but with an actual Z-axis.
You could rename the 'grbl' folder to 'grblb' and rename the 'src/grbl.h' file it contains to 'src/grblb.h' but remember that you have to change "#include <grbl.h>
" in every source file in the library to "#include <grblb.h>
".
I finally got it to work last night. I uninstalled everything from my computer and downloaded new files, even the Arduino IDE application. I installed the modified grbl to the IDE library and uploaded to the Uno board. I was happy when i opened UGS and connected everything and the servo moved up. Now i can finish this pen plotter. I had it draw a picture last night, it turned out ok, i need to make adjustments in the settings to get it to draw better now. Thank you for the help.
I'll post a picture of the picture that i drew with it later.
1 Like
As promised, a few pictures. The first one didn't turn out very good. That may have been in the settings and/or the cnc moved while drawing.
The second plot turned out much better.
I'm glad I was able to figure this thing out. I have way to much money in it to give up on it. I have a few parts that I need to design for it to make the final touches, but right now it works, so I am happy. It was a sigh of relief when I turned the machine back on after uploading the modified GRBL file to the UNO and the servo went up like it should have. Then I spent time figuring out InkScape so I could have a GCode to print. Thanks for helping me figure out what I needed to do in order to get this thing to print.