Welcome! Log In Create A New Profile

Advanced

Create your own G code?

Posted by Kyle R 
Create your own G code?
August 16, 2014 04:20PM
Hey All,

Is it possible to make your own G-code command and have the g-code generator include your command when generating the code? I would like to have a pin on the Arduino go high at the exact moment material would need to be extruded on the build platform. I'm having a syringe deposit my material pneumatically, and so the Arduino pin controls a valve that allows flow. How would I stop the G code generator from producing the filiment extruding g-code while including my own command?

Thanks!
Kyle
Re: Create your own G code?
August 16, 2014 09:56PM
before i go into this on how to make your own g code. i should state that m126 and m127 does just that for a valve. i do not know how to set it up though, nor do i see an easy way to configure it

yes it would be easier if it was a M command.

look at used m codes here:
[reprap.org]

then look at gcode compliance here [en.wikipedia.org]

M stands for Miscellaneous function

in marlin for example there are no M codes from 700 to 800.

so choose a code number my example will have M700
and program in the case section of marlin_main.h around line 1822, before the line case 31: //M31 take time since the start of the SD print or an M109 command

you will need to initialize the pin or define it in configuration.h such as #define yourpin

also you will need to set the pinmode and also the pin state in the void setup () of marlin_main.h
such as before line 423 adding this code:
pinMode(yourpin,OUTPUT);
digitalwrite(yourpin,LOW);

and program in the case section of marlin_main.h around line 1822
in the code below sending M700 causes pin to high, and sending M701 causes pin to go low.
add this

case 700:
pinMode(yourpin,OUTPUT);
digitalwrite(yourpin,HIGH);

break;

case 701:
pinMode(yourpin,OUTPUT);
digitalwrite(yourpin,LOW);

break;



you will want to make sure the code works, then i would move the case 700 and 701 to the end of the m codes section, and then also change the digitalwrite to the much faster write
Re: Create your own G code?
August 17, 2014 05:55AM
Quote
Kyle R
How would I stop the G code generator from producing the filiment extruding g-code while including my own command?

You don't. As about all firmwares feature a movement buffer these days to allow uninterrupted moving, M codes are not neccessarily in sync with movement commands.

That said, you can handle a valve just like a heater, using M106 S255 to turn it on, M106 S0 to turn it off.

To solve your problem, it's likely a much better idea to tweak the firmware instead of messing with the G-code generator. E codes conveniently show you when to turn the valve on and when to turn off. As E is a movement command, it's in snyc with other movements. In Teacup firmware, the valve on command would go into dda_start() in dda.c. Valve off into dda_step() in the same file, where the check for movement end is done.


Generation 7 Electronics Teacup Firmware RepRap DIY
     
Re: Create your own G code?
August 18, 2014 03:41AM
Thank you both for your thorough replies, I'm now really starting to get a strong feeling for how G code is structured. My next conceptual challenge is how to get the slicer to actually include those commands within the code itself. I have been able to manually enter g code commands and get my valves to open and close with my modified firmware, but am having trouble finding how to get them included in the g code program automatically.

Thanks again!
Re: Create your own G code?
August 18, 2014 12:51PM
Quote
Kyle R
Thank you both for your thorough replies, I'm now really starting to get a strong feeling for how G code is structured. My next conceptual challenge is how to get the slicer to actually include those commands within the code itself. I have been able to manually enter g code commands and get my valves to open and close with my modified firmware, but am having trouble finding how to get them included in the g code program automatically.

Thanks again!

Starting and ending g-code sections.
Re: Create your own G code?
August 18, 2014 03:12PM
The starting and ending g come sections are for before and after the entire print, or so I believe. I am replacing my filament extruder with the valves, placing material with the valves as the business end. Therefore I need commands to open and close valves in the same way commands would be send to the extruder motor to push more filament through, or stop pushing filament, etc. Is this sort of modification in the slicer possible, to include my valves instead of including the filament extruding code?

Thaniks!
Re: Create your own G code?
August 18, 2014 03:30PM
Perhaps you can write a g-code post-processor?

Andy
Sorry, only registered users may post in this forum.

Click here to login