3D printing

How to autotune Marlin Hotend/Extruder PID parameters

In order to autotune the extruder E0 hotend in Marlin, use

M303E0C3S210

where:

  • M303: Autotune PID
  • E0 tune extruder E0 (this is the only extruder on single-extruder printers)
  • C5: Perform 5 cycles (one cycle: heat up to the specified temperature, then cool down to room temperature)
  • S210: Tune at a temperature of 210°C

I always recommend to tune at whatever temperature you use most (e.g. if you want to print mostly PLA at 185°C, use S185 instead of S210 in the command). Tuning at the correct temperature will increase the accuracy of the system.

Regarding the number of cycles, C3 = 3 cycles is mostly for quick tuning. Since heating up and cooling down takes a long time, but doing many cycles increases the accuracy of the tuning. Typical values are:

  • C1: Tuning mostly just for testing, for example if you have modified your extruder hardware
  • C3: Really quick tuning
  • C5: “Standard” tuning
  • C8: Thorough tuning
Posted by Uli Köhler in 3D printing, Electronics

Where to enable extruder-temperature controlled fans in Marlin?

In order to enable a fan in Marlin that is controlled automatically based on the extruder temperature (read: If the extruder is hot, turn on the fan), open Configuration_adv.h and look for the Extruder cooling fans section and set for example E0_AUTO_FAN_PIN to whatever pin you want to be automatically controlled.

/**
 * Extruder cooling fans
 *
 * Extruder auto fans automatically turn on when their extruders'
 * temperatures go above EXTRUDER_AUTO_FAN_TEMPERATURE.
 *
 * Your board's pins file specifies the recommended pins. Override those here
 * or set to -1 to disable completely.
 *
 * Multiple extruders can be assigned to the same pin in which case
 * the fan will turn on when any selected extruder is above the threshold.
 */
#define E0_AUTO_FAN_PIN PA_8
#define E1_AUTO_FAN_PIN -1
#define E2_AUTO_FAN_PIN -1
#define E3_AUTO_FAN_PIN -1
#define E4_AUTO_FAN_PIN -1
#define E5_AUTO_FAN_PIN -1
#define E6_AUTO_FAN_PIN -1
#define E7_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1
#define COOLER_AUTO_FAN_PIN -1
#define COOLER_FAN_PIN -1

 

Posted by Uli Köhler in 3D printing, Electronics

How to fix Pronterface/Printrun UnicodeDecodeError: ‘utf-8’ codec can’t decode byte … in position …: invalid continuation byte

Problem:

When starting Pronterface / Printrun on Linux using pronterfaceprintrunpython3 pronterface.py or similar, you see an error message like

Traceback (most recent call last):
  File "pronterface.py", line 62, in <module>
    app = PronterApp(False)
  File "/home/uli/dev/tools/Printrun/printrun/pronterface.py", line 2464, in __init__
    self.mainwindow = PronterWindow(self)
  File "/home/uli/dev/tools/Printrun/printrun/pronterface.py", line 170, in __init__
    self.parse_cmdline(sys.argv[1:])
  File "/home/uli/dev/tools/Printrun/printrun/pronsole.py", line 786, in parse_cmdline
    self.process_cmdline_arguments(args)
  File "/home/uli/dev/tools/Printrun/printrun/pronterface.py", line 1031, in process_cmdline_arguments
    pronsole.pronsole.process_cmdline_arguments(self, args)
  File "/home/uli/dev/tools/Printrun/printrun/pronsole.py", line 769, in process_cmdline_arguments
    self.load_default_rc()
  File "/home/uli/dev/tools/Printrun/printrun/pronsole.py", line 664, in load_default_rc
    self.load_rc(config)
  File "/home/uli/dev/tools/Printrun/printrun/pronsole.py", line 632, in load_rc
    for rc_cmd in rc:
  File "/usr/lib/python3.8/codecs.py", line 714, in __next__
    return next(self.reader)
  File "/usr/lib/python3.8/codecs.py", line 645, in __next__
    line = self.readline()
  File "/usr/lib/python3.8/codecs.py", line 558, in readline
    data = self.read(readsize, firstline=True)
  File "/usr/lib/python3.8/codecs.py", line 504, in read
    newchars, decodedbytes = self.decode(data, self.errors)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xd3 in position 4: invalid continuation byte

Solution

When you see this error message, typically your pronsolerc is corrupted. In order to remove it,

rm -rf ~/.config/Printrun
Posted by Uli Köhler in 3D printing, Python

How to disable Marlin cold extrusion prevention via G-Code

If you want to test your extruder, you can disable cold extrusion prevention using M302:

M302 P1

Re-enable with

M302 P0

