While G-Codes are not something that most 3D printing enthusiasts come to direct contact with, they are essentially the thing that allows a 3D printer to function.
If you aren’t familiar with G-Codes, you can think of them as the language of the 3D printer, with each code referring to an action. As slicers convert the STL files to G-Code format, we usually don’t have to deal directly with G-Codes for the most part.
On the other hand, knowing what some G-Codes do can be very helpful, as there are a few G-Codes that provide utility; and aren’t part of a standard printing process.
As G-Codes can show differences between firmware, we will be talking about some of the vital G-Codes in the Marlin firmware and the functionality they bring.
So, what are the Marlin M500, M501, M502, M503, and M504 G-Codes?
- M500 (Save Settings) – Saves the settings to EEPROM.
- M501 (Restore Settings) – Loads the settings from EEPROM.
- M502 (Factory Default) – Resets all configured settings to factory defaults.
- M503 (Report Settings) – Shows a report of the current settings.
- M504 (Validate EEPROM Contents) – Validates the EEPROM.
Next up, we will be looking into each of these G-Codes separately and in greater detail to understand how they really function and find the appropriate use-cases for them.
What is Marlin M500?
M500 (Save Settings) is the G-Code for saving the settings into the EEPROM from the volatile memory in the Marlin firmware.
When you change some values in the configuration of your printer, the printer only writes these settings to the volatile memory.
Unlike persistent storage, all the data in the volatile memory is lost when the printer loses power, meaning that the settings you have configured will only be in effect until you turn your 3D printer off.
As the EEPROM is a form of persistent storage, writing the current settings to the EEPROM allows you to keep them between power cycles.
What is Marlin M501?
M501 (Restore Settings) is the G-Code for restoring the settings from the EEPROM to the volatile memory in the Marlin firmware.
While the Marlin firmware automatically runs the M501 G-Code whenever you turn your printer on, you can manually use it in cases where the auto-load does not work.
Since your printer uses the data in the volatile memory to configure itself, the data in the EEPROM will not be in effect unless you load it from the EEPROM to the volatile memory first.
The reason behind this is that while volatile memory is fast, the EEPROM is considerably slower. As a result, the EEPROM is only used for hard storage, whereas the volatile memory provides frequent and quick access.
By restoring the settings from the EEPROM to the volatile memory with the M501 G-Code, your printer will have access to the settings you have saved previously.
What is Marlin M502?
M502 (Factory Reset) is the G-Code for resetting all the settings in the volatile memory to their factory defaults.
As this G-Code only resets the settings in the volatile memory, you will also need to use the M500 G-Code if you would like to reset the configuration in the EEPROM to their factory default.
While you won’t frequently use it, the M502 G-code can be pretty handy in scenarios where you misconfigured your printer or after configuring the settings specifically for a single print.
What is Marlin M503?
M503 (Report Settings) is the G-Code for displaying all the current settings in the volatile memory.
Using this G-Code will show you the settings that are currently loaded on the volatile memory. If you would like to see the configuration in the EEPROM, you will need to use the M501 G-Code to load the settings into the volatile memory first.
The M503 G-Code is the quickest way of getting a detailed summary of all the configuration that is currently in effect, which can be very helpful if you are unsure about some of the settings you have recently changed.
While the M503 G-Code produces a detailed output by default, you can also receive a more concise summary by executing the G-Code M503 false, which disables the detailed output flag.
What is Marlin M504?
M504 (Validate EEPROM) is the G-Code for validating the contents of the settings saved in the EEPROM.
While it’s not something you will need to use often, you can use this G-Code to verify the settings you have saved to the EEPROM and ensure that everything is in order in cases where you suspect that your configuration isn’t saved to the EEPROM as intended.
What is Marlin EEPROM?
EEPROM stands for Electrically Erasable Programmable Read-Only Memory.
It is a form of persistent storage that is widely used in integrated systems, capable of storing very small amounts of data through electrically modifying its individual bytes.
As EEPROM is a physical element that is contained within your 3D printer, it’s not directly related to the Marlin firmware. The Marlin firmware can write to the EEPROM and read from it whenever necessary, just as any other 3D printer firmware.
How to Enable EEPROM in Marlin?
To use EEPROM commands (such as M500, M501, and M502) with the Marlin firmware, you may first have to enable EEPROM functionality.
Here are the steps you should take to enable EEPROM in Marlin.
- Open the “Configuration.h” file in a text editor. You can find this file in the root directory of the Marlin firmware.
- Find the line with the text //#define EEPROM_SETTINGS and replace it with this text instead #define EEPROM_SETTINGS.
- Recompile the firmware and flash it to your 3D printer.
How to Disable EEPROM in Marlin?
If you have previously enabled EEPROM in Marlin and would like to disable it, flash the original version of Marlin to your 3D printer.
As the Marlin firmware has EEPROM disabled by default, flashing a fresh copy will automatically cause the EEPROM to be disabled completely.
Knowing the G-Codes that allow you to use the EEPROM can definitely be handy in a multitude of scenarios, which is why we highly recommend enabling EEPROM and using these commands actively to make your 3D printing experience smoother.
We will be covering more of the G-Codes that you can use to make your 3D printing life easier, so stay tuned!
Mike started his 3D printing journey with the Anet A8 when it first came out back in 2017, and has been obsessed with 3D printers ever since. Nowadays, he primarily uses his Ender 3 to print functional parts that make his life more convenient whenever possible.