Electronics, stepper drivers and control boards
📍 Where we are: Part II · The Machine Stack — Chapter 5 of 16. Chapter 4 described the firmware; this chapter covers the circuit boards it runs on and the safety circuits that stop a heater from running away. It closes Part II.
The firmware is the driver's brain; the electronics are the nerves and muscles. A small computer chip decides, a "driver" chip turns each decision into the right current for a motor coil, a thermometer chip-and-wire reports the nozzle's temperature, and a power switch heats the nozzle. If the thermometer falls out and starts reporting "cold", a well-designed system notices that something is wrong instead of heating forever.
What this chapter covers
We follow the signal path from the microcontroller (MCU) to stepper drivers, heaters, sensors and CAN-bus toolheads, cover thermal safety, and ask what to open-source in a hardware design. Code was run unless marked otherwise.
The control board
A control board carries the MCU, sockets or chips for stepper drivers, power switches for the heaters and fans, and connectors for endstops, probes and thermistors. A classic open example is RAMPS 1.4, a shield that sits on an Arduino Mega: it takes Pololu-style driver boards (A4988, DRV8825), supports up to five motors, is mainly a 12 V board, and uses MOSFET outputs for the heated bed (pin D8), hotend (D10) and a fan (D9) [1]. Its wiki page notes that the bed MOSFET and poly fuse can run hot [1]. 32-bit boards followed, for example the BIGTREETECH SKR V1.3 (LPC1768, with TMC2130 and TMC2208 interfaces per its repository description) [2] and Duet boards running RepRapFirmware (Chapter 4).
Stepper drivers
The driver chip controls the current in a motor's coils and divides each step into microsteps (Chapter 3). Marlin's stock configuration lists A4988, DRV8825, LV8729, TB6600 and several Trinamic (TMC) chips such as TMC2208, TMC2209 and TMC5160 [3]. Klipper can configure TMC2130, TMC2208/2224, TMC2209, TMC2240, TMC2660, TMC5160 and TMC5262 at run time [4]. The manufacturer's TMC2209 datasheet (Rev. 1.09, February 2023, now published by Analog Devices) describes a step/direction driver with a UART option, StealthChop2 and SpreadCycle chopper modes, StallGuard4 sensorless stall detection, and 256 microsteps through MicroPlyer interpolation, with up to 2 A RMS motor current [5].
stealthChop and spreadCycle
TMC drivers have two chopper modes. By default Klipper uses spreadCycle, which "provides greater torque and greater positional accuracy" than stealthChop, while stealthChop "may produce significantly lower audible noise on some printers" [6]. Klipper recommends picking one mode and keeping it: either omit stealthchop_threshold (spreadCycle) or set it to 999999 (stealthChop always on) [6].
A Klipper driver section looks like this. The pin and current values are placeholders and we did not run it on hardware; parameter names are from the configuration reference [7]:
[tmc2209 stepper_x]
uart_pin: <board-specific pin>
run_current: 0.8 # amps RMS, illustrative; check your motor
#stealthchop_threshold: 999999 # default is 0, i.e. spreadCycle
DUMP_TMC prints every register field Klipper configures and can read back [6].
Thermistors and temperature sensing
A thermistor is a resistor whose resistance changes strongly with temperature. The board reads it with a voltage divider and the firmware converts it to degrees. Marlin's stock TEMP_SENSOR_0 1 selects "100kΩ EPCOS" from its sensor table [3]; Klipper names examples such as "EPCOS 100K B57560G104F" and "Generic 3950" and supports PT100/PT1000 and thermocouple amplifier chips (MAX31855, MAX31865 and others) [7] [4].
The "3950" is a beta value. The following snippet converts a raw ADC reading to a temperature with the beta equation 1/T = 1/T0 + ln(R/R0)/B. The pull-up (4.7 kΩ) and ADC range (12 bit) are illustrative assumptions, not any specific board. We ran it with Python 3.
import math
def beta_temp_c(r_ohm, r0=100_000, t0_c=25.0, beta=3950):
inv_t = 1/(t0_c + 273.15) + math.log(r_ohm / r0) / beta
return 1/inv_t - 273.15
def divider_r(adc, adc_max=4095, r_pullup=4700):
return r_pullup * adc / (adc_max - adc) # thermistor to ground
for adc in (1500, 4000):
r = divider_r(adc)
print(f"adc {adc:4d} R {r:9.0f} ohm T {beta_temp_c(r):6.1f} C")
adc 1500 R 2717 ohm T 136.5 C
adc 4000 R 197895 ohm T 10.4 C
An ADC value near full scale means a very high resistance, which is how a loose sensor can look to the firmware.
Thermal safety
Marlin's comments state the problem plainly: if a thermistor falls out, it reports the lower temperature of the room air and "the firmware will keep the heater on". Its solution is to start observing once the target is reached and halt if the temperature stays more than a hysteresis below target for longer than a period [8]. The stock values are 40 s and 4 °C for hotends, and 20 s and 2 °C for the bed, enabled by THERMAL_PROTECTION_HOTENDS and THERMAL_PROTECTION_BED; a separate "Heating failed" check watches that temperature rises within WATCH_TEMP_PERIOD (40 s) [3] [8]. The example's 275 °C maximum is described as protecting components "but NOT from shorts and failures" [3].
Klipper enables heater verification automatically for every configured heater. Its [verify_heater] section defaults are max_error: 120, hysteresis: 5 and a check_gain_time of 20 seconds for extruders and 60 seconds for the bed, and leaving the configured min_temp/max_temp range puts the MCU into a shutdown state [7].
The snippet below is a simplified illustration of the Marlin idea, not Marlin's code; we ran it.
class RunawayWatch:
def __init__(self, period_s=40, hysteresis_c=4):
self.period, self.hyst, self.below_for, self.armed = period_s, hysteresis_c, 0, False
def step(self, target, measured, dt=1):
if measured >= target - self.hyst: self.armed = True
if not self.armed: return "heating"
if measured >= target - self.hyst: self.below_for = 0; return "ok"
self.below_for += dt
return "HALT" if self.below_for >= self.period else "watching"
w = RunawayWatch()
log = [w.step(200, 200)]
log += [w.step(200, 25) for _ in range(40)] # sensor fell out: reads room temperature
print(log[0], log[1], log[-1])
ok watching HALT
Treat firmware protection as one layer, not the only one: it cannot act if the firmware is not running.
CAN-bus toolheads
A CAN bus is a two-wire network that lets a small board on the toolhead talk to the main board, instead of one wire per sensor and motor. Klipper supports CAN on stm32, SAME5x and rp2040 chips with a CAN transceiver, recommends 1000000 as the bitrate and a USB-to-CAN adapter, and requires exactly two 120 ohm terminators (about 60 ohms measured between CANH and CANL with power off). A device is found with canbus_query.py and configured with canbus_uuid [9]:
[mcu my_can_mcu]
canbus_uuid: 11aa22bb33cc
(Quoted from the documentation; not run.) Katapult is a GPL-3.0 bootloader for Klipper [10], and Duet 3 expansion and tool boards run Duet3Expansion firmware [11].
Control board signal path: MCU and drivers to motors, heater switches and thermistors, a CAN-bus link to the toolhead, and firmware thermal protection watching the temperature loop.
Original diagram by the authors, created with AI assistance.
What to open-source, and what not to
OSHWA's certification asks that everything under the creator's control be open; third-party chips need datasheets that are "fully accessible and shareable", while closed third-party components outside the creator's control need not be opened, though they "cannot require an NDA for access" [12] [13]. For a board that means publishing schematics, layout in a native format, the bill of materials and firmware. Branding is optional and outside the scope of opening the source [13].
Why it matters
Knowing the signal path and the default protections your firmware enables tells you where to look when a heater or motor misbehaves.
In the real world
When building or repairing, check your driver's current setting against the motor's rating, and test thermal protection deliberately, attended, rather than assuming it works.
Key terms
- Stepper driver — a chip that converts step and direction signals into coil currents for a stepper motor.
- TMC (Trinamic) driver — a family of drivers (TMC2209, TMC5160 and others) with stealthChop and spreadCycle modes and a configuration interface.
- spreadCycle / stealthChop — two TMC chopper modes: torque and accuracy versus lower noise.
- Thermistor — a resistor whose resistance varies strongly with temperature, used as a thermometer.
- Beta value — a thermistor constant (such as 3950) used in a simple resistance-to-temperature formula.
- Thermal runaway — a heater staying on while the temperature does not rise as expected, for example because the sensor has come loose.
- CAN bus — a two-wire network for linking boards, used to connect toolhead boards.
- Shield (RAMPS) — an add-on board that plugs onto a microcontroller board.
Where this leads
With the machine stack covered, Part III turns to the software above it, beginning with slicers.