How to configure Marlin to enable auto-fans with dual extruder
I have successfully assembled my custom-built 3D printer and configured Marlin for two extruders and one heated bed. Here is a picture of the printer.
My heated bed runs on a linear axis with ball bearings. When the printer has been running for an hour or so these parts get really hot and I am afraid that the plastic parts will melt if I print any longer or with higher temperatures. So I decided to add fans below the heated bed to keep them cool.
A known problem when using two extruders and a heated bed is, that all three power outputs D8, D9, D10 are in use (in my setup D8 belongs to the first extruder, D9 to the bed, and D10 to the second extruder). If you want to have software-controlled fans on top of that, you need to use a workaround. I bought the RRD fan extender which does exactly what I need. You plug it into the RAMPS 1.4 board and get two new outputs D6 and D11.
Currently I have configured the firmware as follows:
#define E0_AUTO_FAN_PIN 11
#define E1_AUTO_FAN_PIN 6This automatically enables the fan of the left extruder E0 when its hotend exceeds 50 °C. The same goes for the right extruder E1. The fans are plugged into the fan extender's outputs D6 and D11. It all works fine.
Now to add fans to the heated bed, I have modified the firmware so that D11 controls both extruder fans. As long as at least one extruder is hot, both fans are running. For that purpose, I connected both extruder fans in parallel to D11 and modified the firmware as follows:
#define E0_AUTO_FAN_PIN 11
#define E1_AUTO_FAN_PIN 11That part works fine and was quite easy to achieve. What I would like to do next is connect the other pin, D6, to the temperature sensor of the heated bed, so that the fans underneath the bed become active when the bed is at 50 °C or more.
I made several attempts to trick the firmware into believing that there are three hotends, registering the heated bed as E2.
#define E2_AUTO_FAN_PIN 6
I manually defined the temperature sensor of the bed for E2 and commented out some sanity checks and conditionals to enable some parts of the firmware that control the auto-fans. While I get the code to compile, the printer usually halts immediately after it is turned on or as soon as an extruder or the bed is activated. The error messages are not very helpful ("killed, please restart" etc).
Does anybody know a good way how to achieve my goal? Any help would be appreciated. Thank you in advance.
After trying many different things, I found out that the solution is really simple and requires only a few lines of code. I'll answer my own question in the hope that this will help someone.
First, I defined a few constants (macros actually). To keep my own stuff separate, I created a new file for them called myconfig.h:
#define MY_BED_TEMP_THRESHOLD 50
#define MY_BED_AUTO_FAN_PIN 6
#define MY_BED_AUTO_FAN_SPEED 255The pin constant corresponds to D6 which is the green marked output of the RRD Fan Extender where I connected the fans under my bed.
Second, in the file temperature.cpp of the Marlin Firmware, I included my file and added four lines of code:
#include "myconfig.h"
...
#if HAS_AUTO_FAN
void Temperature::checkExtruderAutoFans() {
...
HOTEND_LOOP() {
if (current_temperature[e] > EXTRUDER_AUTO_FAN_TEMPERATURE)
SBI(fanState, fanBit[e]);
}
// --- start of my code ----------
if (current_temperature_bed > MY_BED_TEMP_THRESHOLD)
digitalWrite(MY_BED_AUTO_FAN_PIN, MY_BED_AUTO_FAN_SPEED);
else
digitalWrite(MY_BED_AUTO_FAN_PIN, 0);
// --- end of my code ------------
...
#endif // HAS_AUTO_FAN
...Now my fans are automatically turned on while the bed temperature is higher than 50 °C and are turned off again after the bed has cooled down far enough.
License under CC-BY-SA with attribution
Content dated before 7/24/2021 11:53 AM