Skip to main content

Compiling Marlin 2.x for the Creality Ender 3 using PlatformIO

 I had previously modded my Ender 3 to use the FreeABL for auto bed-leveling.


This requires compiling and uploading a custom version of Marlin firmware with AUTO_BED_LEVELING_BILINEAR enabled. Since this takes quite a quite of extra storage, it requires SLIM_LCD_MENUS to be enabled. This removes the function to configure E-steps from the control panel. 

As mentioned in my previous post, setting the right E-steps value is one of the most important operation to perform when changing filament or print nozzle. As a result of enabling SLIM_LCD_MENUS, I can only configure E-steps by hooking up the Ender 3 to my laptop and issuing raw G-codes. This was getting old pretty fast.

So the other day, I started poking around to see if there is a way to fit both AUTO_BED_LEVELING_BILINEAR and SLIM_LCD_MENUS in the limited storage on the plain-vanilla Ender 3. After much research and tinkering, I am glad to report this is indeed possible. Here are 2 links I found most useful in helping me achieve this objective:

I use PlatformIO to compile the Marlin firmware (2.0.6.1) using the melzi_optimized profile:


which essentially uses the build parameters mentioned here:

build_unflags = -g -ggdb
build_flags   = ${common.build_flags} -fno-tree-scev-cprop -fno-split-wide-types -Wl, --relax -mcall-prologues

The following features were modified from the default Ender 3 Configuration.h file:

//#define STRING_CONFIG_H_AUTHOR
//#define SHOW_BOOTSCREEN
//#define SHOW_CUSTOM_BOOTSCREEN
//#define CUSTOM_STATUS_SCREEN_IMAGE
//#define SPEAKER
#define S_CURVE_ACCELERATION
#define MANUAL_PROBE_START_Z 0.2
#define FIX_MOUNTED_PROBE
#define NOZZLE_TO_PROBE_OFFSET { -45, -5, -5 }
#define AUTO_BED_LEVELING_BILINEAR
#define RESTORE_LEVELING_AFTER_G28
#define GRID_MAX_POINTS_X 4
#define EXTRAPOLATE_BEYOND_GRID
#define Z_SAFE_HOMING
#define DISABLE_M503

and Configuration_adv.h file:

//#define LCD_INFO_MENU
//#define ARC_SUPPORT

With these changes, I am finally able to fit both the normal LCD menu *and* bilinear bed leveling function into the compiled firmware (with S-curve acceleration thrown in).

RAM:   [===       ]  30.6% (used 5007 bytes from 16384 bytes)
Flash: [==========]  98.1% (used 127580 bytes from 130048 bytes)

The new firmware didn't like the old config values, so the settings had to be initialized. There were basically 2 operations that needs to be performed from a fresh setup like this:

  1. Probe Z-offset
  2. Auto bed leveling

Probe Z-offset

Z-offset is the distance between the print bed and the nozzle when the ABL probe is engaged. Another way to look at it is that when the ABL probe is disengaged, the Z-offset is the distance that the nozzle needs to travel down so that it just touches the print bed. Therefore if the Z-offset is set too high, the nozzle will dig into the print bed and leave scratch marks on it as it moves, as I had the privilege of finding out! So set the Z-offset to as low as possible to get the first layer to stick, and not any higher.

Finding the Z-offset requires some work on the user's part. First, select Menu > Motion > Auto Home. This will move to print head to the center of the print bed and lowers the print head until the ABL probe engages.

Now disengage the ABL probe and move the nozzle to touch the print bed using Menu > Motion > Move Axis > Z Axis. Move using the 1mm interval initially until the nozzle is almost touching the print bed, then insert a piece of paper between the nozzle and the print bed. Switch to using 0.1mm interval and continue moving the nozzle downwards until you can just feel drag when you move the paper. 

Remember the current Z-axis value (eg. 0.2mm). Now select Menu > Configuration > Probe Z-offset, which will show you the current Z-offset value (default -5mm i.e. last value of NOZZLE_TO_PROBE_OFFSET). To get the new Z offset, simply add the 2 values toegther (eg. -5mm + 0.2mm = -4.8mm). Adjust and set the Z-offset value, and remember to store it using Menu > Configuration > Store settings.

Select Menu > Motion > Auto Home again with the ABL probe engaged, then disengage the probe and test again by moving the Z-axis. Now when the Z-axis is at 0.0mm, it should just touch the print bed and introduce the same drag on the piece of paper.

Auto Bed Leveling

The auto bed leveling option is found under Menu > Motion > Bed leveling. Since I have defined GRID_MAX_POINT_X to be 4, the firmware will automatically perform bed leveling by probing 16 points (4x4) on the print bed. This part is pretty straightforward.


Comments

Popular posts from this blog

Update: Line adapter for Ozito Blade Trimmer

Update (Dec 2021): If you access to a 3D printer, I would now recommend this solution , which makes it super easy to replace the trimmer line. I have been using it for a few months now with zero issue.

Attiny85 timer programming using Timer1

This Arduino sketch uses Timer1 to drive the LED blinker: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 /* * Program ATTiny85 to blink LED connected to PB1 at 1s interval. * Assumes ATTiny85 is running at 1MHz internal clock speed. */ #include <avr/io.h> #include <avr/wdt.h> #include <avr/sleep.h> #include <avr/interrupt.h> bool timer1 = false , led = true ; // Interrupt service routine for timer1 ISR(TIMER1_COMPA_vect) { timer1 = true ; } void setup() { // Setup output pins pinMode( 1 , OUTPUT); digitalWrite( 1 , led); set_sleep_mode(SLEEP_MODE_IDLE); // Setup timer1 to interrupt every second TCCR1 = 0 ; // Stop timer TCNT1 = 0 ; // Zero timer GTCCR = _BV(PSR1); // Reset prescaler OCR1A = 243 ; // T = prescaler / 1MHz = 0.004096s; OCR1A = (1s/T) - 1 = 243 OCR1C = 243 ; // Set to same value to reset timer1 to

Line adapter for Ozito Blade Trimmer

This is an adapter for Ozito 18V battery trimmer (and possibly some Bosch trimmers as well) that uses a plastic blade for cutting. It lets you insert a 2.4mm trimmer line (about 8cm long) and use that for cutting. Simply cut a length of trimmer line and briefly heat up one end with a lighter so that a little bulb is formed. Then insert the trimmer line into the adapter and slot that into the trimmer as per normal. Make sure the trimmer line is not so long that it touches the safety guard. If that is the case, simply trim off any excess with a cutter or scissors. This part is best printed using PETG, which is a tougher and more flexible material. PLA is more rigid and breaks more easily. However, even with PETG, it will still break when it hits something really hard. Since this takes only 0.5m of material and 15 minutes to print, I will usually print a batch of nine at a time at very little cost. The blades that they sell do not break when it hits a hard object, but