Welcome! Log In Create A New Profile

Advanced

Set GPIO pin state based on hotend temperature

Posted by convoluted 
Set GPIO pin state based on hotend temperature
May 09, 2019 05:08AM
Hi all. I'm looking for a way to set the state of a GPIO pin based on the hotend temperature (e.g., GPIO set high when above a temperature threshold, and low otherwise). The plan is to use the GPIO as an input to a custom-built fume extraction fan controller. I plan on hijacking an unused pin on my board (Lulzbot Mini with RAMBo and single extruder).

I've been looking through the source code (Marlin 2.0.0.110) and I don't have a good sense where I could insert a GPIO state change. There's a lot going on in there. Initially I was looking at using getActualTemp_celsius().

Could you please help me determine the appropriate place to insert the code? Note: I'm also open to other suggestions than using a GPIO pin. My fan controller can utilize UART, SPI, I2C, etc. Maybe there's something that Marlin is already sending out that I could intercept?

Thanks!
Re: Set GPIO pin state based on hotend temperature
May 09, 2019 08:55AM
its already there...

take a look in configuration_adv.h

/**
 * Extruder cooling fans
 *
 * Extruder auto fans automatically turn on when their extruders'
 * temperatures go above EXTRUDER_AUTO_FAN_TEMPERATURE.
 *
 * Your board's pins file specifies the recommended pins. Override those here
 * or set to -1 to disable completely.
 *
 * Multiple extruders can be assigned to the same pin in which case
 * the fan will turn on when any selected extruder is above the threshold.
 */
#define E0_AUTO_FAN_PIN -1
#define E1_AUTO_FAN_PIN -1
#define E2_AUTO_FAN_PIN -1
#define E3_AUTO_FAN_PIN -1
#define E4_AUTO_FAN_PIN -1
#define E5_AUTO_FAN_PIN -1
#define CHAMBER_AUTO_FAN_PIN -1
#define EXTRUDER_AUTO_FAN_TEMPERATURE 50
#define EXTRUDER_AUTO_FAN_SPEED 255   // 255 == full speed

set one of these to an unused pin and set a temp and that pin will change state at that temp
Re: Set GPIO pin state based on hotend temperature
May 10, 2019 01:11AM
Thanks. I couldn't get it to work that way, so instead I modified a function in temperature.h. Probably not the best location to inject code, but seems to work. Here's the modified function to hijack PH1 on RAMBo:

    FORCE_INLINE static float degHotend(const uint8_t e) {
      E_UNUSED();
      // Custom firmware for fume extraction and lighting system
      if (temp_hotend[HOTEND_INDEX].current >= 35) {
        PORTH |= (1 << 1); // turn on system
      } else {
        PORTH &= ~(1 << 1); // turn off system
      }
      return temp_hotend[HOTEND_INDEX].current;
    }

For some reason the compiler is complaining about "PORTH1" (PH1), so instead I just used the decimal equivalent.
Re: Set GPIO pin state based on hotend temperature
May 11, 2019 04:27AM
There is the TEMP_STAT_LEDS built-in option if you wanted.
Sorry, only registered users may post in this forum.

Click here to login