Final Project¶
Introducing: FilaSense, a 3D printing filament diameter and roundness measuring device for those, who recycle their printing waste into new spools of filament.
This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International license.
Bill of materials¶
Amount | Material | Source | Cost / unit | Sum |
---|---|---|---|---|
~350g | Filament(PLA or PETG) | Bambu Lab | €22,99 / 1Kg | €22,99 |
1 | 3mm multiplex Sheet | Lasersheets | €5,78 | €5,78 |
1 | Doublesided FR4 Sheet | Amazon | €15,69 / 2 pack | €15,69 |
1 | USB power supply | Amazon | €4,99 | €4,99 |
1 | Angled USB-C to USB-A cable | Amazon | €6,79 / 2 pack | €6,79 |
~40cm | 28AWG ribbon cable | Amazon | €10,95 / 3m | €10,95 |
4 | Amphenol IDC connector | RS-Online | €0,69 | €2,76 |
1 | SEEED Studio XIAO RP2040 | Reichelt | €5,45 | €5,45 |
3 | ATTiny412 (SOIC-8) | Reichelt | €0,75 | €2,25 |
3 | SS59ET hall effect sensor | Reichelt | €2,15 | €6,45 |
1 | Rotary encoder with switch | Mouser | €2,38 | €2,38 |
1 | 1.3” OLED Display | Amazon | €8,49 | €8,49 |
5 | 1206 Resistor (1000Ω) | Mouser | €0,25 | €1,25 |
3 | 1206 Resistor (470Ω) | Mouser | €0,30 | €0,90 |
3 | 1x3 Pinheader (THT) | BerryBase | €0,60 | €0,60 |
4 | 2x2 Pinheader (SMD) | Reichelt | €1,80 | €1,80 |
3 | M3x16mm Socket head screw | Eisenwaren2000 | €1,82 | €5,46 |
18 | M3x10mm Socket head screw | Eisenwaren2000 | €0,82 | €14,76 |
3 | M3x8mm Socket head screw | Eisenwaren2000 | €1,50 | €4,50 |
20 | M3x6mm Socket head screw | Eisenwaren2000 | €0,37 | €7,40 |
12 | M2x6mm Socket head screw | Eisenwaren2000 | €0,82 | €9,84 |
3 | 4x2mm Neodymium Magnet | Amazon | €5,29 / 100 pack | €5,29 |
~20cm | 1.5mm Wire | Amazon | €6,99 / 5m | €6,99 |
~20cm | 2mm Wire | Amazon | €4,97 / 10m | €4,97 |
TOTAL | €158,73 |
By the way, buying individual screws is incredibly expensive, you should probably just get a mixed box of M3 or M2 screws like this.
Initial thought process¶
A little while ago I had the opportunity to build a DIY filament extrusion kit from ARTME3D at HRW FabLab and loved every bit of the process.
Not only is the machine incredibly compact for it’s capabilities but also the engineering behind it left me speechless at some points making it probably one of my favorite things I have built in recent years.
I mean just look at how to bring the melt filter into the right shape. So simple, so elegant, I could read these docs for weeks on end.
Anyways after having built this amazing machine and producing my first few spools of recycled filament with shreds of failed prints and support material I noticed a glaring issue: there was no way to keep track of the filament’s diameter and/or roundness besides constantly checking manually with calipers.
Both of these parameters can have a big influence on print quality, so naturally I searched the internet for all kinds of filament sensors, but pretty much every single one of them was a runout sensor.
The purpose of a filament runout sensor is to warn you or automatically pause the current print job when it detects that you have no more filament left.
These, while being useful addons for any 3D printer, would not help with my issue so I kept searching and eventually found the InFiDEL, a low cost inline filament diameter estimator originally created by Thomas Sanladerer a.k.a. MadeWithLayers.
This definitely looked promising but still kind of limited, because you can’t assume that the filament you are using is perfectly round and you are only measuring the width of the cross section.
Okay so why not just put three InFiDEL probes in a row at different angles, estimate the roundness that way and Bob’s your uncle, right?
That would work, sounds like a great idea, I said, but at some point it hit me… what do you actually do with these measurements?
I mean it’s not like I am trying to sell these spools of filament with a guaranteed tolerance in diameter. No, this filament is going to be used right here in our lab, mostly for prototyping and inhouse projects.
So what if this array of probes could also be used as a printer add on just like the runout sensors? But instead of only telling the printer whether or not there still is filament to be used, it would measure the diameter and roundness and directly tell the printer how to adjust its flowrate in order to compensate for any unevenness in the filament.
And that is exactly what I plan on building, a 2in1 tool to keep your recycled filament’s tolerances in check during production and tell your 3D printer how to compensate when printing.
Here are some early sketches of what I want it to look like:
Don’t worry, the brutalist aesthetic is not set in stone.
I am a big fan of modularity when it comes to important and frequently maintained parts and since the probes are expected to produce reliable results at any given time I feel like making individual modules out of them for calibration and maintenance purposes is the right call.
It will be important that the fastening mechanism is as rigid as possible because any kind of wobble might skew the results.
Also if the printer picks up the filament right out of the machine (I should really work on a name for this) without a buffer, the distance in between needs to be spot on in order for the whole thing to work.
To enter any calibration values I plan on integrating an LCD Display.
Prusa recently released a GPIO module that is capable of sending gcode commands directly to the printer mid print via I2C. Most modern open source 3D printer mainboards have an I2C interface as well so that will probably be the next thing for me to explore.
I plan on testing the communication side of this project directly on a Pursa Mk4 printer so one of my goals is to make it directly mountable to the spool holder.
Something like this:

