Temperature control

Temperature control reads a sensor and drives a heater: Smoothie changes heater power to maintain the requested temperature.
Temperature control reads a sensor and drives a heater #

This module reads temperature sensors (thermistors) and uses heater and cooler elements to maintain a set temperature. A temperature controller reads a sensor and turns a heater or cooler on and off to hold the temperature you set. It is used for example for extruder hotends, or heated beds. You can use one for an extruder hotend and another for the heated bed.

A J-head hotend with thermistor and heating element

This is a J-head hotend with its thermistor and heating element.

Multiple modules

In Smoothie, you do not get just one TemperatureControl module. You can actually create as many as you want, simply by adding them to the configuration file.

It goes something like this:

V1 Configuration (flat namespace):

temperature_control.hotend.enable                    true
temperature_control.hotend.thermistor_pin            0.23
etc ...

temperature_control.bed.enable                       true
temperature_control.bed.thermistor_pin               0.24
etc ...

V2 Configuration (INI sections):

[temperature control]
hotend.enable = true
hotend.thermistor_pin = ADC1_1
# etc ...

bed.enable = true
bed.thermistor_pin = ADC1_2
# etc ...

This will create and configure two separate TemperatureControl modules that will act completely independently from each other.

The line that effectively “creates” the module is the option. If set to true, a module is created and further configuration is read. If set to false, further configuration for this module is ignored as no module is created.

In the Configuration section below, the first two parts (temperature_control.module_name) of the configuration are sometimes omitted for conciseness, but have to be added in your actual configuration file (see example).

Configuration

Reading temperatures

To reach a desired temperature, you must be able to know what the current temperature is. This is done using a Thermistor connected to an ADC on the controller board, or a Thermocouple.

Thermistor

A given controller board only has a given number of ADCs (analog (temperature) to digital (Smoothie) converter) capable pins.

On the Smoothieboard for example, there are 4 thermistor inputs, labelled from T0 (or th1) to T3 (or th4), and corresponding in the same order to the pins 0.23 to 0.26. T0 is usually used for the hotend, and T1 for the bed.

Thermistor inputs are not polarized, the direction you connect them in on your board is not important.

V1 Configuration:

temperature_control.hotend.thermistor_pin        0.23

V2 Configuration:

[temperature control]
hotend.thermistor_pin = ADC1_1
Smoothieboard thermistor input name T0 (th1) T1 (th2) T2(th3) T3(th4)
Pin for configuration 0.23 0.24 0.25 0.26
Smoothieboard v2 thermistor input name T1 T2 T3 T4 (Board temp)
Pin for configuration ADC1_1 ADC1_2 ADC1_3 ADC1_0
STM32 Pin PF11 PF12 PB0 PA0_C
Typical use Hotend Bed Hotend2/Chamber Board monitoring
You read the value of the thermistor inputs by sending the M105 command.

If you receive a value of inf for an input, for example: ok T:inf /0.0 @0 B:24.1 /0.0 @ It means the sensor is not properly connected, or it is damaged in some way.
Choosing the right thermistor

Find out which thermistor is fitted to your hotend or bed, then set its model in the config. If it is missing from the list, use the beta value or the Steinhart–Hart coefficients from the datasheet. See choosing a thermistor for the model list and both config examples.

PT100

The PT100 as used by the E3D amplifier needs a firmware build that includes PT100 support. The pre-built binary firmware may not include it, so check the PT100 page.

Configuration and usage

On V1, use the E3D analog PT100 amplifier on a spare ADC pin. The pull-up on the thermistor inputs interferes with this amplifier. Check PT100 wiring and configuration before connecting it, including the 3.3 V supply requirement. On V2, use a supported thermistor or MAX31855 thermocouple.

Thermocouple via SPI

Thermocouples are supported by connecting a MAX31855 chip to one of the SPI channels. Thermocouples give a stable measurement over a wide temperature range, and can typically withstand higher temperatures than thermistors.

Use a MAX31855 breakout when your hotend needs a thermocouple, for example the Adafruit Thermocouple Amplifier MAX31855 breakout board. Use an isolated probe with this chip. A probe tied to ground can trip its fault detection. For a grounded probe on V1, see the AD8495 example below.

Notes for V1:

  • The MAX31855 does not like having the thermocouple electrically connected to ground, and will flag an error if this happens. Make sure your thermocouple is isolated. If you must use a non-isolated thermocouple, try the AD8495 analog amplifier instead (see next section).
  • Connecting a thermocouple and a RRD GLCD panel to the same SPI bus does not work.
  • You need a recent edge build if you want to have multiple thermocouples on the SPI bus.
  • As of 2018-02-13, the max31855 module does not work when configured without a heater pin.

