PIDYou might have noticed that your Prusa i3 Hepheseto printer does not stay at the desired temperature and varies constantly. The exterior temperature may also effect your printer. If you have moved your printer from its usual place or if there’s a current of air, this can make the temperature oscillate constantly and not remain at the desired temperature. This happens because the mechanism in charge of heating the hot-end is not adjusted. This has a very simple solution and is done by typing in the correct PID values. To understand this process, we need to know what a PID is exactly.

Graph showing a (varying from the desired temperature) unadjusted PID and an adjusted PID (a lot more close to the desired temperature)

Graph showing a (varying from the desired temperature) unadjusted PID and an adjusted PID (a lot closer to the desired temperature)

What’s a PID?

The PID (proportional-integral-derivative) is a control mechanism through feedback that calculates the deviation or the error between the current temperature and a desired value. We try to adjust the output signal so that the whole process can apply equal measurement values. When we receive the measurement error, through its three constants (Kp, Ki, Kd) the PID makes the corresponding adjustments. In the case of a 3D printer, its heating process is carried out by this process. We indicate that we wish to obtain a temperature of 210ºC, but the hotend has a different temperature, we subtract the desired temperature from the real one and so obtain the error value. The error is applied to the PID process indicating to the heater how much it should heat up. This process is constant and this loop is being performed at all times to obtain the correct temperature. What if the PID is not adjusted? We would have a constant oscillation of the temperature. Why? Let’s say that the temperature is close to the desired level, but if the PID is not correct, it will apply too much charge to the heater and will exceed the desired temperature, and it can stay like this for a good while before starting to print. If the PID is correctly adjusted the oscillation will be reduced or completely eliminated, helping the hotend to heat up quicker.

Block diagram of a PID control (source: Wikipedia)

Block diagram of a PID control (source: Wikipedia)

We need to take into account that if you are printing in another room or have a window open, this may effect the hotend’s heating process and therefore the adjusted PID may not be totally accurate for the circumstances. The PID’s firmware was calculated with specific conditions that can be different to the ones you might have when printing. So if you notice that the temperature is oscillating constantly or if it takes a long time to reach the desired temperature when starting to print, you should adjust the PID.

How to adjust the PID

To adjust the PID, you need to be connected to the printer via a USB cable and use a program that allows you to send commands to the printer. Cura allows you to do this perfectly. To do this, the first thing you would need to activate is the interface to be able to control the printer via USB. Go to “File” -> “Preferences” and click on the “Print window” tab. To be able to connect with your computer you need to select the series port found in “Machine settings”. To connect, add an object to the base and click on the print icon. You will see the following screenshot.

Pronterface

Pronterface

We are now connected with the printer. If you wish to make sure, press the home button of any axis and watch as the corresponding motor moves. To adjust the PID, there is an autotune option that has been created in the firmware, we can say that this firmware is going to give you the correct values of Kp, Ki, Kd that you need. Keep in mind that the temperature of the hotend is recommended to be at room temperature when carrying out the autotune. To start the autotune of the PID, you need to send the command M303 S210. In this case “S210″ indicates the temperature at which you would normally print (210ºC for example).
Once you’ve sent the command you will see how the temperature starts to rise, and after a while, drop. This will happen a few times. When the process finalizes, it will give you the Kp, Ki and Kd values. In the following picture, you can see the values I obtained during the test.

Finished autotune and variable values

Finished autotune and variable values

Now we need to tell the computer to use these values instead of the ones in the firmware. You have two ways of doing this: indicating it at the beginning of each Gcode or modifying the firmware. If you wish to indicate it at the beginning of each Gcode, you need to go to the “start.gcode” in Cura and type in front of the M303 command the values given by the autotune. In this case, we would need to place M301 P14.82 I0.8 D68.25 (note that capital letters must stay the same). Keep in mind that to have this PID you need to place it in all of the Gcodes. This process is a good way of checking if the PID is correct before modifying the firmware.

On the other hand, if you wish to directly add the values to the firmware, you would need to download the firmware from the following link. You will need to modify the “configuration.h” file and look for the “PIDTEMP” section and variable values “DEFAULT_Kp”, “DEFAULT_Ki” and “DEFAULT_Kd”. Modify the values obtained by autotune and place them in the variables.

Modifications to the firmware values

Modifications to the firmware values

Once correctly saved you would need to load the code. You can do this from the Arduino IDE. To do this open the “marlin.ino” file with the program. Select the correct controller card (in this case “Arduino Mega 2560″) and the correct series port where the electronic device is connected. Lastly, press on the right arrow icon to load the code. This way you will have the modified firmware loaded.

You will now have your PID adjusted correctly to your conditions and not oscillating constantly when heating up. You can repeat this process all the times you want until it works correctly.

Ruben Sierra (@sgruben in Twitter) is an industrial engineer technician, specialising in Industrial Electronics. He is a maker and is passionate about programing, robotics, and 3D printing. He currently works in 3D tech support at BQ.