Custom Buttons in Pronterface: An Intro to GCode

The place to share your best tips and tricks for the best prints.

Moderator: Elijah

Elijah
Site Admin
Posts: 767
Joined: Wed Oct 10, 2012 6:33 pm

Custom Buttons in Pronterface: An Intro to GCode

Postby Elijah » Fri Mar 29, 2013 2:22 pm

A 3D Printer, like all CNC Machines works through the procedural language of GCode. When printing, your computer (or an SD card attached to the printer) reads off a .gcode or .gco file one line at a time, and your printer acts it out. Here is an example:

G1 X200 Y200 Z200 F10000


This means: perform a coordinated movement (G1) such that the X, Y and Z axis will be 200mm away from their home positions (X200 Y200 Z200) and do so at a feedrate of 10000mm/s (F10000)

The coordinated movement will actually go far less than 10000 mm/s because there is something of a "speed limit" set in the machine's firmware. So F10000 really is our way of saying "go as fast as you safely can."

Gcode gets much more complex than this. As part of it, there are a whole family of terms that are known as M-codes. M-codes control various operating aspects of the machine. For example:

M104 S185


This means: Heat up the printer (M104) to 185 degrees Celsius (S185).

In your printer control software, there is a command line through which you can send GCode to the machine manually, in some cases during a print. (During a print, if needed, almost always will you be sending M-codes).

In Pronterface, you can create custom buttons that will send frequently used GCode commands to your printer. To do so, right-arrow click either the "SD" "Print" or "Pause" button and choose "Add custom button". Since I use these machines all the time, as well as do quality assurance tests on them, I have a lot of buttons. Here's what mine looks like:

Image

As you can see, I have lots of buttons, grouped by color.

The Yellow ones are all about coordinated movement--moving the machine while it's not printing. This is fantastic for bed leveling (move to the 4 corners) and moving to what I call a 'safety position' after a failure, assuming the failure IS NOT more than a few inches tall when it fails.

Red and Blue are about cooling systems for the extruder.
Cyan and Magenta are concerned with the temperature hot end.

Green buttons are somewhat miscellaneous. I'll explain them a moment. Here are what each of the button do and why:

By the way in hex color code:
Yellow is #FFFF00
Red is #FF0000
Blue is #0000FF
Green is #00FF00
Magenta is #FF00FF
and Cyan is #00FFFF
You need to know the hex code of the color you want to specify it when adding the custom button.

"XY Front Left"
The Command is
G1 X0 Y0 F10000

"XY Front Right"
G1 X260 Y0 F10000

"XY Rear Right"
G1 X260 Y230 F10000

"XY Rear Left"
G1 X0 Y230 F10000

I use the above commands for bed leveling. Highly recommend it. Just remember to do it while your extruder is cold, or you'll risk melting the platform!

"X130 Y115 Z115"
G1 X130 Y115 Z115 F10000

The above is my safety position, which is the special center of the work area. Not to be used unless the failure print is shorter than 115mm, which is almost always the case.

"Fan ON"
M106 S100

"Fan OFF"
M107

For turning the extruder cooling fan on or off. "S100" refers to a percentage. You can PWM your fan (though there is no functional benefit in the current Series 1 design). For example, half speed would be "M106 S50". The fan needs enough constant voltage to stay running, so don't expect it to work below S30ish without a helping spin.

"Heat to 185C"
M104 S185

"Heat to 195C" is just the same thing with the different number, and "Heat OFF" is the same but with a zero instead.

"Z115"
G1 Z115 F10000

Moves the platform so that it's 115mm away from the hot end. "Z25" would be "G1 Z25 F10000".

"Home XY"
G28 XY

G28 is the homing command. (Your machine does this at the beginning of every print.) Sending G28 alone will home all axes. You have to specify which ones you want to home as shown above. There is no feedrate in a G28 command because the firmware specifies the homing speed.

"Allow Cold Extrusion"
M302

I use this for testing purposes. When I need to see if the polarity of my E-motor is correct (if its hooked up right) I plug the motor in, press this button, and then do a test extrusion with no filament loaded. It checks out if it goes in the right direction. M302 disables what's called "Cold Extrusion Prevention" where the E-Motor is disabled when the hot end is colder than a firmware specified temperature to reduce the risk of clogging and related mechanical errors.

