What are the variables for PID control? How to use M301? How to use this command to switch from PID to bang-bang?

I'd like to have the 12V PID output of an old Printrboard hotend control a relay that attaches to a 120V crockpot for something I'm making. I have everything working fine using a relay, but because the hotend heater is using PID control, the relay clicks about 3 times per second each time it needs to heat up the crockpot.

Not only is this sound annoying, but it will likely reduce the life of the relay significantly. I need the crockpot temperature controlled, so the programmatic thermistor control on an old 3D printer board is a huge help, and probably cheaper than the alternatives. Especially since this board has an SD slot built in and can run any code on power-up. In "bang-bang" control, there would be less clicking as the crockpot heats up, and the relay wouldn't be damaged.

I can't update the firmware on my board to use a different pin because it is a really old Printrbot board. All the required software is almost 5 years old and is really difficult to find. Fortunately the Printrboard does support M301. So, I should be able to use this command to switch from PID control to bang-bang.

In Marlin's documentation, it describes a command called M301, along with a lot of variables for using this command. The problem is, I don't know what any of these variables mean.

M301 [C<value>] [D<value>] [E<index>] [I<value>] [L<value>] [P<value>]


[C<value>]

C term (requires PID_EXTRUSION_SCALING)

[D<value>]

Derivative value

[E<index>]

Extruder index to set. Default 0.

[I<value>]

Integral value

[L<value>]

Extrusion scaling queue length (requires PID_EXTRUSION_SCALING)

[P<value>]

Proportional value


About the only thing I know for sure is that the extruder index is 0.

What command would I enter to make this a bang-bang PID controller, so that I don't damage my relay long-term?

• I have a Printrboard. Updating the firmware is in fact quite easy, even nowadays. In the time it takes you to adapt M301 you'll already have a new firmware. – FarO Nov 11 '19 at 8:44
• Yea, the Marlin pins.h file for printrboard helped a lot. It was the search engine that was spitting out irrelevant stuff – K Mmmm Nov 11 '19 at 23:38

What command would I enter to make this a bang-bang PID controller

There's no such thing as a "bang-bang PID controller". "bang bang" is mutually exclusive of PID. The M301 command is only good for fine-tuning the parameters of the PID controller, but it won't let you switch to bang bang. Unfortunately, you must update the firmware if you wish to use bang bang.

You could try setting all values to 0, except P, which you set to an as high value as possible. This will cause the output to be fully on when the temperature is lower than the setpoint, and fully off when higher than the setpoint. However, this can still cause rapid clicking of the relay when the temperature is hovering around the setpoint. Bang bang has some hysteresis built-in (i.e., there is a margin around the setpoint in which the relay will never be toggled); there's no way to emulate this with PID.

• There must be a way to make it as close to bang bang as possible – K Mmmm Nov 10 '19 at 17:09
• @steveantwan No, there isn't. To drink red wine from a white wine glass you have to empty the glass first. – Trish Nov 10 '19 at 18:00
• @steveantwan I added something on emulating bang bang with PID. – Tom van der Zanden Nov 10 '19 at 19:47
• Thanks. It is possible to emulate hysteresis as well if you are only trying to heat something. For example: M109 S105; M109 S95; M109 S105; M109 S95 ... (repeated) would keep the heat roughly centered around 100 degrees - it would work well with your suggestion for modifying PID. You'd still get some clicking i think for a few seconds each time during the "watch temp" period............ But i decided to just bend over backwards to flash the arcane firmware to enable bang-bang – K Mmmm Nov 10 '19 at 22:24
• If you use an SSR, you could just use the PID as-is. Other than that, the Printrboard is also just an AVR based board and still supported in Marlin 2.0 as PRINTRBOARD or PRINTRBOARD_REVF – towe Nov 11 '19 at 7:29