Projects

End Of Line

3D Printer Filament Outage Detector

Oliver Higgins

Issue 14, August 2018

This article includes additional downloadable resources.
Please log in to access.

Log in

Running out of printer filament can lead to disaster, but with our simple filament detector failed prints are a thing of the past.

BUILD TIME: 60 MINUTES
DIFFICULTY RATING: Intermediate

We have all been there. Your object is missing the final few layers because your printer ran out of filament 19 hours into a 20 hour print. You thought you had enough filament, and told yourself to check in on the print when you thought it was close to being finished, but you forgot. What if there was an easy way to avoid this annoying and costly occurrence.

THE BROAD OVERVIEW

This project will save you having to supervise the print job to ensure it doesn’t run short of filament. Instead, it will pause the job until you are able to add more filament. Once you refill the filament, you simply press resume. You can also set it up to turn the heat bed and tool off once the job pauses.

You can also add a USB camera or RPi camera you can stream the vision to your computer. This means you can monitor your job from another room without having to constantly check on the print.

HOW IT WORKS

Our simple solution uses a Raspberry Pi and a handful of parts, including a microswitch that becomes our filament outage sensor. A 3D printed housing for either 1.75 or 2.85/3mm filament is required, along with a 3D printed bracket that mounts to the filament spool holder.

As you print, filament travels through the switch housing, holding the switch closed. Once the filament runs out the switch opens, triggering the RPi running OctoPi. This pauses the print, and turns off the heatbed and tool.

ABOUT OCTOPI

OctoPi is an open source RPi based implementation of the OctoPrint 3D Print server environment. It offers full and remote monitoring of every aspect of 3D printing. It provides considerable extensibility well beyond this article through its plugin system, and best of all it’s 100% open source. The degree of detail that it offers is unparalleled and can be set up in just a matter of minutes.

connection

Build 1:

The OctoPrint Server

3D Printed Case

Here at the DIYODE workshop, we use the LulzBot Taz and Mini. As such this article uses some resources specific to these printers, however, there are many cases available for Raspberry Pi’s available at Thingiverse for other printers.

If you're printing at home, you will need to 3D print the following:

  1. RPi Case Top & Bottom
  2. RPi Camera Module (If using the RPi Camera Module)
camera
Parts Required: JaycarAltronicsCore Electronics
1 × Raspberry PiXC9000Z6302BCEO5436
3D Printed Enclosure--Special Order

Parts Required:

OPTIONAL:JaycarAltronicsCore Electronics
1 × Raspberry Pi Camera XC9020Z6305ACEO4421
3D Printed Camera Enclosure--Special Order

OPTIONAL:

THE OCTOPI SOFTWARE

Setting up OctoPi is quite straightforward, however, if you have not installed or set up an RPi before we would recommend you check out and install NOOBS. To make the system run as efficiently as possible the Operating System is installed without a desktop environment. You will need to be comfortable executing some commands at the command line. You will also need to edit one text file.

Download the latest version of OctoPi from: https://octopi.octoprint.org/

Next, prepare the SD card and upload the image.

FOR WINDOWS USERS: Win32 Disk Imager: https://sourceforge.net/projects/win32diskimager/

FOR MAC USERS: We recommend using Etcher: https://etcher.io/

If you are using WiFi to connect you will need to setup the SSID and passwords. Once you have imaged your SD card, navigate to the card in your operating system and locate the “octopi-network.txt” file located in the SD card’s root directory. If you plan to use Ethernet you can skip this step.

##WPA/WPA2 secured
#iface wlan0 inte manual
#wpa-ssid "put SSID here"
#spa-psk "put password here"

and change this to:

##WPA/WPA2 secured
iface wlan0 inte manual
wpa-ssid "AWESOME_NETWORK"
spa-psk "1231456123456»

A couple of things to note. Make sure you are using text editing software, not a word processor or rich text editor. On Windows, we would recommend Notepad++ or notepad. On Mac, Atom or BBEdit. (TextEdit on Mac is known to put strange characters in for “” and as such is not recommended in this case). Secondly, please note that most routers by default will have the 2.4GHz channel set to auto with 1-13 being available for use. There are documented issues with the RPi not working with 12 or 13. If you have manually changed the channel on your router, you will need to make sure it is not 12 or 13.

BOOT IT & LOGIN

Eject the SD card from your computer and insert into the RPi. Connect a keyboard and screen, connect the power supply and boot.

Once the system has booted log into your RPi. We need to do this via SSH. If you have not done this before it is simply logging into the remote computer and running a sequence of commands. You will need to do this on more than one occasion for this article, so we need to ensure that we have an understanding of how to access it. If you are using a POSIX style OS such as Linux or OSX, open up a terminal session and log in using the below code:

ssh pi@10.0.0.25
pi@10.0.0.25’s password:

Likewise, on Windows, the easiest way is to use PuTTY using the same settings.

Once you have logged in, use the following command:

sudo raspi-config

If you are using the RPi camera, select option 5 and the option P1, then enable. On a personal note, we also like to enable SSH here (option P2). When finished, select Finish then reboot.

CONFIGURATION