There are so many different G and M codes is Marlin, and I encourage everybody to make custom buttons and get comfortable with them. It's really quite easy to learn.

Go forth and GCode!

https://docs.google.com/document/d/1px- ... w58pz36c0d
Elijah Post
Type A Machines

Rodwagner
Posts: 261
Joined: Mon Dec 03, 2012 5:00 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby Rodwagner » Fri Mar 29, 2013 2:42 pm

Thanks Elijah. Didn't know about custom buttons! Maybe I will start using Pronterface more....

Liquid
Posts: 579
Joined: Sat Feb 16, 2013 12:46 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby Liquid » Fri Mar 29, 2013 4:21 pm

This is pretty cool :D

Elijah, I want one of those testing spool holders :twisted:

LaserGnomes
Posts: 1058
Joined: Thu Dec 06, 2012 10:15 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby LaserGnomes » Fri Mar 29, 2013 9:33 pm

It's super easy... we added "fan 100% button" like day two.

Erat
Posts: 9
Joined: Thu Mar 21, 2013 12:44 pm
Location: Houston TX

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby Erat » Mon Apr 01, 2013 11:30 am

Well done write up!

LaserGnomes
Posts: 1058
Joined: Thu Dec 06, 2012 10:15 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby LaserGnomes » Sun Apr 14, 2013 11:26 pm

We added some Custom.. custom buttons. LOLZ
Attachments
CustomButtons.jpg
CustomButtons.jpg (178.45 KiB) Viewed 12748 times

Liquid
Posts: 579
Joined: Sat Feb 16, 2013 12:46 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby Liquid » Mon May 13, 2013 2:13 am

Just want to mention that the PWM (Pulse Width Modulation) ranges from 0-255.

So if you want a custom button that turns your fan on at 100%, the code would be:

M106 S255


vs

M106 S100


This would be particularly important for those who do a manual warmup, before starting a print, as the fan will be running at the same level while warming up as it would be while printing.

If you normally run your fan during a print, at a different percentage, you can calculate the S(value) using the following.

Percentage Wanted / 100 * 255 = S(Value)


So if you want a custom button that turns your fan on at 80%, you would use the following.

80 Divided by 100 Times 255 = 204, Value is S204, Fan is on 80%
80/100*255

70 Divided by 100 Times 255= 178.5, Value is S178 or S179, Fan is on "near" 70%. S178.5 would probably work, but its probably better to use a whole number.

etc.

LaserGnomes
Posts: 1058
Joined: Thu Dec 06, 2012 10:15 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby LaserGnomes » Mon May 13, 2013 11:28 am

TheTechGuru wrote:
M106 S255



Yeah that's what ours says. M106 S255.. confirmed 100%.

psutex
Posts: 1
Joined: Mon May 20, 2013 3:40 am

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby psutex » Tue May 21, 2013 12:43 pm

Elijah,
This is a great write up, I now know what I can do and how to do it, but I don't know what the command is for what I want. I sometimes drive my steppers into something hard and the motor stalls, belts slips, terrible noises are produce. First I should learn not to do this, but I would like to create a kill switch. Currently I turn the power off from the power supply. Is there a way to turn the power off to the motors? Is that really what I want? Thanks.
psutex

LaserGnomes
Posts: 1058
Joined: Thu Dec 06, 2012 10:15 pm

Re: Custom Buttons in Pronterface: An Intro to GCode

Postby LaserGnomes » Tue May 21, 2013 5:53 pm

No... you ideally want to just stop the interaction.

Interaction is typically a result of curling or bad bed leveling. No amount of coding will overcome that... inversely some attention to leveling and z-height should remove those problems.

If you are talking about the random cat paw that gets in the way... yeah that's just life. Sadly the motors don't have a resistance sensor or anything to my knowledge that would allow them to auto kill upon impact.

Typically if something is physically interfering with the machine... turning off the power to the machine entirely is best as it will power down the steppers allowing you to freely move the gantry.

That said.. once you've freely moved the gantry.. when you turn it on.. it has no idea where it is. So you need to click the master home key to "reconfigure" where home really is after the manual offline movements. If you move the gantry while off and attempt to home a specific axis instead... it will not "reset" home and you will get a bunch of noise as the motor tries to push through the physical limitations to meet what it thought was home coordinates.

-2 cents.


Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 1 guest