<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel>
        <title>Turn on a LED while extruding (only)</title>
        <description> Hello,

I have tried to figure out how to turn on a LED when the printer is extrudig filament, but only when its extruding forward.

I&#039;m using Marlin and tried to add a command to light the LED at various places in the code but all I have managed so far is to get it permanently lit or to flicker for a short while.

I dont want to modify the G-codes sent to the priner, or add new ones.

I use this to light/shut of the LED
digitalWrite(59, HIGH);
digitalWrite(59, LOW);

Any ideas how to do this?</description>
        <link>https://reprap.org/forum/read.php?219,582334,582334#msg-582334</link>
        <lastBuildDate>Sun, 13 Sep 2026 19:21:27 -0400</lastBuildDate>
        <generator>Phorum 5.2.23</generator>
        <item>
            <guid>https://reprap.org/forum/read.php?219,582334,583201#msg-583201</guid>
            <title>Re: Turn on a LED while extruding (only)</title>
            <link>https://reprap.org/forum/read.php?219,582334,583201#msg-583201</link>
            <description><![CDATA[ Solved!<br />
<br />
Add this code in Planner.cpp / plan_buffer_line. Above "prevent_dangerous_extrude"<br />
<br />
<blockquote class="bbcode"><div><small>Quote<br /></small><strong></strong><br />
  if (target[E_AXIS]&gt;position[E_AXIS])  //--------------------------------Test LED--------------------------------<br />
    {<br />
      digitalWrite(59, HIGH);<br />
    }<br />
    else<br />
    {<br />
      digitalWrite(59, LOW);<br />
    }<br />
<br />
  #ifdef PREVENT_DANGEROUS_EXTRUDE</div></blockquote>]]></description>
            <dc:creator>MR_delta</dc:creator>
            <category>RAMPS Electronics</category>
            <pubDate>Wed, 11 Nov 2015 15:20:59 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?219,582334,582854#msg-582854</guid>
            <title>Re: Turn on a LED while extruding (only)</title>
            <link>https://reprap.org/forum/read.php?219,582334,582854#msg-582854</link>
            <description><![CDATA[ Thank you for the answers<br />
<br />
enifs soulution seems perfekt for a hardware modification but that's above my current skill level.<br />
<br />
Olaf, your idea is more what I'm looking for at the moment.<br />
I tried variations of your code in the loop() area of Marlin_main but that did not work because it seems it's only called when the printer is idle.<br />
<br />
So far I managed to get the LED to light up when extruding and idle, and to shut of when retracting.<br />
I modified this code part in stepper.ccp<br />
<blockquote class="bbcode"><div><small>Quote<br /></small><strong></strong><br />
#ifndef ADVANCE<br />
      if ((out_bits &amp; (1&lt;&lt;E_AXIS)) != 0) {  // -direction<br />
        REV_E_DIR();<br />
        count_direction[E_AXIS]=-1;<br />
        digitalWrite(59, LOW);                                                                                    //------------------------------------ Testing LED here ------------------------------------ <br />
      }<br />
      else { // +direction<br />
        NORM_E_DIR();<br />
        count_direction[E_AXIS]=1;<br />
        digitalWrite(59, HIGH);                                                                                    //------------------------------------ Testing LED here ------------------------------------ <br />
       }<br />
    #endif //!ADVANCE</div></blockquote>
<br />
Now all that remains is to figure out a way to turn of the led when the extruder is idle, any ideas?]]></description>
            <dc:creator>MR_delta</dc:creator>
            <category>RAMPS Electronics</category>
            <pubDate>Tue, 10 Nov 2015 17:42:29 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?219,582334,582578#msg-582578</guid>
            <title>Re: Turn on a LED while extruding (only)</title>
            <link>https://reprap.org/forum/read.php?219,582334,582578#msg-582578</link>
            <description><![CDATA[ I don't know why you need this LED.  But since you do, why not implement it directly in the hardware? <br />
<br />
E.g. with a ATtiny85 that reads the extruder's DIR and STEP signals and switches the LED accordingly.  This way, you would not have to modify the firmware again whenever you need a firmware upgrade.  Also, this would even allow you to count the forward and backward steps, so that the LED would only light when it's actually pushing the filament, but not when it's "undoing" the preceding retract.  The extruder's DIR and STEP signals are just across from the + and - of the I2C connector, so the needed power and signal lines (GND, 5V, DIR, STEP) that are needed by the ATtiny  could be easily connected to:<br />
<br />
<a href="http://forums.reprap.org/file.php?219,file=65685,filename=Ramps-EDIR-ESTEP.jpg" target="_blank"  rel="nofollow"><img src="http://forums.reprap.org/file.php?219,file=65686,filename=Ramps-EDIR-ESTEP-small.jpg" class="bbcode" border="0" /></a>]]></description>
            <dc:creator>enif</dc:creator>
            <category>RAMPS Electronics</category>
            <pubDate>Tue, 10 Nov 2015 07:46:36 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?219,582334,582503#msg-582503</guid>
            <title>Re: Turn on a LED while extruding (only)</title>
            <link>https://reprap.org/forum/read.php?219,582334,582503#msg-582503</link>
            <description><![CDATA[ You would have to place a code like<br />
<pre class="bbcode">
If( dir== true &amp;&amp; step==true) 
    digitalWrite(59, HIGH);
else
    digitalWrite(59, Low);</pre>
<br />
The LED would still flicker with very high step-frequency, but it would only be lit when the dir pin is indicating the right direction.<br />
<br />
The example is not real Code, just to show you how-to....<br />
-Olaf]]></description>
            <dc:creator>o_lampe</dc:creator>
            <category>RAMPS Electronics</category>
            <pubDate>Tue, 10 Nov 2015 05:34:08 -0500</pubDate>
        </item>
        <item>
            <guid>https://reprap.org/forum/read.php?219,582334,582334#msg-582334</guid>
            <title>Turn on a LED while extruding (only)</title>
            <link>https://reprap.org/forum/read.php?219,582334,582334#msg-582334</link>
            <description><![CDATA[ Hello,<br />
<br />
I have tried to figure out how to turn on a LED when the printer is extrudig filament, but only when its extruding forward.<br />
<br />
I'm using Marlin and tried to add a command to light the LED at various places in the code but all I have managed so far is to get it permanently lit or to flicker for a short while.<br />
<br />
I dont want to modify the G-codes sent to the priner, or add new ones.<br />
<br />
I use this to light/shut of the LED<br />
digitalWrite(59, HIGH);<br />
digitalWrite(59, LOW);<br />
<br />
Any ideas how to do this?]]></description>
            <dc:creator>MR_delta</dc:creator>
            <category>RAMPS Electronics</category>
            <pubDate>Mon, 09 Nov 2015 17:22:26 -0500</pubDate>
        </item>
    </channel>
</rss>