Set the temperature (and enable) using

M302 P0 S170

In order to report the current status, run

M302

Example output if disabled:

echo:Cold extrudes are disabled (min temp 170C)

Example output if enabled:

echo:Cold extrudes are enabled (min temp 170C)

Whatever you configure will not persist after reboot. In case you want to save the settings to EEPROM in order to persist after reboot, run

M500
Posted by Uli Köhler in 3D printing, Electronics

How to unpause Marlin after M0/M1 echo:busy: paused for user

In Marlin, you can pause the firmware using M0 or M1 which will cause the firmware to loop-print

echo:busy: paused for user
echo:busy: paused for user
echo:busy: paused for user
echo:busy: paused for user
echo:busy: paused for user
echo:busy: paused for user

In order to continue or unpause, use

M108

 

Posted by Uli Köhler in 3D printing

How to reboot Marlin using G-Code

On most Marlin boards, you can use M997 to reboot/restart the microcontroller:

M997

While this is technically the command to update the firmware, on most boards this is implemented by a simple reboot, which will load the bootloader which could update the firmware e.g. if there is a firmware.bin file on the SD card. Since unless a firmware update is intended there is no such file on the SD card, the M997 command will just reboot the board.

Posted by Uli Köhler in 3D printing

How to get or set Trinamic TMC stepper motor current in Marlin firmware

In Marlin, you can dynamically configure the stepper motor current for Trinamic stepper drivers like the TMC2208 or the TMC5160.

Changing the motor current via G-Code

The easiest option is by using G-Codes. In order to set the stepper motor current for X , Y and Z to 2 Amperes (2000 mA), use M906 like this:

M906X2000Y2000Z2000

Now save the settings to the EEPROM using

M500

You can also query the current stepper motor current using

M906
X driver current: 2000
Y driver current: 2000
Z driver current: 2000
E driver current: 800
ok

Changing the motor current in the config file

You can also set default stepper motor current values in the Marlin config files. Note that these will be overridden by any value in the EEPROM.

In Configuration_adv.h, look for

#if HAS_TRINAMIC_CONFIG

which contains axis definitions like

#if AXIS_IS_TMC(X)
  #define X_CURRENT       800        // (mA) RMS current. Multiply by 1.414 for peak current.
  #define X_CURRENT_HOME  X_CURRENT  // (mA) RMS current for sensorless homing
  #define X_MICROSTEPS     32        // 0..256
  #define X_RSENSE          0.11
  #define X_CHAIN_POS      -1        // -1..0: Not chained. 1: MCU MOSI connected. 2: Next in chain, ...
  //#define X_INTERPOLATE  true      // Enable to override 'INTERPOLATE' for the X axis
#endif

Change the value in the line

#define X_CURRENT 800 // (mA) RMS current. Multiply by 1.414 for peak current.

so, for example to set 2A (2000 mA), set it to

#define X_CURRENT 2000 // (mA) RMS current. Multiply by 1.414 for peak current.

 

Posted by Uli Köhler in 3D printing

PySerial minimal request-reply example

This example sends the M119 (print endstop status) command to an attached 3D printer and prints the response in a loop

#!/usr/bin/env python3
import serial
ser = serial.Serial("/dev/ttyACM0")

try:
    while True:
        ser.write(b"M119\n")
        response = ser.read_until(b"ok\n")
        print(response.decode("utf-8"))
finally:
    ser.close()

Example output (in a loop):

Reporting endstop status
x_max: open
y_max: TRIGGERED
z_max: TRIGGERED
ok

 

Posted by Uli Köhler in 3D printing, Embedded, Python

How to view endstop status on Marlin using G-Code?

On 3D printer mainboards running the Marlin firmware, you can use M119 to view the current state of the endstops. Example output:

M119
Reporting endstop status
x_max: TRIGGERED
y_max: TRIGGERED
z_min: TRIGGERED
ok

 

Posted by Uli Köhler in 3D printing, Electronics

How to print Marlin firmware version using G-Code

The Marlin 3d printer firmware allows you to print the firmware version (along with different firmware settings) using the M115 command. The M115 command takes no parameters.

Example output:

