Marlin-Ai3M

Anycubic i3 Mega / Mega-S Marlin 1.1.9 Custom Firmware Documentation


About

  • Donate Open Issues Closed Issues License Latest Release Last commit

This is a custom version of the Marlin Firmware for the i3 Mega/Mega-S, gratefully based on derhopp's repo with his remarkable efforts to get the Anycubic TFT screen to work with the latest versions of Marlin.
Deutsche Übersetzung der Anleitung ist hier zu finden. For the German translation of the instructions, click here.
Looking for a BLtouch firmware? Head this way! Mounting and configuration instructions are included.

Read the FAQ linked below if you have any issues/questions. Search the internet if it isn't answered there. Still nothing? Feel free to comment then. (No questions regarding BLtouch please.)

Frequently Asked Questions

Features #back to top

While the i3 Mega is a great printer for its price and produces fantastic results in stock, there are some improvements and additional features that this firmware provides:

  • Mesh Bed Leveling
    • Compensates for uneven beds that are hard to level with screws
    • Probing the bed at 25 points, the printer creates a grid of the surface and compensates automatically while printing
  • PID controlled heatbed
    • Stable temperatures
    • Uses less power
  • S-Curve Acceleration and some tweaks on jerk and acceleration
    • Gradually slowing down certain moves and thus reducing vibrations and improving print quality
  • Filament change feature enabled
    • Switch colors/material mid print (instructions below) and control it via display
  • The filament runout, pause and stop functionality have been overhauled and improved:
    • The hotend now parks and retracts (on pause or stop) and purges automatically (on resume).
  • Linear Advance unlocked (not enabled by default. Google is your friend - you will need to do some calibration. Also: might not work well on TMC2208)
  • Thermal runaway protection
    • Reducing fire risk by detecting a faulty or misaligned thermistor
  • 12V at 100% duty cycle on the parts cooling fan
    • The stock firmware only provides 70% of the power, many aftermarket fans require the full amount to run flawlessly
  • Support Watterott or FYSETC TMC2208 without having to reverse the connectors
    • Other vendors' TMC2208 might work well too but I strongly recommend those
  • No need to slice and upload custom bed leveling tests, test it with a single GCode command
  • Easily start an auto PID tune or mesh bed leveling via the special menu
    • Insert SD card, select special menu and press the round arrow
  • Added M888 cooldown routine for the Anycubic Ultrabase (EXPERIMENTAL)
    • This is meant to be placed at the end Gcode of your slicer. It hovers over the print bed and does circular movements while running the fan. Works best with custom fan ducts. Thanks to kulfuerst for the idea and suggestion of this feature!
    • Optional parameters:
    • T<temperature>: Target bed temperature (min 15°C), 30°C if not specified (do not set this under room temperature)
    • S<fan speed>: Fan speed between 0 and 255, full speed if not specified
    • e.g. M888 S191 T25: run the fan at 75% until the bed has cooled down to 25°C

Installation #back to top

Known issues:

  • Power outage support is not included
  • Estimated print times from your slicer might be slightly off.
  • Special characters on any file or folders name on the SD card will cause the file menu to freeze. Simply replace or remove every special character (Chinese, Arabic, Russian, accents, German & Scandinavian umlauts, ...) from the name. Symbols like dashes or underscores are no problem. Important note: On the SD card that comes with the printer there is a folder with Chinese characters in it by default. Please rename or remove it.

Compatibility info:

  • Since late 2020, Anycubic started shipping their printers with a new display. It has a blue background and yellow text. With this display, the special SD menu will not work. Features like Manual Mesh Leveling and PID Tuning need to be configured via USB (e.g. OctoPrint or Cura as host). The printing features itself remain functional.

Installation

I provided three different precompiled hex files: One for no modifications on the stepper motor drivers - good for people who didn't touch anything yet, one for boards with TMC2208 installed and where the connectors have been flipped and one with TMC2208 and the connectors in original orientation.

Choose your precompiled hex:

  • Choose the correct hex file:
  • For TMC2208 with connectors in original orientation, use Marlin-AI3M-vx.x.x-TMC2208.hex
  • If you use TMC2208 and already reversed your connectors, use Marlin-AI3M-vx.x.x-TMC2208_reversed.hex
  • If you use a newer version of the TMC2208 that doesn't require the connector to be reversed (TMC2208 "v2.0" written on the PCB, chip on the top side), please also use Marlin-AI3M-vx.x.x-TMC2208_reversed.hex.
  • If you use the original stepper motor drivers, use Marlin-AI3M-vx.x.x-stock_drivers.hex.