Connect to the RPi via a browser and connect to octopi.local or the IP address that is listed on boot.

Once you are connected to the RPi, you will be greeted by the “Configure Access Control” page. Enter a username and password and then select the “Keep Access Control Enabled” button on the bottom right.

Next is the printer setup screen. If you are familiar with Cura, then the setup question will be of no surprise to you as the Cura engine comes with OctoPi. If not, you will need to know the following as a minimum;

  • Name
  • Model
  • Bed shape (Rectangular or circular)
  • Origin point
  • Volume (Print bed dimensions)
  • Is the bed heated?
  • Nozzle diameter
  • Number of Extruders

Finally, select the auto connect at login. You now have a wireless print server for your 3D printer!

CAMERA CONNECTION

If you have not connected your RPi camera module or USB webcam, connect it and you will have a live stream on the control tab. The default RPi camera cable is quite short, so we would recommend getting a longer one with 100, 200 & 300mm being available.

tablet

UPLOAD & PRINT

With OctoPrint installed we can now upload and print. Make sure you have a GCODE file ready to go and head over to http://octopi.local or http://10.x.x.x (or the IP used earlier). When we first go to the landing page, we are able to view the current status of the printer. To start the printer (assuming it is connected and turned on) we must log in using previously set log in details and connect to the printer (assuming you did not click select auto print).

The upper left corner contains the printer control area. Once logged in we are able to connect to the printer. It will take a few moments to establish a connection and communicate with your printer. While this happens, go to files located at the bottom right of the screen. Click on Upload and locate the GCODE file that you have generated. It will appear on your list once the upload is complete. Click the print button, and provided the printer is connected the system will start. If you have connected and enabled the RPi camera click on the CONTROL tab and we will get a live stream of your print. Clicking on the GCODE tab will show the current GCODE output and a visual representation of where the print is at. The TERMINAL tab will give the current GCODE code that is being executed.

Now that the OctoPrint has been installed and configured, we can move on to our filament sensor detector.

filament sensor

Build 2:

Filament Sensor Detector

3D Printed Case

We have supplied two basic housing units for the standard microswitch to accommodate 1.75mm and 2.85/3mm filament. One of the issues we face is that all printers are quite different, so you may need to supply some ingenuity in regards to developing something that will work for your particular printer. Our particular printer has the spool located over the top of the printer’s chassis, with minimal clearance to the hot end when parked, so we elected to create a device that was based upon the spool itself. This may suit if you have a spool inner diameter of approximately 50mm. This design works and has been tested, however it does create some pull on the filament due to sitting off-centre. Ideally, it would sit further out and flow better. The housing also has enough space to place some plastic tubing leading up and away from it. If we do choose to do this, we need to trim the metal part of the switch. Otherwise, there are many different options around for different printers. Providing it is a “switch” based input then it will still work with OctoPrint using the method described.

3d print 3
Parts Required:JaycarAltronicsCore Electronics
1 × MicroswitchSM1038S3265POLOLU-1403
2 × 0.1" (2.53mm) Crimp Connectors---
Hook-up WireWH3011W2251PRT-08867
3D Printed Enclosure--Special Order

Parts Required:

BUILDING THE SENSOR

This may possibly be the smallest build we have ever put together in DIYODE. Our entire circuit is one switch! Well, we do have two crimp connectors to make it easy to attach to. Before we get to the build, make sure you have printed your switch casing. You may even find that printing the basic housing on its own, and testing the system, a simpler way to get up and running. The microswitch and the housing have 2.5mm mounting holes as standard. For this project, we used a 3mm drill to widen up the switch’s holes as to easily fit the more common size. Repeat for the casing as required.

With the casing and switch in place, we need to solder on some wires to connect to our RPi. You will need about 1m, but please do check where you intend to mount the sensor and cut to length accordingly. Bare the ends of the wire and solder to the middle and rear poles of the microswitch (The rear pole is the end of the switch where the metal lever joins the switch body, see below in the diagram). It is best practice to protect the connections with a small length of heatshrink if you have that available.

Connect two female 2.54mm crimp connectors to the other end.

fritzing

INSTALLING THE SENSOR

With the switch wired in place and the housing screwed securely we can move to connecting the unit and setting it up in OctoPrint. We assume you already have a working OctoPrint installation and have completed a test print to ensure that it works. We will be connecting our filament sensor to pins 18 and 20 of the RPi. It does not matter which way around we connect them. Physical pin 18 is the 9th pin along on the outside row, 20 is next to it. With this complete, we need to go about setting up our OctoPrint installation to read the filament sensor.

SETTING UP THE OCTOPRINT PLUGIN

We need to install the OctoPrint Filament Sensor plugin. There are different ways of doing this. The simplest and direct is using the OctoPrint plugin manager. With your OctoPrint page open, go to the top and click on the spanner icon to open the settings page. With the settings page open, scroll down to find the plugin manager on the left-hand side. Select this, and the left pane will give you a list of the installed plugins. Scroll down and select the “Get More…” option at the bottom. This will open the “Install new plugins” page. In the search box type “filament” and you will be presented with a series of plugins. We want to install “Filament Plugin Reloaded”. Select install and OctoPrint will install the plugin for us.

Settings - PLUGIN MANAGER

plug-in manager
plug-ins install

With the new plugin installed you must reboot your RPi. Once complete navigate back to the settings, and down the bottom, on the left, you will find “Filament Plugin Reloaded” under the Plugin section. Select this, and we are presented with options for our filament sensor. We are presented with Pin, which we set to 24, Debounce time which is left at 250ms, Switch type which we leave set to “Normally Open” If you wired your switch the wrong way around we can change it here. We need to change “Board Pin Mode” to “BCM Mode” this is for the pin numbering. Before we mentioned that we connected to physical pin 18, however, this is GPIO pin 24. This can be confusing but leave as we have stated. Finally, make sure that "Pause print when out of filament” is checked. Save and return to the setting screen.

filament sensor reloaded

Our sensor is now connected and setup, but we have one last job to do. The current set up will pause the printer, but OctoPrint can execute some GCODE when these events happen so we will turn off the bed and tool. Go to GCODE Scripts under Printer on the settings page. Find the “After job has paused” option and in the text box next to it add the following lines:

M104 S0
M140 S0

The first line sets the extruder temperature to 0 (M104) and the second (M140) sets the heatbed to 0, effectively shutting the machine off. In the next box “Before print job is resumed” place the following:

M109 S205
M190 S60

This will set our extruder to 205 degrees and the bed to 60. Once these temperatures have been reached the print will resume. Please be mindful that these are our preferred PLA temperatures for the LulzBot PLA printers. If you are using ABS or alternative print materials, you will need to set them at different temperatures.

scripts

We now have everything set up and ready to go, but to make sure things are in fact working correctly we need to do some simple tests to make sure it’s working. We need to log back into our RPi. Log into the system using SSH as described above. Once you have logged in we need to log into the hidden OctoPrint directory and then into the logs directory:

cd .octoprint/
cd logs

Once we are in the directory, we need to use “tail” to read the log stream. Tail is an interesting command that allows us to watch a particular file. By doing this, we can watch the background of OctoPrint to make sure that the switch is, in fact, triggering an event when the state changes. Make sure you have some filament in the filament sensor and enter the following command:

tail -F octoprint.log

We will see the log pop up, and it will display something similar to this:

octoprint.plugins.filamentreload - INFO - Setting up sensor. octoprint.plugins.filamentreload - INFO - Using BCM Mode octoprint.plugins.filamentreload - INFO - Filament Sensor active on GPIO Pin [24]

If we trigger the filament sensor now, nothing will happen. We need to start a print in order for us to test the sensor. Start a new print, and you will see the following line in our SSH session:

octoprint.plugins.filamentreload - INFO - PrintStarted: Enabling filament sensor.

Once the print has started, we can test the filament sensor by removing the piece of filament we have used. Once the switch state is changed then we get the following output:

octoprint.plugins.filamentreload - INFO - Out of filament!
octoprint.plugins.filamentreload - INFO - Pausing print.

This output will also coincide with the printer pausing. Please note that it will take a few moments for the last few GCODE commands to execute before it pauses. With the system paused we get the following screen in OctoPrint.

OctoPrint

To restart the print, click on the resume button that replaces the pause button. Be mindful that the big red button restarts the print.

A NOTE ABOUT PAUSE/RESTART: One thing of note that we will leave for extra credit. In the pause/restart GCODE, we turned the tool and bed off. There is an M600 “Change filament” command, but the implementation seems to vary based upon firmware and printer model. This command will essentially park the tool rather than pause the print, before returning back to where it was.

EXAMPLES

To execute filament change with no parameters, M600 uses the settings in Configuration.h:

M600

To set the change position and do filament change at X:10, Y:15 and Z:+5 from current:

M600 X10 Y15 Z5

This system will give you the peace of mind to start big prints or even start a print when we are unsure if we have enough filament left on the spool.

WHERE TO FROM HERE?

As mentioned at the start of the article, the OctoPrint software provides considerable extensibility well beyond this article through its plugin system. You could for example, have OctoPrint send you push notifications to your phone with job progress using Pushbullet or Pushover.

Get status updates on your Slack or Telegram messaging tools. You can even create timelapse recordings of your prints that you can share. Being 100% open source, you can configure to your own needs.

One thing that's worth considering however, is a dual-feed filament changeover system. This is a little akin to the dual toilet roll holders often found in public toilets. OK, bare with us here...

What if you could have two spools of filament fed into a system, which automatically switched over the roll when it detected an outage? Awesome idea, right?

There are a few challenges here, in that you would effectively need to fuse the start of the new roll to the end of the old roll. But we already have the technology to do this available to us in the form of an extruder.

In theory, an extruder with the same output size as the filament your printer uses (which could potentially be drilled out from a standard size extruder), could provide the necessary merging of filaments.

It would take some fiddling with temperatures and pressures, but it can theoretically be done with relatively minimal effort. However it would solve one of the major headaches that can come around with complex, filament heavy prints.

It would also save the inevitable collection of "almost used" filament rolls many of us have!