The V1 RRD GLCD and MAX31855 examples need separate SPI buses. On V2 Prime, use the expansion SPI bus and give each MAX31855 its own chip-select pin. All MAX31855 sensors use the same bus.

Smoothieboard v1 Breakout board
3v3 Vin
GND GND
0.16 CS CS
0.18 MOSI Not used
0.15 SCK CLK
0.17 MISO DO
Smoothieboard v2 Breakout board
3v3 Vin
GND GND
PD15 (GE contact 6, if free) or any GPIO (e.g., from Gadgeteer) CS
PB5 SPI1 MOSI Not used
PA5 SPI1 SCK CLK
PA6 SPI1 MISO DO

See Prime header GE for the connector contacts. The MAX31856 board needs a different driver and cannot use these settings.

To configure Smoothie to use the thermocouple connected like this, replace the thermistor and thermistor_pin parameters with the following:

V1 Configuration:

temperature_control.hotend.sensor        max31855

The SPI channel and chip select pin can be changed using the following parameters:

temperature_control.hotend.chip_select_pin    0.16
temperature_control.hotend.spi_channel         0    # SPI channel 0 or 1

V2 Configuration:

[temperature control]
hotend.sensor = max31855
hotend.spi_select_pin = PD15
hotend.spi_channel = 0    # SPI channel 0 or 1

When using the MAX31855, you need to reduce the frequency at which temperatures are read. This is due to a limitation in the amplifier, see this pull request. The MAX31855 and MAX6675 chips take 100 and 220 milliseconds, respectively, to perform the temperature conversion. Sampling them faster than this will interrupt the conversion process, causing the chip to return the same value for every subsequent sampling. To resolve that, set readings_per_second to 9 for the MAX31855 and 4 for the MAX6675.

V1 Configuration:

temperature_control.module_name.readings_per_second      9

V2 Configuration:

[temperature control]
module_name.readings_per_second = 9

Thermocouple via Amplifier

On V1, Smoothie supports reading thermocouples via an ADC (the same kind used to read thermistors) if the analog value is converted by the AD8495 thermocouple amplifier. This allows you to read values from a thermocouple without having to use a SPI port. To use the AD8495, you need to set the right sensor type:

V1 Configuration:

temperature_control.hotend.sensor    ad8495

And then configure the pin you’ll be using to read the sensor:

temperature_control.hotend.ad8495_pin   0.24

And the offset. This will depend on the AD8495 wiring. If the REF pin(pin 2) is connected to ground or 0V then the offset is 0. This means that Smoothie can measure 0C to 660C, depending on thermocouple. If, like the Adafruit board, the REF pin is connected to 1.25V then the offset is 250. With a 250 offset, Smoothie can measure -250C to 410C. The formula for calculating offset is offset = REF/0.005. The simplest way to see if the offset is set incorrectly is that the temperature reading at room temperature will be wrong.

NOTE from a community member: The AD8495 needs a GND and VCC. Using either GND or AGND from the Smoothieboard seems to work. Unclear which is preferred (if you know, please update this note!).

temperature_control.hotend.ad8495_offset   250
On V2, use the MAX31855 setup above. The firmware does not have an AD8495 driver.

Heating things up.

To reach the desired temperature, you need a means of changing the temperature. This is usually done by letting current through:

  • Resistors
  • Heater cartridges
  • PCB, kapton or silicone heater plates

This is for example how hotends or heated beds are heated to their target temperature.

The component turning the current on and off can be a mosFET (like on Smoothieboard) or a Solid-State Relay for example.

This is controlled from the board running Smoothie using a GPIO pin.

In the case of mosfets, on a Smoothieboard, a given pin is connected to a given mosfet, and you have to use that specific pin to control that specific mosfet.

See this schematic below or on the Smoothieboard page to see what mosfet corresponds to what pin.

Mosfet inputs and outputs

Read more about the mosfets here

To set a pin to a given heater, do for example:

V1 Configuration:

temperature_control.hotend.heater_pin        2.7

V2 Configuration:

[temperature control]
hotend.heater_pin = PE0

Note on pins:

A pin is an input or output of the board, you name it by its number in the config, see the pinout. You can change how it behaves by adding modifiers after the number, for example 1.19! inverts it.

Modifier Symbol
Invert pin !
Open drain o
Pull up ( default on most pins ) ^
Pull down v
No pull up -
Repeater mode @

Some pins have hardware on the board forcing a given configuration, for example endstop inputs have on-board pull-up resistors which configuration can’t remove.

Learn more: Pin configuration

Controlling with G-codes