M115
FIRMWARE_NAME:Marlin bugfix-2.0.x (May 13 2021 14:16:08) SOURCE_CODE_URL:github.com/MarlinFirmware/Marlin PROTOCOL_VERSION:1.0 MACHINE_TYPE:OCTOPUS_V1_0 EXTRUDER_COUNT:4 UUID:cede2a2f-41a2-4748-9b12-c55c62f367ff
Cap:SERIAL_XON_XOFF:0
Cap:BINARY_FILE_TRANSFER:0
Cap:EEPROM:1
Cap:VOLUMETRIC:1
Cap:AUTOREPORT_TEMP:1
Cap:PROGRESS:0
Cap:PRINT_JOB:1
Cap:AUTOLEVEL:0
Cap:RUNOUT:0
Cap:Z_PROBE:0
Cap:LEVELING_DATA:0
Cap:BUILD_PERCENT:0
Cap:SOFTWARE_POWER:0
Cap:TOGGLE_LIGHTS:0
Cap:CASE_LIGHT_BRIGHTNESS:0
Cap:EMERGENCY_PARSER:1
Cap:PROMPT_SUPPORT:0
Cap:SDCARD:1
Cap:REPEAT:0
Cap:SD_WRITE:1
Cap:AUTOREPORT_SD_STATUS:0
Cap:LONG_FILENAME:1
Cap:THERMAL_PROTECTION:1
Cap:MOTION_MODES:0
Cap:ARCS:1
Cap:BABYSTEPPING:0
Cap:CHAMBER_TEMPERATURE:0
Cap:COOLER_TEMPERATURE:0
Cap:MEATPACK:0
ok

 

Posted by Uli Köhler in 3D printing, Electronics

What is the difference between BIGTREE_OCTOPUS_V1 and BIGTREE_OCTOPUS_V1_USB

When building Marlin firmware for the BigTreeTech Octopus from the official BigTreeTech GitHub repository Marlin directory, you can see two different targets in PlatformIO:

  • BIGTREE_OCTOPUS_V1
  • BIGTREE_OCTOPUS_V1_USB

It is not immediately made clear what the difference between those is, but a short description can be found in ini/stm32f4.ini:

BIGTREE_OCTOPUS_V1_USB has support for using USB flashdrives directly on the board and serial-over-USB while BIGTREE_OCTOPUS_V1 has not.

In most cases, you want to build BIGTREE_OCTOPUS_V1_USB if printing via USB (e.g. via Octoprint) because the BIGTREE_OCTOPUS_V1 configuration does not allow printing via USB.
The compiler definitions for BIGTREE_OCTOPUS_V1 in ini/stm32f4.ini are:
build_flags        = ${stm32_variant.build_flags}
                     -DSTM32F446_5VX -DUSE_USB_HS_IN_FS

whereas BIGTREE_OCTOPUS_V1_USB enabled more USB-related features:

build_flags       = ${stm_flash_drive.build_flags}
                    -DSTM32F446_5VX -DUSE_USB_HS_IN_FS
                    -DUSE_USBHOST_HS -DUSBD_IRQ_PRIO=5
                    -DUSBD_IRQ_SUBPRIO=6
                    -DUSBD_USE_CDC_MSC
Posted by Uli Köhler in 3D printing, Electronics, PlatformIO, STM32

How I fixed STM32CubeProgrammer CUBEPROGRAMMER_ERROR_NOT_SUPPORTED

I tried to flash the DFU bootloader on the BigTreeTech Octopus V1 3D printer mainboard. However, STM32CubeProgrammer v2.8.0 showed me the following error message when trying to connect:

CUBEPROGRAMMER_ERROR_NOT_SUPPORTED

I could only fix this by completely uninstalling STM32CubeProgrammer and then installing STM32CubeProgrammer v2.7.0 from the BigTreeTech Github Repo. Most likely downloading v2.7.0 from the ST homepage will also work but I didn’t verify this.

Posted by Uli Köhler in 3D printing, Electronics, STM32

What 4-pin connectors are used on 3D printer mainboards for stepper motors?

Most currently available mainboards use this connector for connecting a stepper motor to the mainboard:

These connectors are named JST XH 2.54mm.

While many people interface these using standard 2.54mm female connectors

they should be interfaces using the proper JST XH 2.54mm female connector.

Posted by Uli Köhler in 3D printing

How to fix Marlin Error: Build environment ‘linux_native’ is incompatible with BOARD_RAMPS_14_EFB

Problem:

When compiling Marlin for simulation, you see an error message like

Error: Build environment 'linux_native' is incompatible with BOARD_RAMPS_14_EFB. Use one of these: mega2560, mega1280

Solution:

Open Marlin/Configuration.h and change the line

#ifndef MOTHERBOARD
  #define MOTHERBOARD BOARD_RAMPS_14_EFB
#endif

to use the BOARD_LINUX_RAMPS board:

// Choose the name from boards.h that matches your setup
#ifndef MOTHERBOARD
  #define MOTHERBOARD BOARD_LINUX_RAMPS
#endif

Even if the error message shows that you should use mega2560 or mega1280, you need to use BOARD_LINUX_RAMPS!

Posted by Uli Köhler in 3D printing