Welcome! Log In Create A New Profile

Advanced

Use an Opto stop to pause print when filament runs out?

Posted by cfeniak 
Re: Use an Opto stop to pause print when filament runs out?
October 11, 2014 01:05PM
Ok, the changes detailed in my last post did *not* stop the M600 from being called multiple times. I have figured out why it happens, though.

According to the instructions in this topic, the pause() routine which sends the M600 gets called from inside the manage_inactivity() routine, which itself gets called from various places, including loop() and G4. Testing on my printer shows that clicking the switch quickly, open-closed, results in only one M600 being sent. But if the switch is left open, say for the duration of how long it takes to change the filament, then loop() will run several times, each time running manage_inactivity(), each time running pause(), each time sending another M600 to the queue.

To fix this, you need to make the following changes, assuming you've followed the instructions above in setting it up initially. Everything will be in marlin_main.

Near the top, find the Private Variables section.
Add static int pause_switch = 0;

I put mine just after static char *strchr_pointer;

In the void setup_pausepin() routine, add pause_switch = 0; before the #endif

In the manage_inactivity() routine, in the #if defined(PAUSE_PIN) && PAUSE_PIN > -1 section, between pause(); and #endif put in
else
pause_switch = 0;


Finally, change void pause() to

void pause()
{
if (pause_switch == 0) {
enquecommand("M600");
pause_switch = 1;
}
}


This should work to keep the M600 from getting sent multiple times per filament change. If you find any bugs, let us know.

Edit: I just had an unexpected opportunity to test this. My filament snagged in the dry box, which resulted in me cutting off two lengths. Instead of tossing them, I decided to run them through and see how the changes worked. There was no problem. The switch opened when the end of the filament passed it, an M600 was sent, I replaced the filament and pressed the LCD knob. The printer went straight back to printing, no repeated M600 commands. Success!

Edited 1 time(s). Last edit at 10/11/2014 03:58PM by AbuMaia.


MakerFarm 8" Prusa i3v
RAMPS 1.4
0.4mm E3D v6 for 1.75mm
Re: Use an Opto stop to pause print when filament runs out?
October 11, 2014 01:52PM
Hello everyone! I have been following this thread for a bit now, and I think I have a solution....

I too have multiple instances of M600 being executed, and also I was annoyed that it executed even when I wansn't printing, so here is my solution:


in Marlin_main.cpp, right before the end bracket for M600 ( } ) add this:


card.pauseSDPrint();  // inject pause command to prevent further instances of this command!!



now when you click the LCD to return to printing, just scroll down to 'resume'.. I haven't had a problem yet!


Now, since I often change filament before I print, i was tired of switching my machine off to prevent M600 from being executed...

again in Marlin_main.cpp where you defined the PAUSE_PIN.... make it look like this: assuming you have a mechanical switch wired up Normally Closed


#ifdefined(PAUSE_PIN) && (PAUSE_PIN > -1)
  if(card.sdprinting)   // only execute when printing
   {
     if( 0 != READ)PAUSE_PIN) )
      {
        pause();
      }
   }
#endif

and finally following lazzymonk's bool variable up above, my pause function looks like this:

void pause()
{
  #if pauseAdded == false
     enquecommand("M600");
     pauseAdded = true;
 #endif
}

Hope this helps y'all out!
BTW, this is my first post on the RepRap forums, figured it should be helpful and not asking for help!!!


- Ben
Re: Use an Opto stop to pause print when filament runs out?
October 11, 2014 04:00PM
Looks good Ben. Definitely an easier mod than mine. Though I'm curious if there are other commands to pause the print and determine if its printing, that do not rely on the SD. I've just added a Raspberry Pi to my printer running OctoPi, so I don't print from my SD as much anymore. I wonder if those commands would still work even if the print isn't running from the SD?


MakerFarm 8" Prusa i3v
RAMPS 1.4
0.4mm E3D v6 for 1.75mm
Re: Use an Opto stop to pause print when filament runs out?
October 11, 2014 08:11PM
I have never printed directly from a computer. When I use OctoPrint I always send the gcode to SD card. But I would imagine the commands would work as is. Maybe try this in the pause function:


void pause()
{
  #if pauseAdded == false
     enquecommand("M600");
     pauseAdded = true;
     enquecommand("M24");  // add this to automatically resume (untested)
 #endif
}
Edit: this is kind of a dirty way of doing it, but if it works there's no reason to change it. I'll try when I get back to my printer tomorrow.