By default, Smoothie will not heat anything. That could be a dangerous thing to do unwatched.

You have to send G-codes to turn your heater on and off, set a given temperature etc.

There is a set of widely used G-codes corresponding to different usual actions (for example setting the hotend temperature is M104 in the Reprap world).

But as you are defining your own custom temperature controller, you have to choose what gcode will be used to control it, Smoothie doesn’t know what exactly it’s controlling.

So for example if this is a hotend, it will look something like this for the “standard” gcodes:

V1 Configuration:

temperature_control.hotend.set_m_code            104
temperature_control.hotend.set_and_wait_m_code   109

V2 Configuration:

[temperature control]
hotend.set_m_code = 104
hotend.set_and_wait_m_code = 109

set_m_code is used to set a given temperature, and continue running Smoothie immediately. set_and_wait_m_code is used to set a given temperature, and then pause Smoothie until that temperature is reached.

Reading with G-code

There is a single g-code used to read temperature for all the temperature_control modules at the same time: M105

But it has to have a way to tell you what temperature corresponds to what specific module.

There is a standard format for this which was used before Smoothie and still is today:

ok T:22.1 /0.0 @0 B:22.5 /75.0 @210

Here T is the hotend, and B is the bed. This is a convention. But in your configuration, we have to specify which is which:

V1 Configuration:

temperature_control.hotend.designator        T

V2 Configuration:

[temperature control]
hotend.designator = T

Bang Bang Control

The simplest form of heat control is called bang bang this simply turns the heater on or off depending on whether it is under or over the target temperature (plus some hysteresis). This is best used for high amp beds using a relay to turn it on and off.

to enable this form of control in the config define the following…

V1 Configuration:

temperature_control.bed.bang_bang            true            # set to true to use bang bang control rather than PID
temperature_control.bed.hysteresis            2.0              # set to the temperature in degrees C to use as hysteresis when

V2 Configuration:

[temperature control]
bed.bang_bang = true          # set to true to use bang bang control rather than PID
bed.hysteresis = 2.0          # set to the temperature in degrees C to use as hysteresis

Example: If you set your temperature to 50 degrees, and your hysterisis is 2 degrees, then the heaters will turn on if the temperature is below 48 degrees, and off if the temperature is above 52 degrees.

The default form of heater control is PID.

PID

PID is the default. It adjusts heater power as you get closer to the target, so the heater can settle instead of cycling fully on and off. Tune the hotend and bed separately. Use the values from the autotune below, or see PID settings and manual tuning if you need to adjust them yourself.

PID autotuning

Run M303 from a serial terminal to tune at the temperature you actually use. V1 selects the controller with E and V2 selects the tool with P. Follow the autotuning steps to find the ID, run the tune and put the PID values in your config.

Fine Tuning

If the temperature goes well past the target on its first climb, see fixing overshoot. Use a heater rated for your power supply and set the maximum temperature for your actual heater assembly.

Safety

This module controls temperature by actuating heating elements. Heat, if left unchecked, causes fire. Fires are painful, expensive, and can even cause death. You definitely should set up as many safety features as you can, even those that are disabled by default. This section explains how to do so.

This can happen to you! Fire It has already been known to happen to Reprap/CNC enthusiasts.

For an example see here.

A heater can start a fire if the temperature reading is wrong or the output gets stuck on. Set the temperature limits and runaway checks for your heater. Use a separate cutoff where the machine needs one, and read the wiring warning before wiring the output.

Thermistor disconnect

If a thermistor is disconnected from its thermistor input (cable gets cut, connector falls), Smoothie can detect the problem by itself, as this causes a recognizably different input.

When this happens, Smoothie will detect the problem, turn off all heaters, and enter the HALT state. It will also show you the following message:

Temperature reading is unreliable on T, HALT asserted - reset or M999 required

You need to solve the issue, and then either reset the board or issue the M999 command.

You do not need to do anything to activate this safety check.

Watchdog

The watchdog is a peripheral inside the microcontroller. Smoothie must tell it “Hey, I’m alive and I have not crashed” on a regular basis. If Smoothie stops doing that, the watchdog knows Smoothie has crashed and puts the board into a safe state, which turns all heaters off. You do not need to do anything to activate this. On V1 it is enabled by default (10 second timeout, configurable with watchdog_timeout) and a timeout enters the debug handler. Use the temperature checks below as well. A watchdog cannot turn off a heater if the power switch has failed on.

Maximum temperature detection

You activate this safety check (and you should) by adding the following to your configuration. Set a maximum temperature for your actual heater, sensor and mount. The value in the examples is just an example.

V1 Configuration:

