Notifications
Clear all

Getting the loaded filament type somehow  

  RSS
Schorsch3000
(@schorsch3000)
Active Member
Getting the loaded filament type somehow

So,

i'm planing a whole automated electric setup for my enclosure.

There will be a raspberry pi, an Arduino as an io extender, dimmable led lights, a fan sitting in the cutout in the back, and a fan circulating air within the enclosure, temperature sensors for the outside and inside temperature and door-closed sensors.

ther Pi will be connectet via usb to the MK4 and also reads infrmation from its webinterface.

I want to have filament-specific modes, eg: setting a regulated temperature within the enclosure while printing, 5°C above outside for pla, 40°C for ABS.

 

Is there any way to get the type of the loaded fillament from the printer?

My current workaround is to download the current gcode file when a new print starts and searching for 

; filament_type = XYZ

but that feels so wrong.

 

 

PS: since i know someone will ask what the circulating fann will ne used for:

for materials that like to be printed in warmer environments, the fan will be on while the bed heats up before print, so the air inside will be slighty warmer.

After a print, both fans will spin up to cool everything down fast. one pushes warm air out, the other forces air onto the hotend and bed.

 

 

 

 

 

Posted : 22/09/2023 3:03 pm
ScottW
(@scottw)
Reputable Member
RE: Getting the loaded filament type somehow

I am using Octoprint to control an exhaust fan in a manner similar to what you plan.  You mentioned a pi as part of your setup but did not say whether you intend to use Octoprint.  In any case, I'll describe my setup -- it may give you some ideas even if you aren't using Octoprint.

I have a bash script on the pi named "fanCtrl" which reads the enclosure temperature (from DS18B20), accepts various parameters, and controls the fan accordingly (on/off relay on GPIO, hardware PWM for Noctua fan).  For example, parameters of "Maxtemp 35" would instruct it to adjust the fan speed to maintain 35C or less; and the parameter "cooldown 28" sets the fan at 100% until 28C is reached (or 20 minutes has passed) to cool down the enclosure after a print.  

I use the Octoprint plugin "Gcode Commands" to call the script.  That plugin lets you define arbitrary Gcodes (OCTOxx) which call a system command when processed.  Those commands can be introduced into the print stream from your Slicer's Gcode Scripts, or from a custom UI button in Octoprint, or from the Gcode Scripts within Octoprint.  I defined an "OCTO10" Gcode, which executes the following:

/bin/bash /home/pi/.octoprint/scripts/fanCtrl $OCTOPRINT_GCODESYSTEMCOMMAND_ARGS

Finally, I added the following jinja2 code to Octoprint's "Before Print Job Starts" Gcode Script.  This leverages the embedded "filament type" PrusaSlicer adds to the Gcode filename to choose a target temperature for that print:

{% if ('_PLA_' in event.name) or 
      ('_PVA_' in event.name) or
      ('_PVB_' in event.name) %}
OCTO10 maxtemp 30 ; PLA, PVA, PVB
{% elif ('_PA_' in event.name) or
        ('_PETG_' in event.name) or
        ('_FLEX_' in event.name) %}
OCTO10 maxtemp 35 ; PA,PETG,FLEX
{% elif ('_ABS_' in event.name) or
        ('_ASA_' in event.name) %}
OCTO10 maxtemp 40 ; ABS, ASA (max 40c for buddyboard in enclosure)
{% else %}
OCTO10 maxtemp 35 ; unknown type, default 35C
{% endif %}

I also added the "OCTO10 cooldown 28" command in Octoprint's "After Print Job Completes" and "After Print Job is Cancelled" scripts.

So, the normal workflow is like this: 

  1. I slice in PrusaSlicer and upload to Octoprint (PrusaSlicer embeds filament type in filename), 
  2. The jinja2 code in Octoprint's "Before Print Starts" script runs, interrogates the filename to find filament type, and introduces an "OCTO10" into the print stream with parameters of "maxtemp" and the desired temp for that filament,
  3. The Gcode Command plugin sees the OCTO10 command, calls the bash script and passes the parameters to it,
  4. The bash script iteratively checks the enclosure temp (DS18B20), and controls the fan as needed during the print,
  5. When the print completes, Octoprint's "After Print Job is Complete" script runs, which introduces the "OCTO10 cooldown 28" to the print stream,
  6. The Gcode Command plugin sees the "OCTO10 cooldown 28" command and calls the bash script with those parameters,
  7. The bash script sets the fan to 100% until 28C is achieved (or 20 minutes has elapsed), then turns the fan off.

 

I also added UI buttons to Octoprint's UI (this can be done via the Octoprint config.yaml file) so I have buttons to manually set various modes as well.  But primarily, I now just "slice and print" -- and the scripting takes care of everything automatically.

LED Lighting is also controlled via Octoprint, using a smart plug and another Octoprint plugin -- but that's a manual process using a UI button in Octoprint.

Hope that gives you some ideas.

Posted : 23/09/2023 5:44 pm
Schorsch3000
(@schorsch3000)
Active Member
Topic starter answered:
RE: Getting the loaded filament type somehow

hey scottw, 

thank you very much for your replay.

i think i'm going without octoprint here.

Nothing against octoprint, i've used it for years with my anet a8.

I used it with cura and set cura and octoprint up to pretend my printer knows how to handle encloser temperature (M141 and M191)

I than used a small self written octoprint plugin that gets the line of gcode just befor sending it to the printer, watching for M141 and M191 and reporting saied temperature to an arduino that did control a fan using PWM / PID.

I just used the arduino here so that E between the printer and the enclosure was easy. the pi was attached to the printer.

The Printer cound be removed hust by detaching 2 usb (arduino and cam) and 1 xt60 connector for power.

i did think about using the material-type within the name, but sometimes the filename is to long to work with prusalink and than i need to shorten the name by hand, and that is something that will break 😀

Thanks!

Posted : 23/09/2023 7:00 pm
Fil4ment
(@fil4ment)
Trusted Member
RE: Getting the loaded filament type somehow

I'm trying to poke at the developers, to give me GPIO pin numbers, so I can write M42 and M226 G-codes into the filament-specific "End G-code", to do basically what you're wanting.

https://forum.prusa3d.com/forum/postid/663473/

Sadly, it seems that the devs are a bit overwhelmed, right now, and aren't wanting to help. I know there are GPIO pins available, I just don't know which physical pins go to which pin number. If anyone can come up with that, then we can both carry on with our projects, and get a standalone (non-octoprint) enclosure control system.

Posted : 24/09/2023 4:11 pm
Schorsch3000
(@schorsch3000)
Active Member
Topic starter answered:
RE: Getting the loaded filament type somehow

oh i'm fine with managing things by myself. i'm going to have a somewhat special setup there.
all i need it to know what filament is loaded, the printer knows, its right there down in the footer 🙂

Posted : 24/09/2023 6:15 pm
Fil4ment
(@fil4ment)
Trusted Member
RE: Getting the loaded filament type somehow

using an M42 to drive a GPIO pin would do, would it not? It would be driven by the filament profile in the slicer, but the printer barks at you if there's a difference between the sliced material and the loaded material, so it really should be the same thing.

Posted : 24/09/2023 7:07 pm
Share: