3D printing

What 6-pin connector do NEMA23 stepper motors use?

There are multiple different types of connectors for NEMA23 stepper motors. This is one of them.

A typical connector for NEMA23 stepper motors such as the Nanotec SCA5618X2804-A is the JST B6P-VH (part number of the male connector on the motor, source: NanoTec datasheet).

The corresponding mating connector is the JST VHR-6N, the series of connectors is being called JST VH. The pitch is 3.96mm.

The crimp contacts part numbers are (source: datasheet):

  • SVH-21T-P1.1 for 0.33mm² to 0.88mm²
  • SVH-41T-P1.1 for 0.5mm² to 1.25mm²

Posted by Uli Köhler in 3D printing

How to check a stepper motor for open/short circuit?

In order to correctly check a stepper motor for a hard short circuit, you need an LCR meter. If you only have an multimeter, skip the winding inductance check.

Measuring the phase resistance

First, check the resistance of each phase winding (pair A and pair B). The resistance should be between 0.5 Ω and 5 Ω, but note that it is also influenced by your multimeter probes and the contact resistance from the probe to the pin. If possible, compare the measurement to the datasheet of your stepper motor or to the datasheet of your motor or a good motor of the same model. If the datasheet lists 1.5 Ω, I would accept anything from 1.0 Ω to 2.0 Ω. If you see an infinite resistance (typically indicated by OL [overload] on your multimeter), either you measured the wrong pins or your probes do not electrically contact the pins – or your motor has an open winding (no contact). Re-measure multiple time, trying to contact the pin on different points on the surface to confirm. Also check if your multimeter displays a sensible value if you short the multimeter probes.
If you see a resistance that is way too low (e.g. 0.2 Ω for a nominal 1.5 Ω motor), your winding is shorted. This is typically not caused by a bad contact from the probes to the pin, but re-measure a few times just to confirm.

Now measure the resistance from one of the phase A pins to one of the phase B pins. The resistance should typically be OL (overload – i.e. a resistance so high the multimeter can’t measure it), but at least 5.0 MΩ. If it is any less, this indicates that the phases are shorted to each other. Be sure that you measured the correct pins.

Measuring the phase inductance

Now, Check the inductance of each phase winding (pair A and pair B). The inductance should be a couple of mH, but never below 100uH. A lower inductance indicates an winding that is shorted internally. If possible, compare with the datasheet of your stepper motor or see What phase inductivity value should my stepper motor have? for more details on this topic.

Now check, using the resistance mode of your LCR meter, check if any phase wiring has. Typically the resistance between one phase winding and the other

If you don’t know which pins of the connector belong to which phase winding, the two pins of each pair should have an inductance that is within ±30% of each another at maximum.

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

How to fix Marlin random driver error detected coil short circuit crash (Trinamic TMC)


When using Trinamic drivers with the Marlin 3D printer firmware, you might occasionally experience errors like

Send: N4193 G1 X12.345 Y34.567 E122.15252
Recv: E driver error detected: 0x10136000
Recv: coil short circuit
Recv: 		X	Y	Z	E
Recv: Enabled		true	true	true	true
Recv: Set current	2000	2000	2000	1000
Recv: RMS current	1999	1999	1999	990
Recv: MAX current	2819	2819	2819	1396
Recv: Run current	31/31	31/31	31/31	19/31
Recv: Hold current	15/31	15/31	15/31	9/31
Recv: Global scaler	167/256	167/256	167/256	133/256
Recv: CS actual	31/31	31/31	22/31	19/31
Recv: PWM scale	196716	33095745	65576	33488924
Recv: vsense
Recv: stealthChop	true	true	true	true
Recv: msteps		128	128	128	128
Recv: interp		true	true	true	true
Recv: tstep		171	678	max	1580
Recv: PWM thresh.	24	24	411	13
Recv: [mm/s]		102	102	3	41
Recv: OT prewarn	false	false	false	false
Recv: triggered
Recv:  OTP		false	false	false	false
Recv: off time	4	4	4	4
Recv: blank time	24	24	24	24
Recv: hysteresis
Recv:  -end		2	2	2	2
Recv:  -start		1	1	1	1
Recv: Stallguard thrs	0	0	0	0
Recv: uStep count	62	32	227	497
Recv: sg_result	0	0	395	0
Recv: stallguard
Recv: fsactive
Recv: stst		*	*		*
Recv: olb
Recv: ola
Recv: s2gb					*
Recv: s2ga
Recv: otpw
Recv: ot
Recv: Driver registers:
Recv: 		X	0x00:1F:40:00
Recv: 		Y	0x00:1F:40:00
Recv: 		Z	0x80:16:41:8B
Recv: 		E	0x10:13:60:00
Recv: echo:Driver error
Recv: Error:Printer halted. kill() called!
Changing monitoring state from "Printing" to "Error"