Or compile it yourself:

  • Download and install Arduino IDE
  • Download the Source code.zip from the latest release
  • Browse into the Marlin folder and run Marlin.ino
  • In the IDE, under Tools -> Board select Genuino Mega 2560 and ATmega2560
  • Open Marlin.ino in the Marlin directory of this repo
  • Customize if needed (e.g. motor directions and type at line 559 to 566 and line 857 to 865 in Configuration.h)
  • Under Sketch, select Export compiled binary
  • Look for the .hex file in the Marlin directory (only use the Marlin.ino.hex, not the Marlin.ino.with_bootloader.hex!)

After obtaining the hex file:

  • Install the printer's USB drivers if not yet done.
  • Flash the hex with Cura, OctoPrint or similar
    • e.g. in Cura: Settings -> Printer -> Manage Printers -> Update Firmware.
  • Use a tool with a terminal (OctoPrint, Pronterface, Repetier Host, ...) to send commands to your printer.
    • Side note: Cura can also send commands via USB in the Monitor tab, but since you can't read responses from the printer, I'd recommend a tool with a proper terminal
  • Important: Connect to the printer and send the following commands:
  • M502 - load hard coded default values
  • M500 - save them to EEPROM
  • (Only needed on major firmware flash - e.g. coming from Anycubics default FW. Not needed after flashing an update of this firmware unless explicitly mentioned in the changelog)
  • If you are using this on a Mega-S, those four additional commands are necessary:
  • M92 E384 - set correct steps for the new extruder
  • M203 E30 - limit extruder feedrate
  • M204 R1500.00 - lower retract acceleration
  • M500 - save the values
  • I highly recommend calibrating the extruder as explained below.

Manual Mesh Bed Leveling #back to top

If you have issues with an uneven bed, this is a great feature.

  • Insert an SD card, enter the print menu.
  • Enter the special menu by selecting it and pressing the round arrow:

Special Menu

  • In this menu, the round arrow is used to execute the command you selected.
  • Preheat the bed to 60°C with this entry: (if you usually print with a hotter bed, use the Anycubic menu)

Preheat bed

  • Level your preheated bed as well as you can with the four screws.
  • Start the mesh leveling:

Start MMBL

  • Your nozzle will now move to the first calibration position.
  • Don't adjust the bed itself with screws, only use software from here on!
  • Use a paper - I recommend using thermopaper like a receipt or baking paper
  • Use the onscreen controls to lower or raise your nozzle until you feel a light resistance: (If you want to send the same command multiple times, select the item again, even though it is still marked red.)

Z axis controls

  • Once finished , move to the next point:

Next mesh point

  • Repeat the last two steps until all 25 points are done.
  • Your printer will beep, wait 20 seconds and then save (the printer will beep once more to confirm):

Save to EEPROM

  • Reboot your printer.

After leveling:

  • To ensure your mesh gets used on every print from now on, go into your slicer settings and look for the start GCode
  • Look for the Z-homing (either just G28 or G28 Z0) command and insert these two right underneath it:
    M501
    M420 S1
                            
  • Your printer should now correctly print first layers even on a warped bed.
  • When working on the printer, installing a new hotend or nozzle or the bed warping over time, a new Mesh Leveling procedure is recommended.

Manual commands for use with OctoPrint etc.:

  • G29 S1 - Start MMBL
  • G29 S2 - Next Mesh point
  • Raising Z: G91, G1 Z0.02, G90 (one after another, not in one line)
  • Lowering Z: G91, G1 Z-0.02, G90
  • After seeing ok in the console, send M500 to save.

Testing your bed leveling

Leveling test model

I can recommend this customizable leveling test by kenwebart.

Testing via GCode

Send the following commands

G28
G26 C H200 P5 R25 Q4.2 Z4
                        
  • To adjust your filament's needed temperature, change the number of the H parameter
  • Default bed temperature is 60°C, if you need another temperature, add e.g. B80
  • Q parameter sets retraction length in mm, Z sets unretraction.
  • If your leveling is good, you will have a complete pattern of your mesh on your bed that you can peel off in one piece
  • Optional: Hang it up on a wall to display it as a trophy of how great your leveling skills are.

M600 Filament Change #back to top

M600 Demo

BETA: This now also works without USB printing, via SD & display.