It should also be mountable to standard aluminium extrusions for compatibility with other printers and of course the ARTME3D Mk3 filament extruder.
That is pretty much all I have for now, let’s see where this goes.
First Models¶
What you see here is an early version of what might at some point become my final project, looks good so far right?
I am not quite sure yet what kind of LCD display I am going to use in the end so I just went with this model of a BTT Mini 12864 V1.0 display by Tyler Phillips on GrabCAD for now
Keep in mind that the display model was only added for demonstration, I had do remove it due to storage space constraints
I also plan on experimenting with some kind of snap fit way of mounting the sensor modules to the main body, but using built in guide rails, heatset inserts and M3 screws seems more rigid
Here is a short video of the construction process
You can dowload the final_project_week02.f3z file by clicking right here
Producing the main PCB¶
During the Electronics Production week I designed and milled my first PCB, which I wanted to use for my final project.
Due to shipping delays I had to use different hardware than initially planned but the layout pretty much stayed the same regardless.
The core function for this board is to be the server in an I2C bus and thus be able to connect to a chain of helpers.
I designed the whole thing in KiCAD and manufactured it with an LPKF ProtoMat S63 PCB mill.
The gerber manufacturing files and design files for KiCAD are available for download right here:
Soldering the SMD components was as easy as can be with the use of solder paste and some hot plates but manually soldering on the pin headers turned out to be a gigantic pain in the rear.
At least I learnt that lesson, I guess…
Anyways, as the scope of my project changed over time, so did the main PCB.
After the display frying incident of week 10 and realizing, that an I2C bus needs pull-up resistors to work properly, I began working on a new iteration that looked like this:
This board was the first to feature a 2x2 pin header for the I2C bus, which came in handy later when planning out the wiring.
In the Interface and Application Programming week the cracks in my initial designs began to show as connecting a rotary encoder and display ended up in a mess of wires, which I wanted to clean up.
I hopped back into KiCAD and created a new board.
It looked good but sadly didn’t work.
To be honest at that point my brain was a little fried so I messed up by including pull-downs instead of pull-ups.
As a sanity check, I desoldered all the faulty resistors and created this abomination.
Which… also didn’t work… but shuffling around the code helped.
I simply enabled the board’s internal pull-ups and finally got it working.
The board still looked hideous though, so I went back to KiCAD and fixed my mistakes, leaving me with the final version of my mainboard.
You can download the KiCAD project by clicking here, or find it in the Download section at the bottom of this page.
Worker boards¶
Week 9 also known as the Input Devices week inspired me to produce a worker board featuring an ATTiny412, an SS59ET hall effect sensor, a 1x4 pin header for the I2C connection and one more single pin to program the board via UPDI.
In this project the hall effect sensor is the main tool for me to measure the filament’s thickness.
Unfortunately this board had some issues so I won’t link any design or gerber files in here, but the adventurous ones of you can feel free to check them out via my documentation of the assignment.
After taking some time to figure out the mainboard, I came back to this one to adapt the 2x2 I2C pin header layout and add a 1x3 pin header for the UPDI interface, this time featuring its own power and ground pins.
This iteration worked so well that it ended up already being the final one, so I produced two more copies.
Click here to download the KiCAD project, or check the Download section at the bottom of this page.
Programming¶
I guess the video from above was kind of a spoiler, so maybe I should talk about the software side of this project, now that the PCBs are done.
As already mentioned, the soldering lesson from a few weeks ago didn’t really stick and I ended up frying my first display.
Luckily the lab had more to offer and I got to work with a different one.
The code for this project was written entirely in the Arduino IDE and uses the following libraries:
-
RotaryEncoder by Matthias Hertel, a library simplifying the use of rotary encoders
-
U8g2 by Olikraus, a library to control OLED and LCD displays
-
Wire.h, Arduino’s built in I2C library
Since I wanted to show the filament thickness in a graph, I began coding exactly that.
I didn’t have any actual values yet so I went with a sine wave.
More details on how the code works and how programming via UPDI works can be found here.
Click here to download my sine_wave.ino file.
To get some values to work with I first had to establish the communication between the worker boards and the mainboard, which was easy enough with the built in Wire.h
library.
The only problem that occured was that I2C communication happens on a byte per byte basis and integer values take up two bytes.
But that was nothing a little bitshifting and masking couldn’t fix.
The sensor boards essentially split the value in half.
Sensor Sender
#include <Wire.h>
void setup() {
pinMode(0, INPUT);
Wire.begin(2);
Wire.onRequest(requestEvent);
}
void loop() {
delay(10);
}
void requestEvent() {
int16_t value = analogRead(0);
byte array[2];
array[0] = (value >> 8) & 0xFF;
array[1] = value & 0xFF;
Wire.write(array, 2);
}
After receiving them, the mainboard then puts the pieces back together.
Main Receiver
#include <Wire.h>
void setup() {
Wire.begin();
Serial.begin(9600);
}
void loop() {
delay(10);
int16_t value;
byte a,b;
Wire.requestFrom(2, 2);
a = Wire.read();
b = Wire.read();
value = a;
value = value << 8 | b;
Serial.println(value);
}
Check out my documentation of the Networking and Communicatinos week to learn more.
During the Interface and Application Programming week I figured, that only a graph of the current value wasn’t going to cut it.
I wanted to create kind of a menu sturcture as can be found on many Marlin based 3D printers, so I sketched out a UML diagram to help me organize my thoughts.
Integrating this menu in combination with the logic to control it via a rotary encoder took a bit of time, but worked out in the end.
Only after the PCBs were sorted out, did I return to take a closer look at the code again.
I implemented a bootscreen, updated the graph submenu, combined the sensor calibration submenus into one and added one to read the raw sensor values.
Click here to download my FilaSense_Mainboard.ino and FilaSense_Sensorboard.ino files, or check the Download section at the bottom of this page.
The way forward¶
With the Mechanical Design and Machine Design weeks done, the midterm review was about to happen and it was time to think about… time…
Here is a simple gantt chart of what I planned on doing in the weeks leading up to the presentations.
As it turns out, I am not the greatest at planning ahead and this gantt chart ended up getting thrown overboard.
It did give me a neat overview of the tasks that were still ahead of me though and, I have to say, being able to choose what to tackle first made it more approachable for me.
I guess spiral development sounds nice on paper, but doesn’t necessarily work out for everybody.
Case, Modules and Clips¶
Now, that the electronics are working as intended, I was able to focus on building a digital twin of my project.
It was mostly built in fusion with the PCBs being exported from KiCAD as STEP files.
Here is a timelapse of the construction:
I’ll quickly go over the key points but for a detailed look under the hood check out my System Integration weekly assignment.
The real heart and soul of this design is this 3D printed spring mechanism, that I came up with.
It consists of two spring parts, between which an idler wheel is sandwiched.
The left end of the springs is fastened to the module’s case and cannot move, while the right side slides in chamfered grooves.
The idler wheel is a guide for the filament that gets pushed through the machine and is thus displaced according to the filament’s current thickness.
The bottom spring part houses a small magnet that sits directly on top of the sensor board’s hall effect sensor.
That way the filament diameter directly controls the values sent from the sensor board to the mainboard.
To measure not only the diameter, but also the roundness of the filament, I placed three of these modules at different angles and built a case around them.
Click these links to download the Sensor Module and Assembly Fusion files , or check the Download section at the bottom of this page.
The case features little anchors along the sides to which both the IDC and USB cable can be fastened with lasercut clips.
To help identify the UPDI pins I lastly designed a vinyl cut sticker that sits on the back of the sensor modules.
I hope by now you know where to find the .dxf files for the clips and stickers.
Here is a timelapse of me building the whole thing:
Calibration and Operation¶
Although I included some pretty solid base calibration values in the software section, I highly recommend calibrating the highest and lowest acceptable sensor states.
The concept is pretty simple, select the calibration submenu, insert a piece of 1,5mm thick wire and press the encoder’s button.
Repeat the same steps with a piece of 2mm thick wire.
Any filament below or above is either going to cause underextrusion problems or a clog, which you definitely don’t want.
At the end of the calibration routine, the measured values will be displayed on the screen.
If you don’t want to recalibrate the machine after every boot, you should copy these values into the FilaSense_Mainboard.ino
file and flash the board.
When accurate calibration values have been set, all you need to do is insert some filament you want to test for viability and enter the Measure
menu.
In this example, I respooled a spool of recycled filament that has previously caused problems, to trigger the Filament too small
error message.
Reflection and closing thoughts¶
This marks the end of my trip through the FabAcademy and although I am about to collapse in exhaustion, both mentally and physically, I have to admit, I probably learned more over the course of these last 20 weeks than I have in all the prior years studying computer science.
A large portion of this comes from me actually caring for the projects for once.
My favorite ones definitely were my chainmail spinning top from the 3D Scanning and Printing week
And my vinyl tree from the Computer-controlled Machining week.
These must have been the most inspired works of my life so far and I probably wouldn’t have ever come up with them if it weren’t for the FabAcademy.
On the other hand this kind of destroyed me mentally week over week.
Caring too much for a single project, you know you only have one week for and having to cut features to stay on schedule while still only finishing just on time without leaving two minutes to breathe almost made me quit.
In the beginning I remember Neil saying that all weekly assignments could probably be done in two hours each if everything worked without fails.
That means only doing the absolute bare minimum to check off all requirements, but that’s not how my brain works.
I wasn’t able to come to terms with producing generic slop that has been done a billion times before, even if it would have been the smarter and healthier choice.
Especially after the Mechanical Design and Machine Design weeks, where we went wayyy overboard with our machine while essentially building it with only 3 out of 4 planned people, I could have used a break but sadly it didn’t come.
Only when I eventually did collapse in exhaustion, I decided that it was time to take a breather, which is why you can probably see a steep drop in quality and length of my weekly assignments at some point.
And while this drop bothers me, it was desperately needed or I wouldn’t have been able to finish my final project without cutting even more features.
This isn’t even supposed to sound all that dark, but I think it is a good idea to spread the word that while many things created here are awesome, it is not all sunshine and rainbows.
To end on a happy note, I want to thank my fellow students Kerstin Ogrissek and Lars Hofmann as well as our instructors Jonas van Hagen and Lars Mattern for everything they have done.
This would not have been possible without you! <3
Stay hydrated.