G-Code 101: Modify Your 3D Printing Files
What is G-Code?
RS-274 (more commonly known as G-code) is a programming language for CNCs (Computer Numerical Control) used in computer-aided manufacturing. The basic gist of the language is to tell tools/devices to “go there and do this”.
G-codes can be used on many types of machines, such as laser cutters, lathes, and milling machines. Best 3D printer. For 3D printers, G-code is typically created when an object is “sliced” for printing. Slicing turns an object into a series of layers. Layers move tools using G-code commands to mimic the outline and internal structure of an object. Common slicers like Cura and PrusaSlicer do all the heavy lifting for you, but if you want to make your own G-code for him, you can script it to tweak his 3D printer and make as much We can provide the best service.
In this how-to, you’ll learn how to write G-code. in particular, Clarity Ender 2 Pro as our test machine. Create a script to help manually level the print bed. The code written for this how-to was written for the Ender 2 Pro and will need to be modified for the 3D printer.
Create a G-code script
G-Code doesn’t require fancy text editors or IDEs. All you need is a simple text editor like Notepad, or our favorite Notepad++.
Each line of G-code is an instruction to a piece of the device, and commands are written using a command reference followed by command parameters (if any). Comments must be preceded by a semicolon to create a comment.
1. Open a text editor and create a comment line that explains the purpose of the code.
; Ender 2 Pro Example Control G-Code
2. Set the absolute position using command G90. This means that all movements are calculated from the same starting point.
G90; Absolute positioning
3. Use command M117 to display a message on the Ender 2 Pro’s LCD screen. The string (message) is just after issuing the command, no parameters are required.
M117 Tom's Hardware; Prints the string to the LCD screen
Four. Pause the script for 3 seconds using the command G4 (dwell).
G4 P3000; Wait for 3 seconds
Five. Use command M117 to display a message and use G4 to pause the script long enough for the user to read it.
M117 Heating bed; Prints the string to the LCD screen
G4 P1000; Wait for 1 second
6. Heat the print bed to 60 degrees Celsius using command M190 (S60). This command will stop script execution while the bed reaches the desired temperature.
M190 S60; Set the bed temperature to 60C and wait until it hits that temperature
7. Home all printer axes with command G28.
G28; Home all axis
8. Set the movement speed to 1500mm/min. This ensures that the bed and hot end move at the same speed. Higher, 3000mm/min is possible, but start slowly. That way you have time to deal with the problem.
G1 F1500; Set Feedrate (tool movement) to 1500 mm/min
9. Use command G1 to raise the Z axis 8mm so the nozzle is clear of the print bed. I don’t want the nozzle to crash into the print bed as it can damage the nozzle and bed.
G1 Z8; Lift Z Axis 8mm
Ten. Use the G1 command to move the nozzle to the set X and Y position. In this case, the position is directly above the left front bed adjustment wheel.
G1 X28 Y35; Move to position 1
11. Use M117 to output instructions to the user.
M117 Level the bed #1
12. Use M0 to wait for user input. Note that this command does not work with all 3D printers. If it doesn’t work, replace it with G4 and use a longer wait.
M0; Stop, wait for user input
<<If your 3D printer does not support M), use this for a 20 second wait>>
G4 P20000
13. repeat the same process Lift the nozzle, move to the next position, instruct the user and wait for input. Remember to replace her M0 with her G4 if your printer doesn’t support her G4. This will move the nozzle above the right front bed adjustment wheel.
G1 Z8 ; Lift Z Axis 8mm
G1 X140 Y35; Move to position 2
M117 Level the bed #2
M0; Stop, wait for user input
14. Repeat one more time. Now for position 3, the rear right bed adjustment wheel.
G1 Z8 ; Lift Z axis
G1 X140 Y130; Move to position 3
M117 Level the bed #3
M0; Stop, wait for user input
15. Repeat one more time. This time it’s position 4, the rear left bed adjustment wheel.
G1 Z8; Lift Z axis
G1 X28 Y130; Move to position 4
M117 Level the bed #4
M0; Stop, wait for user input
16. Use command G28 to home all axes and display a completion message (M117) on the LCD screen.
G28; Home all axis
M117 Complete; Bed leveling is completed
17. Save the code to your micro SD card as Ender2-Pro-Test.gcode.
18. Remove the card and insert it into the printer.
19. Push in the control dial to open the menu.
20. Scroll down to attach a card and press dial. You can now use your card.
twenty one. [カードから印刷]Scroll down to and press the dial.
twenty two. Select Ender2-Pro-Test.gcode and press the dial.
twenty three. [印刷]Select and press the dial to start. The printer follows the steps in the G-code file.
The code goes through each step of the process, mimicking the bed leveling process, but with the nozzles away from the print bed.
Once the process is complete, the nozzle can be lowered and used to semi-autonomously perform bed leveling.
complete code listing
; Ender 2 Pro Example Control G-Code
G90; Absolute positioning
M117 Tom's Hardware; Prints the string to the LCD screen
G4 P3000; Wait for 3 seconds
M117 Heating bed; Prints the string to the LCD screen
G4 P1000; Wait for 1 second
M190 S60; Set the bed temperature to 60C and wait until it hits that temperature
G28; Home all axis
G1 F1500; Set Feedrate (tool movement) to 1500 mm/min
G1 Z8; Lift Z Axis 8mm
G1 X28 Y35; Move to position 1
M117 Level the bed #1
M0; Stop, wait for user input
G1 Z8 ; Lift Z Axis 8mm
G1 X140 Y35; Move to position 2
M117 Level the bed #2
M0; Stop, wait for user input
G1 Z8 ; Lift Z axis
G1 X140 Y130; Move to position 3
M117 Level the bed #3
M0; Stop, wait for user input
G1 Z8; Lift Z axis
G1 X28 Y130; Move to position 4
M117 Level the bed #4
M0; Stop, wait for user input
G28; Home all axis
M117 Complete; Bed leveling is completed
Add G-Code with Slicer
Adding custom G-code to the slicer allows you to control every aspect of the printing process. Add a nozzle wipe before printing, preheat the bed to a custom temperature, and tweak many other settings for the perfect print. Here’s how to edit G-code with the two most popular slicers, Prusa Slicer and Cura.
Adding G-Code with Prusa Slicer
1. [プリンター設定]Click[エキスパート]Click. Note that this reveals all the features of Prusa Slicer.
2. Click Custom G-Code.
3. You can insert custom G-codes at the start and end of printing. This affects all prints sliced using the Prusa Slicer.
Four. Click Plater to return to preparing the object for printing.
Adding G-Code with Cura Slicer
1. Open Cura and[設定]>>[プリンター]>>[プリンターの管理]Click.
2. [マシン設定]Click.
3. You can now directly edit the printer start and end G-codes.
Four. Click Extruder 1 to edit the extruder G-code.
Five. Close the window and save,[マシン設定]Exit the dialog, then[設定]Close the dialog. Return to the prepare screen and you are ready to slice your new print.
Common G-code commands
instructions | Explanation | example |
---|---|---|
G1 | Linear movement between two points on the work plane. | G1 Z8; Raise the Z axis by 8mm |
Sets the feed rate (velocity) at which the motor moves in mm/min. | G1 F1500; set speed to 1500mm per minute | |
Extrude 25mm filament on 50mm line. (Convenient for nozzle cleaning before printing) | G1 X50 E25 | |
G4 | live. Adds a pause in milliseconds to the sequence. | G4 P1000 |
G20 | Set measurement units to inches | G20 |
G21 | Set units of measure to millimeters | G21 |
G28 | Home all axes | G28 |
G90 | Absolute placement. All coordinates are interpreted as a logical coordinate space. | G90 |
M0 | Waits for user input (usually a button press). Note: This command does not work with all 3D printers. | M0 |
M18 | Disable the stepper motor. | M18; all steppers |
M18ZE; disable Z-axis stepper and extruder stepper. | ||
M117 | Display a message on the 3D printer display. A message is a string containing letters, numbers, and punctuation. | M117 Hello World! |
M190 | Sets the bed temperature in degrees Celsius. | M190 S60 |
M410 | Sudden stop. Emergency stop of all stepper motors. Note: After this command, all axes must be homed as the stepper motor will be displaced. | M410 |
M500 | Save all settings to EEPROM. Use with caution as it will overwrite your current configuration. | M500 |
M701 | The extruder’s stepper motor is rotated for a period of time to load the filament. | M701 |
M702 | Unload filament for use when changing filament rolls. | M702 |