Configuration (only needed once):

  • Send M603 L0 U0 to use manual loading & unloading.
  • Send M603 L538 U555 to use automatic loading & unloading
    • The L and U paramters define the load and unload length in mm. The values above work well on a stock setup, if you modded your extruder, bowden tube or hotend, you might need to adjust those.
  • Save with M500

Filament change process (manual loading):

  • For printing via SD:
    • Place M600 in your GCode at the desired layer
  • For printing via USB:
    • Place M600 in your GCode at the desired layer or send it via terminal
    • Alternatively: Use FilamentChange Pause in the Special Menu
  • The nozzle will park and your printer will beep
    • For safety reasons, the printer will turn off the hotend after 10 minutes. If you see the temperature being under the target:
      • SD printing: Press CONTINUE (only once!) on the screen and wait for the hotend to heat up again.
      • USB printing: Send M108 and wait for the hotend to heat up again.
  • Remove the filament from the bowden tube
  • Insert the new filament right up to the nozzle, just until a bit of plastic oozes out
  • Remove the excess filament from the nozzle with tweezers
  • For printing via SD:
    • Press CONTINUE on the screen
  • For printing via USB:
    • Send M108 via your USB host or use FilamentChange Resume in the Special Menu
    • Note for OctoPrint users: After sending M108, enable the advanced options at the bottom of the terminal and press Fake Acknowledgement

Filament change process (automatic loading):

  • For printing via SD:
    • Place M600 in your GCode at the desired layer
  • For printing via USB:
    • Place M600 in your GCode at the desired layer or send it via terminal
    • Alternatively: Use FilamentChange Pause in the Special Menu
  • The nozzle will park
  • The printer will remove the filament right up to the extruder and beep when finished
    • For safety reasons, the printer will turn off the hotend after 10 minutes. If you see the temperature being under the target:
      • SD printing: Press CONTINUE (only once!) on the screen and wait for the hotend to heat up again.
      • USB printing: Send M108 and wait for the hotend to heat up again.
  • Insert the new filament just up to the end of the bowden fitting, as shown here:

Load Filament

  • For printing via SD:
    • Press CONTINUE on the screen
  • For printing via USB:
    • Send M108 via your USB host or use FilamentChange Resume in the Special Menu
    • Note for OctoPrint users: After sending M108, enable the advanced options at the bottom of the terminal and press Fake Acknowledgement
  • The printer will now pull in the new filament, watch out since it might ooze quite a bit from the nozzle
  • Remove the excess filament from the nozzle with tweezers

Calibration #back to top

Extruder Calibration

  • Get your old E-Steps with M503. Look for the line starting with M92, the value after the E are your current steps.
  • Preheat the hotend with M104 S220
  • Send M83 to prepare the extruder
  • Use a caliper or measuring tape and mark 120 mm (measured downwards from the extruder intake) with a pencil on the filament
  • Send G1 E100 F100
  • Your extruder will feed 100 mm of filament now (takes 60 seconds)
  • Measure where your pencil marking is now. If it's exactly 20 mm to the extruder, it's perfectly calibrated
  • If it's less or more than 20 mm, subtract that value from 120 mm, e.g.:
  • If you measure 25 mm, your result would be 95 mm. If you measure 15 mm, your result would be 105 mm
  • Calculate your new value: (100 mm / actually extruded filament) *your current E-steps (default: i3 Mega 92.6, Mega-S 384)
  • For example, if your markings are at 15 mm, you'd calculate: (100/105) * 92.6 = 88.19
  • Put in the new value like this: M92 X80.00 Y80.00 Z400.00 Exxx.xx, replacing x with your value
  • Save with M500
  • Finish with M82
  • You can repeat the process if you want to get even more precise, you'd have to replace your current E-steps with your newly calibrated value in the next calculation.

Temperature / PID Tuning

Only calibrate your PID values if you experience fluctuating temperatures!

  • Turn on parts cooling fan If you have a radial blower fan like the original one, I generally recommend running it at 70% because of the 12V mod (M106 S191). Remember to also limit it in your slicer.
  • Send M303 E0 S210 C15 U1 to start extruder PID auto tuning
  • Wait for it to finish (Get a coffee! This can take a while.)
  • Send M303 E-1 S60 C6 U1 to start heatbed PID auto tuning
  • Wait for it to finish
  • Save with M500, turn off fan with M106 S0

Note: These commands are tweaked for PLA printing at up to 210/60 °C. If you run into issues at higher temperatures (e.g. PETG & ABS), simply change the S parameter to your desired temperature

