Welcome! Log In Create A New Profile

Advanced

Turn on a LED while extruding (only)

Posted by MR_delta 
Turn on a LED while extruding (only)
November 09, 2015 05:22PM
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'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?
Re: Turn on a LED while extruding (only)
November 10, 2015 05:34AM
You would have to place a code like
If( dir== true && step==true) 
    digitalWrite(59, HIGH);
else
    digitalWrite(59, Low);

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.

The example is not real Code, just to show you how-to....
-Olaf
Re: Turn on a LED while extruding (only)
November 10, 2015 07:46AM
I don't know why you need this LED. But since you do, why not implement it directly in the hardware?

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:

Re: Turn on a LED while extruding (only)
November 10, 2015 05:42PM
Thank you for the answers

enifs soulution seems perfekt for a hardware modification but that's above my current skill level.

Olaf, your idea is more what I'm looking for at the moment.
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.

So far I managed to get the LED to light up when extruding and idle, and to shut of when retracting.
I modified this code part in stepper.ccp
Quote

#ifndef ADVANCE
if ((out_bits & (1<<E_AXIS)) != 0) { // -direction
REV_E_DIR();
count_direction[E_AXIS]=-1;
digitalWrite(59, LOW); //------------------------------------ Testing LED here ------------------------------------
}
else { // +direction
NORM_E_DIR();
count_direction[E_AXIS]=1;
digitalWrite(59, HIGH); //------------------------------------ Testing LED here ------------------------------------
}
#endif //!ADVANCE

Now all that remains is to figure out a way to turn of the led when the extruder is idle, any ideas?
Re: Turn on a LED while extruding (only)
November 11, 2015 03:20PM
Solved!

Add this code in Planner.cpp / plan_buffer_line. Above "prevent_dangerous_extrude"

Quote

if (target[E_AXIS]>position[E_AXIS]) //--------------------------------Test LED--------------------------------
{
digitalWrite(59, HIGH);
}
else
{
digitalWrite(59, LOW);
}

#ifdef PREVENT_DANGEROUS_EXTRUDE
Sorry, only registered users may post in this forum.

Click here to login