Welcome! Log In Create A New Profile

Advanced

Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?

Posted by greenonline 
A colleague posted this question on Stack Exchange 3D Printing (of which I am one of the moderators), and I wondered if there was a solution, or software hack, for this?

Quote

When running Marlin Firmware, is it possible to run G-code scripts/series of commands automatically when you insert the SD card?

I'm running Marlin on a 3D printer board using an ATmega 2560 based board with a reprap discount LCD controller with an SD card slot. I would like to do this without the need to add another computer/board, so native from the board running the Marlin Firmware.

Note that I am not asking about the startup codes upon power on, with the SD already inserted, but rather printing is triggered, on a printer already turned on, just by inserting the SD card. The files that can be run upon start up were mentioned in this answer to a different question:

Quote

With Marlin 1.1.0, you can automatically run a G-Code file when powering on the printer with a SD card already present.

Add a file named auto0.g at the root of your card, containing the following G-Code:

G28 ;Auto-homing
G29 ;Bed leveling


Normally the bed leveling map should be reused for all subsequent prints, until the printer is turned off.

It is possible to provide up to 10 files, from auto0.g to auto9.g.

Just to re-iterate, the answer above is for power on of the printer. However, I am looking for a solution for a printer already switched on and it is the insertion of the SD card which triggers the printing.

Thanks in advance
Quote
greenonline
Just to re-iterate, the answer above is for power on of the printer. However, I am looking for a solution for a printer already switched on and it is the insertion of the SD card which triggers the printing.

It does not seem like an auto print, when inserting a SD-card, is to be found in the current program code of Marlin.

You might consider making a feature request here: [github.com]


I do not think that it would require much work to implement a "card.autoprintfile()" function in Marlin.
It seems to me that a call to such a function could happen at line 5172 right after:
"
else
LCD_MESSAGEPGM(MSG_SD_INSERTED);
"
in the file ultralcd.ccp
Thank you for the reply.

Feature Request posted: [FR] Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware? #11815

Edited 1 time(s). Last edit at 09/12/2018 11:00PM by greenonline.
Basically the code for such a function already exists, e.g. it loads the "auto%i.g" files, so it would probably be fairly simple to reuse and write a function where both those "events" can benefit from the same function albeit run with different parameters: e.g. next to "auto%i.g" it should be possible to allow e.g. "autoSD%i.g" in the root of the SD card.

Edited 1 time(s). Last edit at 09/13/2018 04:03AM by 0scar.
Re: Can G-code scripts be run automatically on inserting an SD card when using Marlin Firmware?
September 13, 2018 03:12AM
It will need some 'protect the user from their own stupidity code' ie what happens when a SD card with the appropriate auto start file is inserted mid print?

Current code doesnt have this, as it just been powered on. ie a known state of not already printing.

Edited 1 time(s). Last edit at 09/13/2018 03:14AM by Dust.
Indeed, good point! Thanks for sharing.

That should be caught first prior to executing the code function, or evaluated in the function. I'll look into it some more.
Sorry, only registered users may post in this forum.

Click here to login