Reminder: PID tuning sometimes fails. If you get fluctuating temperatures or the heater even fails to reach your desired temperature after tuning, you can always go back to the stock settings by sending M301 P15.94 I1.17 D54.19 and save with M500. You can also try my values: M301 P20.28 I1.45 D71.01 + M500.

Firmware Details #back to top

Updating / Back up & restore your settings

Some updates require the storage to be cleared (M502), if mentioned in the update log. In those cases, before updating, send M503 and make a backup of all the lines starting with:

M92
G29
M301
M304

After flashing the new version, issue a M502 and M500. After that, enter every line you saved before and finish by saving with M500.

Something went wrong?

No worries. You can easily go back to the default firmware and restore the default settings. Flash the hex file from the manufacturer's website (in case it's offline, I have uploaded the stock firmwares here as well). After flashing, send M502 and M500. Now your machine is exactly as it came out of the box.

Reporting bugs or issues

I am very grateful for any feedback and constructive criticism. While I ran this firmware for over 800 print hours successfully, I am by no means a commercial user and this machine is just for private purposes. It's stable for me, but since every machine is different, feel free to chime in with your observations.

But please keep in mind that a simple two-liner with nothing but "x doesn't work" won't get us anywhere (let alone on Thingiverse, with a single comment feed at over 500 posts now - it's a mess to navigate).

Acceleration & Jerk

This firmware now (v1.4.6 and up) uses acceleration and jerk values that are either very close or identical to the manufacturer values.

I recommend slightly reducing some accel/jerk values. This reduces print speed by a very tiny fraction but reduces ghosting and improves overall quality a bit. Reduced acceleration and jerk can (depending on your print speed) make very sharp edges getting slightly rounded off.

Since I am just sharing values that work well for me, I'd recommend you to look into acceleration and jerk settings and tweak them to your likings.

Custom values:

M201 X2000 Y1500 Z60 E10000 ; max acceleration
M204 P1200.00 R3000.00 T1500.00 ; default acceleration
M205 S0.00 T0.00 Q20000 X9.00 Y9.00 Z0.40 E5.00 ; min segment time and jerk

Manufacturer/default values:

M201 X3000 Y2000 Z60 E10000 ; max acceleration
M204 P3000.00 R3000.00 T3000.00 ; default acceleration
M205 S0.00 T0.00 Q20000 X10.00 Y10.00 Z0.40 E5.00 ; min segment time and jerk

Try them out yourself and see what works best for you. Simply send the three lines and save them with M500.

Updates & Changelog #back to top

Changelog

16.11.2018

  • First alpha release (GitHub)

30.11.2018

  • First stable release (Thingiverse)

02.12.2018

  • Tweaked default extruder values
  • Added my Simplify3D profile

13.12.2018

  • Adjusted PID and extruder values closer to manufacturer defaults
  • Enabled the G26 Mesh Validation pattern command

17.12.2018

  • Adjusted auto PID tune parameters
  • Replaced manufacturer PID values
  • Raised retraction on G26 Mesh Test
  • Merged latest bugfix from derhopp

24.12.2018

  • Raised PID tuning timeout
  • Adjusted thermal watchdog periods
  • Merry Christmas!

27.12.2018

  • Tweaked acceleration values
  • Fixed TMC2208 layer shifts that were caused by acceleration

  • M502 and M500 after updating recommended (save your mesh and e-steps to put it in after updating!)

31.12.2018

  • Raised maximum bed temperature to 120°C
  • Raised maximum hotend temperature to 260°C (Good for all-metal hotends, beware that the stock hotend has PTFE inside which degrades at 250°C)
  • Lowered minimum extrusion temperature to 170°C

04.01.2019 - v1.0.1

  • Fixed homing issue
  • Enabled printcounter (show printer statistics with M78)

10.01.2019 - v1.0.3

  • Raise nozzle after canceling print via display
  • Corrected bed size