If the error always occurs at the start of each print, be sure to check your stepper motor setup for actual shorts! Measure the inducitivity using an LCR meter to be sure, it should be around the rated value for your motor! See this post for information about typical stepper motor inductivity.

If the error occurs occasionally, it is recommended in the datasheet that you use more conservative short detection settings.

You need to make the change this in Marlin/src/module/stepper/trinamic.cpp.

Go to the section for the driver type you are using. In my example, this would be

// ...
void tmc_init(/* ... */) {
   // NOTE: tmc_init() is the function we need to insert code in!

Now insert, just before the TERN(HYBRID_THRESHOLD, /* ... */) line (if such a line does not exist, insert at the end of the function:

// Set more conservative short detection settings
st.shortfilter(3); // 3us SHORT filter
st.s2vs_level(15); // Lowest sensitivity short to supply voltage protection
st.s2g_level(15); // Lowest sensitivity short to ground protection
st.shortdelay(1); // 1.5us instead of 0.75us short delay

These are the most conservative settings possible using this setup.

Now retry your print.

In case this still doesn’t help, you can disable short protection entirely. Note that short protection exists to prevent damage to your stepper motor, your mainboard and your cabling, so you should only disable it if there is no other choice!

In order to disable short protection entirely, insert this code block instead of the conservative setting code block from above:

// Disable short protection entirely

Tested with Marlin version

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

What phase inductivity value should my stepper motor have?

Stepper motor phase inductivity varies widely. Even for a given size of stepper motor, such as NEMA17 with a length of 38mm, you can buy widely varying inductivity values even from the same manufacturer:

Both of these have the same holding torque of 80NcmInductivity is not an indicator of motor power!

As a general rule, remember:

  • NEMA17 steppers tend to be in the 1mH to 50mH range.
  • NEMA23 steppers tend to be in the 250μH to 25mH range

If you are checking your motor for a shorted winding, if the inductance is below 100μH, you can be pretty sure that the stepper motor is defective.

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

How to install OctoScreen plugin for OctoPrint

OctoScreen provides a plugin that you can use within OctoPrint to configure the UI. You can find it on GitHub here, but you can simply install it using the OctoPrint plugin manager using the following URL:



Posted by Uli Köhler in 3D printing

How to change OctoScreen minimum extrusion temperature


When trying to extrude low-temperature filaments using OctoScreen, you will see this error message:

The temperature of the hotend is too low to extrude. Please increase the temperature and try again

By default, OctoScreen has a minimum extrusion temperature of 150°C which is fine for PLA, but  for some low temperature materials you need to change the hardcoded value.

Note that setting you minimum extrusion temperature too low might damage or even destroy your extruder, if the material is not properly melted. So take caution in setting the correct value here.


Open utils/tools.go and edit this line:


Just set your desired temperature and then recompile (see the OctoScreen README on how to do that)

Note that often the firmware (like Marlin) has a separate cold extrusion prevention limit, so you need to change the limit in both OctoScreen and the firmware. For Marlin, see How to disable Marlin cold extrusion prevention via G-Code.


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

How to auto-reset Marlin after Kill

Under certain critical circumstances like thermal runaway protection, Marlin entered a killed state. You typically need to hard-reset the mainboard after entering that state. However, in environments where physical access to the machine, hard-resetting Marlin is not possible, so you might need to implement.

Note that diagnosing & fixing the underlying issue that caused the reset is extremely important and ignoring it might lead to further issues, up to a fire hazard or the destruction of the printer. So be sure to know what you are doing before just.

The following guide was tested with Marlin It should work with most Marlin 2.x versions with minor adjustments.

First, note that as an alternative to hard-resetting the mainboard there is the SOFT_RESET_ON_KILL option which allows you to trigger a soft reset out of kill mode using a button connected to a pin. We won’t delve into more detail on this, since it doesn’t really change the requirement for physical access to the printer.

Open Marlin/src/MarlinCore.cpp and find the minkill(bool) function.

At the end, this function contains a preprocessor-controlled branch of the following structure:

  // Branch 1 ...
  // Branch 2 ...

We will replace this entire branch by these lines:

// Wait for 5 seconds for controller to catch up
for (int i = 5000; i--;) { DELAY_US(1000); watchdog_refresh(); } // 5000*1ms = 3s
// Auto-reset after kill

I prefer to insert the 5-second delay into the reboot logic so no superordinate controller (like a Raspberry Pi running OctoPrint) can miss that the Marlin board has been killed. Although most controllers should be able to detect the killed state from the G-Code, this 5-second delay will simulate the default behaviour of not resetting at all after the killed state has been reached. However note that in case you absolutely need to reset ASAP after the kill state has been reached, it’s typically safe to omit the wait loop.

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

Implementing STM32 DFU bootloader firmware upgrade in Marlin using M997

Marlin implements the M997 command which is intended to switch the mainboard into a firmware upgrade mode.

All STM32 variants have an integrated (hard-coded – so no need to flash it yourself) bootloader that is notoriously difficult to active.

However, Marlin implements M997 on the STM32 as just a reboot:

void flashFirmware(const int16_t) { HAL_reboot(); }

This only works if you are using a custom bootloader on your board – however, it does not use the STM32 integrated bootloader.

The following code was tested on the STM32F446 (BigTreeTech Octopus V1) but should work on any STM32 variant. It is based on previous work by Dave Hyland on StackOverflow. Replace the default flashFirmware() function in Marlin/src/HAL/STM32/HAL.cpp

void flashFirmware(const int16_t) {


    // arm-none-eabi-gcc 4.9.0 does not correctly inline this
    // MSP function, so we write it out explicitly here.
    //__set_MSP(*((uint32_t*) 0x00000000));
    __ASM volatile ("movs r3, #0\nldr r3, [r3, #0]\nMSR msp, r3\n" : : : "r3", "sp");

    ((void (*)(void)) *((uint32_t*) 0x00000004))();

    // This will never be executed

Note that we left a HAL_reboot() call as a safeguard at the end, just in case the previous calls fail.

On my BigTreeTech Octopus V1 (STM32F446), by using this code, you can successfully enter the integrated DFU bootloader.

Also see our previous posts on how to use the STM32 in DFU bootloader mode:

Posted by Uli Köhler in 3D printing, C/C++, STM32

M206 Set home offset: Positive or negative coordinates? A simple rule for Marlin

When adjusting the home offset (most often the Z offset) of a 3D printer using the M206 command, many users wonder which sign to use. In other words, in order to move the nozzle 0.1mm closer to the bed, do you use M206Z0.1 or M206Z-0.1. However, there’s a simple rule:

To move the nozzle closer to the bed, use positive coordinates, e.g. M206Z0.1 to move the nozzle 0.1mm closer to the print bed.

To move the nozzle further away from the bed, use negative coordinates, e.g. M206Z-0.2 to move the nozzle 0.2mm further away from the print bed.


Posted by Uli Köhler in 3D printing

How to run single command on 3D printer using picocom

In our previous post How to connect to your 3D printer using picocom we showed how to open an interactive serial session on the command line using picocom. But you can also use picocom to run just a single command such as the M997 firmware update command:

echo "M997" | picocom -b 115200 /dev/ttyACM0 --imap lfcrlf --echo

If your USB serial device is named /dev/ttyUSB0 instead of /dev/ttyACM0 you can use this alternative version:

echo "M997" | picocom -b 115200 /dev/ttyACM0 --imap lfcrlf --echo



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

How to home only ONE axis in Marlin

In the Marlin 3D printer firmware, you can home one axis without homing the other axes using G28[Axis].

In order to home the X axis:


In order to home the Y axis:


In order to home the Z axis:


Homing X & Y without homing Z

You can also home multiple axes using G28[Axis 1][Axis 2]. So in order to home the X and the Y axis (but not home the Z axis), run



Posted by Uli Köhler in 3D printing

How to flash Marlin on BigTreeTech Octopus V1 using debug adapter

In order to flash the Bigtreetech Octopus V1 using my STLinkv2 debug adapter, I needed. First we need to note that the first 32k of flash memory are occupied by the bootloader (0x08000000 to 0x08008000). So we need to flash the firmware at address 0x08008000. By default, this is not configured correctly in Marlin.

Open ini/stm32f4.ini and edit the [env:BIGTREE_OCTOPUS_V1]:

platform           = ${common_stm32.platform}
extends            = stm32_variant
board              = marlin_BigTree_Octopus_v1
board_build.offset = 0x8000
board_upload.offset_address = 0x08008000
build_flags        = ${stm32_variant.build_flags}
                     -DSTM32F446_5VX -DUSE_USB_HS_IN_FS
upload_protocol = stlink

Note that you absolutely need to re-flash the bootloader in case you accidentally flashed with the old configuration. Follow the official documentation in order to flash the bootloader. I flash usin STM32CubeProgrammer 2.7.0 (2.8.0 does not work) on both Linux and Windows.

The [env:BIGTREE_OCTOPUS_V1_USB] will be updated automatically as it includes [env:BIGTREE_OCTOPUS_V1]

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

How to turn case light on/off in Marlin using G-Code

In order to turn the case light on in Marlin, use M355S1P255is full brightness:


In order to turn the case light off, use S0


In order to turn it on at half brightness, use P128



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

How to autotune Marlin Hotend/Extruder PID parameters

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



  • 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 COOLER_FAN_PIN -1


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