temperature_control.module_name.max_temp      300

V2 Configuration:

[temperature control]
module_name.max_temp = 300

Once this is set, it will be impossible to set temperatures higher than the value.

Also, if the temperature reaches this temperature, Smoothie will turn off all heaters, go into HALT state, and print out the following message:

Error: MINTEMP or MAXTEMP triggered on T. Check your temperature sensors!
HALT asserted - reset or M999 required

You need to solve the issue, and then either reset the board or issue the M999 command.

The most likely cause for this problem is that a heater mosfet is stuck being always active. If this is the case, Smoothie cannot control that heater anymore, and nothing the firmware can do can solve the issue, and you are on your way to a fire.

This is why you need to give Smoothie a second way to cut power: either by having a signal that allows you to turn the power supply off, or a solid-state relay capable of cutting all power to all mosfets. See documentation below for how to achieve this.

Runaway detection

We call “temperature runaway” a phenomenon where Smoothie tries to control temperature, but for some reason the temperature increases out of control.

There are several ways this can happen:

  • The thermistor is disconnected from the heater block, so the thermistor is reading room temperature, and keeps heating to try to reach its target.
  • The mosfet or solid-state relay controlling the heater is stuck always letting power pass through, this causes temperature to increase even when Smoothie does not ask for temperature to increase.

NOTE This is now enabled by default in newer versions of edge, the timeout is set pretty high (900 seconds), it can be disabled by setting the values below to 0.

Initial heat-up runaway detection

To detect if the thermistor is disconnected during the initial heat-up (temperature increasing until it reaches its target), we need to define how long it should take for temperature to increase to the target. And if the temperature takes too long to reach this target, we know something is wrong (likely the thermistor is detached from the heating element).

To configure this value, we first need to ask the machine to heat-up, and use a timer to know how long it takes. For example, a given hotend could take 100 seconds to heat up. Then, we add a margin to this, for example 20%, and we say that if the hotend takes more than 120 seconds to heat up, something is wrong.

Now that you have a reasonable safety value, add the runaway_heating_timeout option to your configuration file:

V1 Configuration:

temperature_control.module_name.runaway_heating_timeout      120 # max is 4088 seconds

V2 Configuration:

[temperature control]
module_name.runaway_heating_timeout = 120  # max is 4088 seconds

Now, if heating ever takes longer than 120 seconds, Smoothie will know there is a problem, enter HALT state, turn off heaters, and show the following message:

Error: Temperature too long to be reached on T, HALT asserted, TURN POWER OFF IMMEDIATELY - reset or M999 required

You can disable this by setting it to 0.

Please note that if your PID settings are not correctly tuned, this can get activated by accident because of the “swings” un-tuned temperature curves can have. Please tune your PID settings before activating this feature.

If the Smoothieboard is being a bit too strict with detecting the temperatures, you can add runaway_error_range as a parameter (optional), it is 1° by default meaning acceptable temperature detected can be +/- 1° of the set temp. If your printer tends to not stick close enough to the right temperature, increase this value. It only applies to the heat up and cool down timeouts.

Cool down timeout NOTE If you set runaway_cooling_timeout then understand that if you set a bed temp when the bed is already hotter than the setting it will need to cool down within the time period you set.

If the bed has a lot of thermal mass then this may take a long time or actually never happen, and a timeout will occur eventually.

This is why it is disabled by default.

However, if you do reduce the bed temperature during a print you MUST set this value otherwise you will get a runaway detection error if the new temp is lower than the current temp.

This is also true of setting the hotend temperature lower while printing, then you also need to set this timeout correctly.

Out of range runaway detection

This safety feature allows to detect if the current temperature

Appendix: older V2 AD8495 configuration

This comes from the older wiki and has not been checked against the current firmware. The current V2 firmware has no AD8495 driver (see “Thermocouple via Amplifier” above), so these settings probably do nothing on V2.

[temperature control]
hotend.sensor = ad8495
hotend.ad8495_pin = 0.24
hotend.ad8495_offset = 250

Configure the pin you will be using to read the sensor with ad8495_pin.

The ad8495_offset depends on the AD8495 wiring. If the REF pin (pin 2) is connected to ground or 0V then the offset is 0. This means that Smoothie can measure 0C to 660C, depending on thermocouple. If, like the Adafruit board, the REF pin is connected to 1.25V then the offset is 250. With a 250 offset, Smoothie can measure -250C to 410C. The formula for calculating offset is offset = REF/0.005. The simplest way to see if the offset is set incorrectly is that the temperature reading at room temperature will be wrong.

This is a wiki! If you'd like to improve this page, you can edit it on GitHub.