Hi Mikey, sincere thanks for this tutorial. I had previously been struggling to figure out how to do this but you explained it really well. This will open up a lot of new options for me in my research. Thank you again!
Never a problem, I have another video coming up where I use this to trigger the shutters of multiple cameras between layers for the ultimate in smooth 3d printing timelapses :)
Hey there good man. This i my seccond account on YT. I made dual filament add-on on crelity stock board with that info you helped me custom gcode/buck converter for servo. I didnt have buck convertor so i used USB plug xD you can watch two shorts on this channel! You are best man! Cheers!
Goodnight! I really liked your explanation! I wanted to know if I can use the board's pins to read information, as if it were a "digitalRead" on the Arduino. I wanted to put physical buttons that when pressed, could send the programmed gcodes! Thanks for the tutorial and the great lesson!
@@MikeysLab WOW!!! Incredible!!! My board is an SKR 1.4 TURBO, but I believe it's the same for all, right? Do you have any tutorials in this regard? I program well with Arduino, but I'm kind of lost in Marlin! REALLY THANK YOU SO MUCH!!!
Hi Mikey, 🙂 First of all, i loved the tutorial, you provided on adding custom Gcode. With that said, i have a couple of questions regarding adding or changing, what i think are Gcode related items. But first a little background on my level of programming skill. While i am Not quite a n00b, i would honestly critique my Marlin/Arduino/Raspberry pi/ CPP/ skillsets as somewhere between beginner and intermediate) i have done a few Arduino projects successfully, but i really haven't done any serious programming since the way, way. Waaaayy, back days of Ahston-Tate dBase III+ 1.0/1.1/2.0 & Clipper 5.0 days, from Last century. Since then, i have gotten back to studying C++ & Python, which has helped refresh my memory on Conditionals ( if / endif)( do while / end do ) ( if / then / else), etc.,... Now, Onto my questions; 2 years ago, I picked up an Ender 3 pro which had a stock Creality 1.1.4 board. And for a while things were good, until they weren't. About 7 months ago now, I changed out the guts of the printer with a BTT SKR Mini E3 2.0 board running Marlin 2.0 and the BTT 3.0 Touch panel display. Along with an Actual BL touch sensor. I LOVE how this board makes the printer now run virtually silent as compared to, the stock creality board. However, 1 annoying thing i have found is, when a print is finished, the build plate, slides to the back of the printer, unlike how the old Creality board moved the build plate to the front of the printer. What line(s) of code do i need to change in Marlin, to write to the firmware, that will make the build plate, move forward to the front if the printer, at the completion of job?
Yeah there are a couple of ways you could do that. The easiest way would probably be to modify marlin to push debug information to a secondary serial port (assuming your controller has one) then use an Arduino to receive the serial and control the secondary display. Option 2 would be if you controller has enough free pins to handle another LCD you could modify marlin to use the other pins to control the second LCD, this way would be very pin expensive. I suggest the first one, in the end you have an LCD that can accept a serial stream and display it, that becomes a very useful tool for other projects as well.
Hi Mikey! Hope you’re ok. Was just playing around with this in Marlin 1.1 and wanted to create a custom bit of gcode to completely remove a bit of filament from the extruder automatically. Was just wondering if you knew how you can call the gcode_G0_G1() function within a custom gcode to extrude as if a G1 E-100 is called?
Hi Mikey! As far as you’re aware has anyone used this to send a signal to a custom bit of hardware that automatically changes filaments at a defined layer height?
Hi Mikey, first of all, thanks for taking the time to show this stuff! I have a question regarding a weird custom command I'm trying to make involving motion and external sensor. Basically, my code should move an axis (X axis, for instance) until it hits a special endstop (not the one used for homing, but a seperate one wired specifically for this). At first I thought I could just copy paste the homing code, but the problem is that it's important that I record the distance moved as it's nearing the endstop. In case you're curious, I'm trying to make a routine for a printer with two X carriages (IDEX) that homes both printheads on the same endstop to determine the nozzle offset. My second thought was to just do some basic coding: make a loop that steps the axis while polling the endstop until it hits (I'll worry about accuracy later). My question is, is there a way to do these kinds of simple movements in Marlin, or do movements require a lot of preamble code to run? I tried looking at motion.cpp but it didn't help a lot (my coding experience is limited to slightly advanced Arduino projects). Maybe I can brute force it by spamming G1 commands in a loop? That brings me to a side question: in some comments you mentioned you can call Gcode commands from within your custom code, how does that look as written code? I assume you can't just write " G28(); " I hope my question isn't too unclear or extensive... Again, thank you for this amazing tutorial! You've definitely earned a sub!
Yes you can just call g28(); it is just a function in the source. I am not familiar with the motion commands, but here is how I would investigate. I would look up the gcode commands for motion, find the calls in the gcode function that seems to cause the motion, right click on the function and choose find all references, keep going down the rabbit hole till you reach the point that we are actually telling the stepper motor to do something, then work backward to the point it makes sense to start your custom code. I can look into this when I am at a computer if this doesn't put you on the right path.
@@MikeysLab Hi Mikey, I managed to get my steppers moving, thanks for the help! I had one more question regarding calling gcode commands like G28() from within the code. Is there a way to pass parameters to the gCode command? For instance to call "G28 X" or "G1 X20 Y20" like you would in a normal piece of gCode? Internally the gcode seems to get its parameters from the parser (like the example in your video), but I can't seem to find out how to pass them on from the code itself.
I will post a more complete answer after work, but I believe dwell uses a millis() structure to have an event wait for a specific amount of time, but allowing the main code loop to continue and check on every iteration if the delay has elapsed. I am doing a horrible job explaining it lol. I will provide an example after work 😁
I am glad the video helps. During the Marlin configuration you specify a board and processor. This is part of Marlin's Hardware Abstraction. Pin 29 is mapped to a specific pin on the micro controller as defined by the board definition.
The easiest way to do this, depends on if you want to move one of the normal steppers the board already knows about. With that you can simply invoke a G0 command in the source of your function. Move other motors would require either customizing the firmware to add another known stepper in the normal configuration, or in the case of an additional servo, doing direct pin manipulation
Mikey, Brilliant! Excellent tutorial for what I need to do for a custom 3D concrete printer priject. You have saved me tons of time. While this is not critical for my project, the LCD has FFF-like menus that I would like to change beyond the custom user menu scheme already included in Mariin 2.0.7. For example, the Temperature menu is not needed; can you give me some input on its removal? I am playing around with "menu-main.cpp" and making progress. Also, I would like replace Temperature with specials just like you show in this video which represent custom gcode except it is called from the LCD. You mentioned a better than platformio plugin but I didn't catch it from your talk. More input, please.
Yeah boss, Marlin is very modular, so it is just a matter of finding the menu section, then using the "find all references" to see how it all connects. The main IDE I use is Visual Studio Community with the Visual Micro plug in. I am working on a C++ for microcontrollers series where I will be going in depth into the more technical weeds of coding in these constrained environments
OK, success both removing an LCD menu and adding one but more importantly, I followed your coding example and was able to add my own custom G-code which while simple is a good prototype for more of them. If I hadn't made one type, a ")" left out, this would have finished an hour or so sooner. But All Good Now. Many thanks and cheers, to you, Mikey.
Awesome brother. We have all lost hours (or in my case days) over a missing ; lol. That was many moons ago before compilers would give you any reasonable error codes lol
Hello and thank you for this video! It helped me a lot to add my custom gcodes, I wouldn't have succeeded without it. I had a question though, you use the dwell function, and if I understand correctly, this function allows Marlin to continue to perform its actions in the background. The function I created allows to activate pins connected to an arduino board that drives servomotors with an independent program. The problem is that the arduino board has difficulties to send commands to more than three servo-motors at the same time, so I would like to add a delay to the function that activates each pin so that if I send two commands in a row, marlin will leave a delay after the first one before executing the next one. Dwell is not suitable, and I have tried "delay" which does not seem to work either. Do you have any idea what function I should use? Thanks in advance for your help!
I would try using a millis() delay with a while loop. Be careful with this, every delay you do like this will block the processor and stop the main loop.
@@MikeysLab thanks for your fast answer ! I’ll try this this afternoon. My gcode will work only at the beginning of my milling (it’s on CNC) And, my board is a STM32F4. Do you think « millis() » function will work on it ?
@@Phoquounet yes millis() is a built in function, it will return the milliseconds since boot. So some thing like this: long start = millis(); while(millis() < start + 5000) { //do something while waiting, or not :) } Results in an approx 5 second pause.
@@MikeysLab great ! I’ll try this and tell you if that work ;) Thanks ! PS: for pin write, I use “OUT_WRITE(IO, V)” and my gcode take P for the pin and S for enable or disable pin.
hi5 for the video, i need to make the same but with a endstop to control the door switch so when is open the door the printer pause, can you make some help?($$)
That is actually simpler than this mod. I would use an Arduino with the switch connected to an interrupt, then you can use one of the serial ports on the control board and have the Arduino send a M226 to the board. If you are lacking an available serial port you would need to make an extra IO pin an input, add it to the polling loop (duplicate the end stop code) and trigger the M226 command inside of marlin itself. Can I build it for you, no. But I think I have given you enough information to build it yourself.
Hi, thanks for your video really helpfull, i'm on an skr mini e3 1.2, i need to use 2 different free pin for 2 different script on an arduino, i think i'll use the NEOPIXEL PC7 pin which i don't use and the PT-DET PC12 pin, i d'ont know how to specify it in the gcode command: M6453 P7 S50 Do you think this will work ? Because i'm wondering how marlin make the difference between PC, PB or PA pins?
On the skr there is a difference between PA, PB and PC these are port A port B and port C respectively. There are many other marlin gcodes that take a pin number, I would find one of those and work backwards to determine how the pin is specified. For your case you could just remove the pin definition as a parameter in the gcode and hard code it (since you will be using it for yourself) I did it as a parameter to make it more useful for other people.
Hello good man! Can you give me any advice how to control servo motor with creality v4.2.2. board. I think that i can reuse BLtouch connector and reporgram it, but i dont know where to start. Any advice would be helpfull! Cheers!!
Yes you can or any other pin capable of PWM. From there you want to determine the #define for the port and pin ID for the probe servo. Search for all references for that designation, at some point this will lead you to the actual commands the set servo position
@@MikeysLab i didi it. It wasnt too hard. Thx once more! I have new problem. Whan i use servo motor (MG 996R) my display stats to flicker and i gave blank screen. I think that there is something with voltage drop... I turn of than turn on my Ender 3 (4.2.2 board) and everything is normal...
Yup, more specifically over current resulting in a voltage drop. I would feed the servos +5 directly from a buck convertor off of the PSU, servos are always hungry little guys
@@MikeysLab problem solved!!! I didnt have buck converter but i used USB chrager, grounded servo and USB cable to board, pluged V+ to USB and conected signal pin to board. Works like a charm, didn't have any problems with display even whan I stalled servo. Thanky you very much good man!!!
@@MrMun33 never a problem, if you're subscribed stay tuned for some great content, been filming alot the last couple of weeks now just need to sit down and edit, including over hauling and upgrading a old 5 print head liquid cooled printer 😃. If you not subscribed, why wait lol
The IDE is VSCode which is the most common IDE for compiling modern versions of marlin. The Hardware is the board that come with the Ender 3, which is the most popular printer. So I am not sure I understand your comment.
Hi Mikey, sincere thanks for this tutorial. I had previously been struggling to figure out how to do this but you explained it really well. This will open up a lot of new options for me in my research. Thank you again!
Never a problem, I have another video coming up where I use this to trigger the shutters of multiple cameras between layers for the ultimate in smooth 3d printing timelapses :)
Fantastic! Have you already implemented a command that waits for a button to be pressed to continue?
Hey there good man. This i my seccond account on YT. I made dual filament add-on on crelity stock board with that info you helped me custom gcode/buck converter for servo. I didnt have buck convertor so i used USB plug xD you can watch two shorts on this channel!
You are best man! Cheers!
This is an excellent tutorial (Best i have seen on here) and just what i was looking for.Thank you and keep up the great work
Good video mate, well done
Goodnight! I really liked your explanation! I wanted to know if I can use the board's pins to read information, as if it were a "digitalRead" on the Arduino. I wanted to put physical buttons that when pressed, could send the programmed gcodes! Thanks for the tutorial and the great lesson!
Yes you can use them as input, probably best to add an ISR for that
@@MikeysLab
WOW!!! Incredible!!! My board is an SKR 1.4 TURBO, but I believe it's the same for all, right? Do you have any tutorials in this regard? I program well with Arduino, but I'm kind of lost in Marlin! REALLY THANK YOU SO MUCH!!!
Well done, thanks Mike
Any time 😉
HI MIKEY bro, i HAVE this error GcodeSuite::process_parsed_command(bool) i am a noob in cooding how to over come this ,
can you help me please
its working for me now but the issue i dont know how to print a value i read from a thermistor
@@chitrarasanangayarkkanni2796 how did you fix it?
Hi Mikey, 🙂 First of all, i loved the tutorial, you provided on adding custom Gcode. With that said, i have a couple of questions regarding adding or changing, what i think are Gcode related items. But first a little background on my level of programming skill.
While i am Not quite a n00b, i would honestly critique my Marlin/Arduino/Raspberry pi/ CPP/ skillsets as somewhere between beginner and intermediate) i have done a few Arduino projects successfully, but i really haven't done any serious programming since the way, way. Waaaayy, back days of Ahston-Tate dBase III+ 1.0/1.1/2.0 & Clipper 5.0 days, from Last century. Since then, i have gotten back to studying C++ & Python, which has helped refresh my memory on Conditionals ( if / endif)( do while / end do ) ( if / then / else), etc.,...
Now, Onto my questions; 2 years ago, I picked up an Ender 3 pro which had a stock Creality 1.1.4 board. And for a while things were good, until they weren't. About 7 months ago now, I changed out the guts of the printer with a BTT SKR Mini E3 2.0 board running Marlin 2.0 and the BTT 3.0 Touch panel display. Along with an Actual BL touch sensor. I LOVE how this board makes the printer now run virtually silent as compared to, the stock creality board. However, 1 annoying thing i have found is, when a print is finished, the build plate, slides to the back of the printer, unlike how the old Creality board moved the build plate to the front of the printer. What line(s) of code do i need to change in Marlin, to write to the firmware, that will make the build plate, move forward to the front if the printer, at the completion of job?
i want to use two LCD screen ..another one for dignostic purpose simulteniously ...can you do that?
Yeah there are a couple of ways you could do that. The easiest way would probably be to modify marlin to push debug information to a secondary serial port (assuming your controller has one) then use an Arduino to receive the serial and control the secondary display. Option 2 would be if you controller has enough free pins to handle another LCD you could modify marlin to use the other pins to control the second LCD, this way would be very pin expensive. I suggest the first one, in the end you have an LCD that can accept a serial stream and display it, that becomes a very useful tool for other projects as well.
Hi Mikey! Hope you’re ok. Was just playing around with this in Marlin 1.1 and wanted to create a custom bit of gcode to completely remove a bit of filament from the extruder automatically. Was just wondering if you knew how you can call the gcode_G0_G1() function within a custom gcode to extrude as if a G1 E-100 is called?
You don't need a custom gcode for this, just write a macro.
Hi Mikey!
As far as you’re aware has anyone used this to send a signal to a custom bit of hardware that automatically changes filaments at a defined layer height?
I have not, but it would be a great use of it.
Hi Mikey, first of all, thanks for taking the time to show this stuff!
I have a question regarding a weird custom command I'm trying to make involving motion and external sensor.
Basically, my code should move an axis (X axis, for instance) until it hits a special endstop (not the one used for homing, but a seperate one wired specifically for this). At first I thought I could just copy paste the homing code, but the problem is that it's important that I record the distance moved as it's nearing the endstop. In case you're curious, I'm trying to make a routine for a printer with two X carriages (IDEX) that homes both printheads on the same endstop to determine the nozzle offset.
My second thought was to just do some basic coding: make a loop that steps the axis while polling the endstop until it hits (I'll worry about accuracy later). My question is, is there a way to do these kinds of simple movements in Marlin, or do movements require a lot of preamble code to run? I tried looking at motion.cpp but it didn't help a lot (my coding experience is limited to slightly advanced Arduino projects). Maybe I can brute force it by spamming G1 commands in a loop? That brings me to a side question: in some comments you mentioned you can call Gcode commands from within your custom code, how does that look as written code? I assume you can't just write " G28(); "
I hope my question isn't too unclear or extensive... Again, thank you for this amazing tutorial! You've definitely earned a sub!
Yes you can just call g28(); it is just a function in the source. I am not familiar with the motion commands, but here is how I would investigate. I would look up the gcode commands for motion, find the calls in the gcode function that seems to cause the motion, right click on the function and choose find all references, keep going down the rabbit hole till you reach the point that we are actually telling the stepper motor to do something, then work backward to the point it makes sense to start your custom code. I can look into this when I am at a computer if this doesn't put you on the right path.
@@MikeysLab thanks for the quick reply! Sounds like a good idea, I'll definitely give it a try tomorrow. I'll let you know if I get stuck.
@@MikeysLab Hi Mikey, I managed to get my steppers moving, thanks for the help! I had one more question regarding calling gcode commands like G28() from within the code. Is there a way to pass parameters to the gCode command? For instance to call "G28 X" or "G1 X20 Y20" like you would in a normal piece of gCode? Internally the gcode seems to get its parameters from the parser (like the example in your video), but I can't seem to find out how to pass them on from the code itself.
@@omega_one1318 I will have to look at the source code tomorrow and get back to you 😀
@@MikeysLab Did you figure out?? this is the closest I've got to finding the answer to this question :)
How does dwell() allow the main loop to continue in a non-blocking fashion?
I will post a more complete answer after work, but I believe dwell uses a millis() structure to have an event wait for a specific amount of time, but allowing the main code loop to continue and check on every iteration if the delay has elapsed. I am doing a horrible job explaining it lol. I will provide an example after work 😁
@@MikeysLab Right so once the number of milliseconds has been reached, execution must somehow go back to the point where dwell() was called.
Nice, thanks for this.
Hi Mikey, I was inspired by your video. I don't quite understand how Marlin recognized pin 29 on the motherboard?
I am glad the video helps. During the Marlin configuration you specify a board and processor. This is part of Marlin's Hardware Abstraction. Pin 29 is mapped to a specific pin on the micro controller as defined by the board definition.
hi how do i move motors when the code is called?
The easiest way to do this, depends on if you want to move one of the normal steppers the board already knows about. With that you can simply invoke a G0 command in the source of your function. Move other motors would require either customizing the firmware to add another known stepper in the normal configuration, or in the case of an additional servo, doing direct pin manipulation
Can you do a list of gCode commands like for a 3D probe operation?
Is it a matter of simply calling a bunch of gcode functions, one after the other, in the function you created? Or is there a better way to do this?
That is the easiest way. You could look at how a move command is processed and duplicate that, but that is a little more down the rabbit hole
Mikey, Brilliant! Excellent tutorial for what I need to do for a custom 3D concrete printer priject. You have saved me tons of time. While this is not critical for my project, the LCD has FFF-like menus that I would like to change beyond the custom user menu scheme already included in Mariin 2.0.7. For example, the Temperature menu is not needed; can you give me some input on its removal? I am playing around with "menu-main.cpp" and making progress. Also, I would like replace Temperature with specials just like you show in this video which represent custom gcode except it is called from the LCD.
You mentioned a better than platformio plugin but I didn't catch it from your talk. More input, please.
Yeah boss, Marlin is very modular, so it is just a matter of finding the menu section, then using the "find all references" to see how it all connects. The main IDE I use is Visual Studio Community with the Visual Micro plug in. I am working on a C++ for microcontrollers series where I will be going in depth into the more technical weeds of coding in these constrained environments
@@MikeysLab Thank you for prompt reply and tips. I will check out the VS reference.
OK, success both removing an LCD menu and adding one but more importantly, I followed your coding example and was able to add my own custom G-code which while simple is a good prototype for more of them. If I hadn't made one type, a ")" left out, this would have finished an hour or so sooner. But All Good Now. Many thanks and cheers, to you, Mikey.
Awesome brother. We have all lost hours (or in my case days) over a missing ; lol. That was many moons ago before compilers would give you any reasonable error codes lol
Hello and thank you for this video!
It helped me a lot to add my custom gcodes, I wouldn't have succeeded without it.
I had a question though, you use the dwell function, and if I understand correctly, this function allows Marlin to continue to perform its actions in the background.
The function I created allows to activate pins connected to an arduino board that drives servomotors with an independent program.
The problem is that the arduino board has difficulties to send commands to more than three servo-motors at the same time, so I would like to add a delay to the function that activates each pin so that if I send two commands in a row, marlin will leave a delay after the first one before executing the next one.
Dwell is not suitable, and I have tried "delay" which does not seem to work either.
Do you have any idea what function I should use?
Thanks in advance for your help!
I would try using a millis() delay with a while loop. Be careful with this, every delay you do like this will block the processor and stop the main loop.
@@MikeysLab thanks for your fast answer !
I’ll try this this afternoon.
My gcode will work only at the beginning of my milling (it’s on CNC)
And, my board is a STM32F4. Do you think « millis() » function will work on it ?
@@Phoquounet yes millis() is a built in function, it will return the milliseconds since boot. So some thing like this:
long start = millis();
while(millis() < start + 5000)
{
//do something while waiting, or not :)
}
Results in an approx 5 second pause.
@@MikeysLab great !
I’ll try this and tell you if that work ;)
Thanks !
PS: for pin write, I use “OUT_WRITE(IO, V)” and my gcode take P for the pin and S for enable or disable pin.
hi5 for the video, i need to make the same but with a endstop to control the door switch so when is open the door the printer pause, can you make some help?($$)
That is actually simpler than this mod. I would use an Arduino with the switch connected to an interrupt, then you can use one of the serial ports on the control board and have the Arduino send a M226 to the board. If you are lacking an available serial port you would need to make an extra IO pin an input, add it to the polling loop (duplicate the end stop code) and trigger the M226 command inside of marlin itself. Can I build it for you, no. But I think I have given you enough information to build it yourself.
Hi, thanks for your video really helpfull, i'm on an skr mini e3 1.2, i need to use 2 different free pin for 2 different script on an arduino, i think i'll use the NEOPIXEL PC7 pin which i don't use and the PT-DET PC12 pin, i d'ont know how to specify it in the gcode command:
M6453 P7 S50
Do you think this will work ? Because i'm wondering how marlin make the difference between PC, PB or PA pins?
On the skr there is a difference between PA, PB and PC these are port A port B and port C respectively. There are many other marlin gcodes that take a pin number, I would find one of those and work backwards to determine how the pin is specified. For your case you could just remove the pin definition as a parameter in the gcode and hard code it (since you will be using it for yourself) I did it as a parameter to make it more useful for other people.
Hello good man! Can you give me any advice how to control servo motor with creality v4.2.2. board.
I think that i can reuse BLtouch connector and reporgram it, but i dont know where to start. Any advice would be helpfull! Cheers!!
Yes you can or any other pin capable of PWM. From there you want to determine the #define for the port and pin ID for the probe servo. Search for all references for that designation, at some point this will lead you to the actual commands the set servo position
@@MikeysLab i didi it. It wasnt too hard. Thx once more! I have new problem. Whan i use servo motor (MG 996R) my display stats to flicker and i gave blank screen. I think that there is something with voltage drop... I turn of than turn on my Ender 3 (4.2.2 board) and everything is normal...
Yup, more specifically over current resulting in a voltage drop. I would feed the servos +5 directly from a buck convertor off of the PSU, servos are always hungry little guys
@@MikeysLab problem solved!!! I didnt have buck converter but i used USB chrager, grounded servo and USB cable to board, pluged V+ to USB and conected signal pin to board. Works like a charm, didn't have any problems with display even whan I stalled servo. Thanky you very much good man!!!
@@MrMun33 never a problem, if you're subscribed stay tuned for some great content, been filming alot the last couple of weeks now just need to sit down and edit, including over hauling and upgrading a old 5 print head liquid cooled printer 😃. If you not subscribed, why wait lol
I watched a little, what IDE do you use and config? your h/w and s/w are not the typical one so your post is less helpful.
The IDE is VSCode which is the most common IDE for compiling modern versions of marlin. The Hardware is the board that come with the Ender 3, which is the most popular printer. So I am not sure I understand your comment.