22.01.2019 - v1.0.4

  • Fixed movement beyond endstops on some occasions (e.g. Cura's end Gcode)

04.02.2019 - v1.2.0

  • Merging latest changes from Marlin's bugfix-1.1.x
  • Further tweak print canceling behaviour
  • (Skipped internal version 1.1 to not be confused with Marlin 1.1.x)

05.02.2019 - v1.3.0

  • Highly recommended update. Please use M502 and M500 after flashing.
  • Added filament change support and added instructions

06.02.2019 - v1.3.1

  • Bugfix (buffer overflow on M109/M190)

08.02.2019 - v1.3.2

  • Please use M502 and M500 after flashing.

  • Improved USB printing by preventing buffer from running dry and waiting for serial input

  • Slightly reduced feedrate, acceleration and jerk
  • To keep your calibrations and settings, please refer to this section of the readme before flashing this update.

11.02.2019 - v1.3.3

  • Maximum temperatures raised to 275°C/125°C.

12.02.2019 - v1.3.4

  • Fix Simplify3D USB printing buffer issue

18.02.2019 - v1.4.0

  • Completely reworked pause, stop and filament runout functionality:

    • Park nozzle on filament runout & beep to alert user
    • Lift nozzle on pause
    • Retract a small amount depending on action to prevent oozing
    • Prime nozzle after resuming from filament runout
  • M600 filament change updates:

    • Implemented filament change into display
    • Added M108 and M600 routines to special menu
    • Allow special menu to be used while printing
    • Edited continue button to resume from M600 pause
    • Implemented serial communication with display into M600 GCode

23.02.2019 - v1.4.1

  • Fixed M600 issue where the screen only showed continue on the first time it was called, not on any further calls
  • Added custom version identifier to be shown on boot and via M115

24.02.2019 - v1.4.2

  • Fixed M108 display routine to ensure print progress gets handled properly
  • Added SD printing check in marlin_main.cpp M600 routine to skip TFTstate if not necessary (e.g. USB printing)

08.03.2019 - v1.4.3

  • Fixed Z movement on abort
    • On some occasions, the axis would move downwards into the print
  • Implemented nozzle reheating on timeout via display
    • Raise nozzle timeout to 10 minutes
    • Use continue button as reheat trigger
    • Manage nozzle_timed_out variable via display
    • Add PausedByNozzleTimeout flag to enter correct routine on display
  • Use realtime delay on filament sensor (3000ms) to prevent false positives
    • Instead of incrementing a variable on every iteration on the filament sensor trigger loop, we now use a real time macro that ensure better repeatability and is easier to customize.
  • Add audio feedback to M500 and M502 in display menu

13.03.2019 - v1.4.4

  • Reworked pause & stop functionality:
    • Park head with retract on pause and abort
    • Use native functions instead of Gcode
    • Loud beeps to alert user on filament runout
    • Fix potential looping issues by using flags
  • Fix "Stop failed" message on some occasions
  • Added M888 cooldown routine for the Anycubic Ultrabase (EXPERIMENTAL): This is meant to be placed at the end Gcode of your slicer. It hovers over the print bed and does circular movements while running the fan. Works best with custom fan ducts.
    • Optional parameters:
    • T<temperature>: Target bed temperature (min 15°C), 30°C if not specified (do not set this under room temperature)
    • S<fan speed>: Fan speed between 0 and 255, full speed if not specified
    • e.g. M888 S191 T25: run the fan at 75% until the bed has cooled down to 25°C

25.03.2019 - v1.4.5

  • Implemented optional startup chime
    • Enable STARTUP_CHIME in Configuration.h to play a short chime on Trigorilla startup/serial connection, disabled by default
  • Implemented optional endstop beeps
    • Enable ENDSTOP_BEEP in Configuration.h to enable a 2KHz beep when endstops are hit, disabled by default.
  • G26 Gcode:
    • Changed Q parameter to only specify retraction length
    • Added Z parameter for unretraction length
    • Preserved fixed multiplier of 1.2 if Z isn't specified
    • Added check to avoid implausible retract/unretract ratios
    • Changed default config values

04.04.2019 - v1.4.6

  • Fix stuttering / improve quality on models with high numbers of segments:
    • Save memory and CPU cycles by optimizing TFT code for state handling (pause, runout, ...)
    • Remove obsolete filament runout code
    • Increase jerk/accel
    • Increase ASCII buffer size
    • Decrease TX buffer size
    • Revert minimum segment time to factory default
  • PID tuning:
    • Increase cycles on autotune via display
    • Add beep on completion

M502 and M500 (or Load FW Defaults and Save EEPROM via display) is mandatory after this update.


All prior releases can be found here.

License #back to top

Marlin is published under the GPL license because we believe in open development. The GPL comes with both rights and obligations. Whether you use Marlin firmware as the driver for your open or closed-source product, you must keep Marlin open, and you must provide your compatible Marlin source code to end users upon request.

Disclaimer #back to top

/*
* Flashing a custom firmware happens at your own risk.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS
* AND CONTRIBUTORS “AS IS” AND ANY EXPRESS OR IMPLIED
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
* PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
* OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/