Edited 2 time(s). Last edit at 10/11/2014 08:35PM by benkilar.
Re: Use an Opto stop to pause print when filament runs out?
October 12, 2014 10:15AM
I don't think you want to add the resume immediately after the M600, you wouldn't get a chance to change the filament.


MakerFarm 8" Prusa i3v
RAMPS 1.4
0.4mm E3D v6 for 1.75mm
Re: Use an Opto stop to pause print when filament runs out?
October 12, 2014 02:56PM
Not necessarily.. M600 has that whale loop waiting for the LCD to be pressed

while(!lcd_clicked()){
...................

this prevents anything from happening until you press the LCD button, so worst case scenario, the M24 would do nothing.
Re: Use an Opto stop to pause print when filament runs out?
October 13, 2014 03:27AM
Instead of an optical sensor. You should use a endstop, the type that comes with a small roller. Then make a housing for it.

While there is filament inside the housing. The endstop is in closed position.
And after making sure filament comes off of the spool when empty. It will roll through and cause the switch to open.

Causing the printer to
Move to x0 y0 and not z0
Pause print
Rectract out of hotend.
Cool hotend
Keep heatbed on.

And send a message to your phone to change filament.
Also beep and display on screen
Re: Use an Opto stop to pause print when filament runs out?
October 13, 2014 11:58AM
That's exactly what I do, pushthatbolder, except for messaging the phone. I use this switch holder [www.thingiverse.com].


MakerFarm 8" Prusa i3v
RAMPS 1.4
0.4mm E3D v6 for 1.75mm
Re: Use an Opto stop to pause print when filament runs out?
January 06, 2015 04:39AM
Sorry to bring this thread back up, but i tried Abumaia's method, and it works for the most part.
The problem i'm having is that it pauses 2 times in a row, now i did make the adjustments he stated in the last post which should solve the m600 command to be sent multiple times.
But it still pauses 2 times in a row, is there any other way around this?

Thanks in advance smiling smiley
Re: Use an Opto stop to pause print when filament runs out?
February 25, 2015 08:52AM
Same problem as Napalm.

A few notes:

1. When engaging the switch, M600 runs two times (as mentioned). Then i tried it again and it ran 3 times, then 4 times. It seems like it won't run more than 4 times. Note this happens when the printer is actually printing something.

2. When printing from a host I can send M600 and it will only run once as expected.

3. After the filament change has run the "Filament Change" message stays on the screen.

4. If I engage the switch when the printer is not printing, it will only run once. (I didn't put in the code to prevent this since I'm testing).

It seems like it has something to do with the loop for an active print.

I tried all the suggestions so far and I'm still working on it.


Edit:

After a lot of testing and changes I found this:

If I put two of the G4 commands before the M600 it seems to work but this is the resulting commands as seen by the pronterface debug mode:

RECV: echo:enqueing "G4 P0"
RECV: echo:enqueing "G4 P0"
RECV: echo:enqueing "M600"
RECV: ok
RECV: echo:enqueing "G4 P0"
RECV: echo:enqueing "G4 P0"
RECV: ok
RECV: echo:enqueing "G4 P0"
RECV: echo: cold extrusion prevented
RECV: echo: cold extrusion prevented
SENT: M105
RECV: echo: cold extrusion prevented

*I clicked the LCD screen here*

RECV: ok
RECV: ok
RECV: ok
RECV: ok

So it's continuing to send a lot of commands but at least it's only one M600 command.

The interesting thing is if I don't engage the switch after the filament change command runs (meaning i just click the LCD screen but didn't put in filament), the printer continues to send G4 commands as fast as possible until i click the switch which sends a new M600 command.

Edited 2 time(s). Last edit at 02/25/2015 08:50PM by gordo3di.
Re: Use an Opto stop to pause print when filament runs out?
April 09, 2015 03:01AM
I use the Roomba. I want to use Pin A10 it has code 87. How to register this pin to be able to use it

Edited 4 time(s). Last edit at 04/09/2015 03:33AM by mrSEADEMON.
Re: Use an Opto stop to pause print when filament runs out?
November 02, 2022 05:49PM
I'm getting:

'setup_pausepin' was not declared in this scope

why?
Sorry, only registered users may post in this forum.

Click here to login