Filament Scale

This project is a Filament Scale using a RP2040 with integrated LCD display a HX711, 5Kg load cell and a custom PCB.
Rather than a stand alone scale this project integrates the scale into a custom 3D printed spool arm replacing the original in a 3D printer.
Supplies






HX711 & Load Cell 5kg [Rectangular construction 1.3(W) x 1.3(H) x 8(L) cm
RP2040 with integrated LCD 0.96 inch
100nF 1206 SMD - Qty 2
Pin headers - Straight through hole single row
Pin headers - Right angle through hole single row
SIL socket 20pin - Qty 2
SIL socket 4pin - Qty2
M2 x 6mm self tapping screws - Qty 2
M2 x 10mm threaded spacers - Qty 2
M2 x 10mm plastic screws - Qty 2
M2 X 4mm plastic screws - Qty 2
M2 plastic washers - Qty 2
M2 plastic nuts - Qty 2
M3 x 5mm plastic screws - Qty 5
M3 x 13mm plastic screws - Qty 4
M3 x 10mm plastic threaded spacer
M3 x 15mm plastic threaded spacers - Qty 4
M3 X 15+5mm plastic threaded spacers - Qty 4
M3 plastic washers - Qty 5
M4 x 17mm metal countersunk screws - Qty 2
M5 x 17mm metal countersunk screws - Qty 2
Momentary push button switch NO - Qty 3
Toggle switch SPDT - Qty 2
A piece of flat transparent film (PET or similar), from a blister pack.
30 AWG wrapping wire [if utilising wire wrapping]
USB_C lead [right angle due to position and proximity to spool holder.]
May prove more cost effective to buy a range of values rather than individual values unless you already have them available. Some components may also have a MOL greater than the quantity specified in the component list.
No affiliation to any of the suppliers, feel free to obtain the supplies from your preferred supplier if applicatble.
Links valid at the time of publication.
Tools
3D Printer
Needle files
Sanding paper
Craft knife
Soldering Iron
Solder
Wire cutters
Screwdriver (tip profile subject to screw head)
Pencil
Drill
Drill bit 6.5mm
Drill bit 5mm
Drill bit 4mm
Drill bit 3mm
Drill bit 2mm
Wire Wrapping Tool
Flexible Adhesive
Scale (for comparative and reference weight measurement)
Know your tools and follow the recommended operational procedures and be sure to wear the appropriate PPE.
Background
Wanting to know if there is sufficient filament on a spool for those long print jobs prior to printing.
I would normally make use of a separate scale and a calculator.
But a more practical solution would be a scale integrated within the printer.
This project brings the idea to life.
I decided to use a microcontroller with an integrated display to simplify build and reduce size and settled on the RP2040 LCD 0.96.
However, although software information exists for the display it's less than comprehensive with regard to use, in any event I was able to use what was available to progress.
For the HX711 I found a few examples but opted for the following, grzesina.de/az/waage/hx711.py making minor modifications to suit my requirements and for the English language.
A relatively inexpensive Beam Load Cell is used with the gauges attached top and bottom, suitable for low to medium loads such as weighing scales.
The spool arm was designed in TinkerCAD to replace the original for an Elegoo Neptune Pro 4.
The circuit utilises a custom PCB for consistency and to simplify the build process.
Wheatstone Bridge

The Wheatstone Bridge named after Sir Charles Wheatstone but invented by Samuel Hunter Christy in 1833.
The sensing array (1 to 4 strain gauges), in a load cell is derived from the Wheatstone Bridge with additional compensation for variation in temperature, cable and contact resistance.
The strain gauge is likely be a thin, flexible, resistive, metal or semiconductor element(s) attached to the load cell body. When the load cell is subjected to a load the strain gauge is stretched (R increases), or compressed (R reduces), which changes its resistance.
As resistance R = pL/A where p = specific resistivty, L = Length and A = cross section area
Therefore if L or A changes then the resistance will also change.
Taking one potential divider the voltage at the centre tap is the ratio of the two resistors multiplied by the supply voltage.
Vo = (R2/R1+R2)*Vs, vary the values of R1 or R2 and the ratio and hence the voltage changes.
If we consider that the Wheatstone Bridge is 2 *(two resistors), potential dividers in parrallel.
If all the resistors in the Wheatstone Bridge are the same then the voltage at the centre tap of each potential divider will be the same and the differential voltage between the two centre taps will be zero. Vdiff = Vct1 - Vct2
If one resistor changes one of the potential dividers will have a different centre tap voltage and Vdiff will change either positive or negative.
Vdiff = (R2/(R1+R2) - R3/(R4+R3))*Vs
Substituting the resistors for strain gauges (Typical fixed values of 120R, 305R & 1kR), creates the sensing array.
The changes in resistance in the strain gauge will result in small (millivolts), differential voltages in the bridge, as a result signal conditioning in the form of amplification and filtering is employed to enable use by data aquisition systems.
In this case the signal conditioning is taken care of by the HX711.
The HX711 is a 24bit ADC with a PGA of (ChB), 32, (ChA), 64 or 128 with a minimum full scale differental input voltage of +/-20mV. A supply voltage range of 2.6V to 5.5V and operational suppy current of <1.5mA.
For convenience this is available pre assembled on a PCB.
In this application we will be using Channel A and a gain of 128.
CAD Design





The majority of the 3D printed parts were designed using TinkerCad.
These parts are the scale_load, scale_clamp and the scale_nut.
One of its attractions was the screw thread generator to create the clamp and the nut.
However, the right angle bracket and the enclosure were created using BlocksCAD.
Links to TinkerCAD files.
The these and the additional STL files not on TinkerCAD are listed below:
3D Printing





Filament: PLA (Black), simply to match with the printer but any colour as suits personal choice.
Layer Height: 0.1mm for the Scale_clamp and nut, 0.15mm for the Scale_load, Bracket and enclosure.
Infill: 100%
Bed Adhesion: Skirt
No supports
All parts are correctly orientated within the files for printing directly.
All parts where sliced using Cura 5.8.1 and printed on a Elegoo Neptune 4 Pro.
1: Scale_load. 45(dia) x 71(H) mm, Weight: 29g
2: Scale_clamp: 50(dia) x 60(H) mm, Weight: 28g
3: Nut: 41.2(dia) x 10(H) mm, Weight: 8g
4: Bracket. Size: 80(L) x 50(W) x 94(H) mm, Weight: 48g
5: Enclosure: Size: 72(W) x 83.5(L) x 35(H) mm, Weight: 38g
Post Processing
Some post processing may be required to remove aberrations in the cavities and around the edges with sanding paper and needle files in addition to opening and smoothing the holes with the required drill bits to suit the holes.
Circuit

The load cell is connected to channel A at the HX711 via four wires to E+ (red), E- (black), A-(white) & A+(green).
E+ (3V3), and E- (0V), are the load cell supply lines and A+ and A- (1kR output resistance), connect to the amplifier inputs.
B+ & B- the other channel is not connected.
The outputs from the HX711 are connected to the RP2040.
HX711 DT to RP2040 GP0
HX711 SCK to RP2040 GP1
HX711 V+ to RP2040 3V3
HX711 GND to 0V
The selection of the various options are accomplished using switches connected to GP18 to GP21.
These pins are internally connected to 0V via resistors (50kR to 80kR), within the RP2040.
The switches connecting GP18 to GP20 are Momentary switches.
Filament Type: One pin connected to GP18 with the other connected to 3V3.
Filament Diameter: One pin connected to GP19 with the other connected to 3V3.
Spool: One pin connected to GP20 with the other connected to 3V3.
The Mode and Power switches can utilise toggle, push button or slide switches. Although I have used slide switches.
Mode selection: One pin connected to GP21 with the other connected to 3V3.
The mode selection will determine whether entry/pause or measurement..
A power switch is included between the USB_C input (5V), and the RP2040 Pin40 (VBUS), there is an internal Schottky diode (Vf<0.3V@100mA), in series with this input which provides reverse polarity protection.
I prefer to isolate the supply via a switch for general use rather than connecting directly to the onboard USB and use the onboard USB for programming and testing.
PCB





The PCB is double sided and was designed using EagleCAD and manufactured at OSHpark.
Board Size: 49.5(D) x 78.74(W) mm with 3mm mounting holes in each of the 4 corners.
The RP2040 is mounted on the front and the HX711 is mounted behind it on the other side of the board.
Three momentary contact switches are included for option changes, Filament Type, Filament Diameter & Spool Weight.
One SPDT switch to select the mode of operation.
One SPDT switch for power control.
Provision is made to attach a separate USB_C breakout board to the PCB or remote connected.
Additionally there is an auxillary supply input on 2 separate pins.
Subject to user preference the project can be mounted without an enclosure as the PCB accommodates low profile switches or using offboard switches using the supplied enclosure details.
Downloads
Scale Arm Assembly







Orientate the load cell with the end label facing the non flange end of the scale arm, such that the screw holes in the load cell and scale arm are aligned when the load cell is slid into place.
Fix the load cell in place with 2 x M4 x 17mm countersunk screws.
With the flanged end of the scale clamp orientated toward the non flange end of the scale arm push the wires of the load cell through the centre hole of the scale clamp with the screw holes aligned.
The inner part of the flange end of the scale clamp is stepped to allow the side of the load cell to which the wires emerge to not foul during insertion.
Fix the scale clamp to the load cell with 2 x M5 x 17mm countersunk screws.
There will exist a small gap between the scale arm and scale clamp allowing the scale arm to flex in relation to the scale clamp.
Solder a 4pin SIL socket on the ends with the wires in the following order E+(red), E-(black), A-(white), A+(green).
HX711 PCB Preparation




The HX711 was purchased fully assembled on a PCB with additional conditioning components all that is required is to solder in place the SIL pins.
Orientate the HX711 PCB with the HX711 uppermost and with the six drill holes on the left.
Insert a 4pin right angle header with the short pins in the four holes starting top left (E+, E-, A-, A+) and solder in place.
Insert a 4pin straight header from the underside with the short pins uppermost and solder in place.
Slip a plastic washer over a M2 plastic pan head screw.
Pass the M2 screw through one of the mounting holes to the front of the HX711 PCB.
Fit a M2 nut over the M2 screw and tighten.
Repeat the process at the other mounting hole.
On each screw fit a M2 x 10mm threaded standoff.
Further details regarding the HX711 can be found in the attached datasheet.
Downloads
Protective Clear Window

A clear window is used to add some protection in front of the RP2040 which is also flexible enough, to enable if necessary the pressing of the RESET button in the event that the microcontroller locks up.
This is made from a piece of a clear film (PET or similar), from a blister pack.
Cut a rectangle to the following size: 50(H) x 80(L) mm
Drop it into the back of the main cover and while holding it in place insert a marker into the screw holes at the front to mark the film.
With a 3mm drill bit, awl or punch, cut out the holes.
Main Unit Assembly












Main PCB
Position and solder in the two 100nF capacitors.
From the underside insert a 4 pin SIL socket into the holes designated for the HX711 (JP3) and solder in place.
Insert and solder in 2 x 20pin SIL sockets.
Insert a M3 plastic screw from the top to the back of the main PCB and fit a plastic washer and a M3 x 10mm threaded standoff. This helps to retain the HX711 PCB in place once the main PCB is attached to the scale bracket.
Insert the 4pin header of the HX711 PCB into the 4pin socket at the back of the main PCB and secure in place with 2 x M2 x 4mm plastic screws.
USB Board
Power is provided by a separate USB board which is attached remote from the main PCB at the back of the bracket.
A series of holes are provided close to the corner of the bracket to fit the USB board.
Measure 2 x lengths of wire sufficient to reach the USB board and the power connections on the main PCB.
A straight pin SIL header was fitted to the USB board to facilitate wire wrapping although soldering either or without the header is possible.
The USB board is secured in place with 2 x M2 x 6mm self tapping screws.
Holes are provided in the Scale bracket to allow the wires to be threaded through to the main PCB which are connected to the 0V and 5V pins.
Main Cover
The main cover holds the switches that are used to control the scale and provide a degree of protection whilst allowing visibility of the screen.
Widen the five switch holes with a 6.5mm drill bit if necessary.
Starting at the left hand most hole fit 3 x push button switches.
In the remaining two holes fit the toggle switches.
Cut ten lengths of wire sufficient to allow easy soldering of the wires and to reach from the switches to the main PCB.
Attach a pair of wires at each switch adopting the same convention.
Attach a pair of wires from each switch to the main PCB at SW1(Filament), SW2(Diameter), SW3(Spool).
A pair of wires are attached at S1(Mode), and S5(Power).
There is also an opening on the right hand side coincident with the USB socket on the microcontroller.
This alows access as an alternative power source and software editing without having to open the main cover.
If not already done so, fit the RP2040.
Fit the protective film into the main cover, if necessary secure in place with a flexible adhesive.
Scale bracket
To the scale bracket secure 4 x 15 + 5mm plastic threaded standoffs (one in each corner), and a washer with nylon screws. Insert the screw through the corner hole in the rectangular section of the bracket followed by a washer and the standoff and repeat in the other corners.
Thread the leads from the Load cell with the attached 4pin SIL socket and pass it through the centre hole in the Scale bracket.
Ensure the load cell is orientated correcly with the arrow on the end of the load cell pointing downwards.
Secure the Scale arm in place with the large nut.
Pass the leads from the load cell through the centre hole in the Scale bracket and connect to the 4 SIL pins of the HX711 board.
Seat the main PCB on the threaded ends of the standoffs, secure the PCB in place with 4 x 15mm plastic threaded standoffs.
Fit the main cover with the 4 corner holes aligned with the standoff holes.
Secure the main cover at the front via the corners with 4 x M3 x 5mm plastic screws.
Software

The software is written in MicroPython v1.15 using Thonny 3.3.13
The firmware library used was rp2-pico-20210418-v1.15.uf2 this and/or an updated version can be downloaded from the Waveshare site under Software Setup which also includes installion details if required.
Once the firmwave is installed and a connection is established to enable programming.
Rename library hx711f.py (load cell), to hx711.py and copy to the RP2040
Copy library LCD096.py (display), to the RP2040
Copy the three text files ftypes.txt, spool.txt and fdia.txt to the RP2040.
The text files contain custom configuration information enabling the user to simply edit the files without requiring modification to the code.
ftypes.txt contains a list of filament types and density(kg/m3).
A link is provided to a source of filament types and densities other lists are available*.
spool.txt contains a list of spools from different manufacturers and their weight(g).
A link is provided to a source of empty spool weights there are other lists and if in doubt weigh your empty spools*
*No affilation to these links feel free to use other sources.
fdia.txt contains a list of filament diameters(mm).
The same information within these files is also coded within the software as three separate lists.
This means that the user has the option to either use the coded defaults or the contents of the files.
Subject to user preference the lists and/or files can be edited as rewuired.
How is this accomplished.
When the software loads it checks whether each text file is usable, if the file is usable the software loads the data within the file. If the text file is not usable then the software loads the coded defaults.
Any modifications to the text files must follow the same format found within the original file to ensure compatibility.
I created the files with Notepad loaded these into Thonny and saved them to the RP2040.
Run the calibration process (Step 13), and edit the calibration factor in Filament_Scale6.py before renaming and copying.
Rename Filament_Scale6.py to main.py and copy to the RP2040.
Calibration



Prior to operation the scale will require calibration.
Ideally the calibration and operational environmental conditions should be the same for consistency as variations in temperature and humidity will impact the results.
Switch the scale on and allow to stabllise under the environmental conditions prior to calibration.
Rather than manually entering values to hopefully identify the calibration factor which would be somewhat a coarse value I decided it would be better to automate the process.
This would simplify, speed up and improve the accuracy compared to a manual process.
Obtain a known weight and/or verify with another scale and record the weight, this will be the reference weight.
Open Calscale.py
Changed the numeric value on the following line to the value of the reference weight.
calfac, NetWeight = bsa(812) in this case the weight is 812g.
The third value in the following line is the calibration factor which is a starting point for the calibration reference search.
hx = HX711(dout,dpclk,405) in this case 405 is the calibration factor. (This is the actual value for the load cell i used)
If the load cell is changed at a later stage calibration will need to be rerun.
Run Calscale.py
The LCD will display the following: "Remove weight now!" with a 10 second countdown.
This gives time to remove the spool from the spool arm, if one is in place.
Following this the LCD will display "Initializing", during this period the Tare (unladen weight), will be captured.
If the HX711 fails to initialize the following will be displayed "HX711 failed", in red.
If there are no issues.
The following will be displayed "Set D to Weigh".
Place a know weight onto the scale.
Set the D switch into the Weigh position.
The display will show "Calibrating"
This process will take a few seconds to complete.
During the calibration process a binary successive approximation search is carried out.
The search adjusts the calibration factor and carries out the following calculation:
Weight(mid) = (Mean Measurement - Tare) / calibration factor
Then compares the weight(mid), to the reference weight (target) and if the weight(mid), is within the tolerance (0.5) the search is terminated.
Once calibration is completed the display will show "Calibrated" the corrected weight and the new calibration factor.
The initial weight, corrected weight and new calibration factor are also shown on the Shell.
Open Filament_Scale6.py (main.py)
Replace the third value in the following line hx = HX711(dout,dpclk,405), with the new calibration factor.
Save the changes to Filament_Scale6.py (main.py)
Its always a good idea to check the calibration at regular intervals in case the scale has drifted, this can be verified with a reference weight.
Downloads
Operation

Apply power to the Scale.
The LCD will display the following: "Remove weight now!" with a 10 second countdown.
This gives time to remove the spool from the spool arm, if one is in place.
Following this the LCD will display "Initializing", during this period the Tare (unladen weight), will be captured.
If the HX711 fails to initialize the following will be displayed "HX711 failed", in red.
If there are no issues.
The display will next show the mode menu:
A:Filament Scale (First on the left)*
B:Standard Scale (Second on the left)*
- FIve switches on the front panel referenced A to E.
Press the button for the required Scale option.
A: Filament Scale
Switch D must be set to entry/pause mode to update the menu.
Three input fields will be displayed on the LCD.
Filament Type, Filament Diameter & Spool.
Each field controlled by a separate button.
E.g
Filament Type= PLA (Switch A)
Filament Diameter= 1.75mm (Switch B)
Spool= eSUN/244g (Switch C)
Repeatedly press the appropriate button to cycle through its option list.
Following selection of the required fields the following will be displayed "Set D to Weigh" in yellow.
Set the D switch into the Weigh position.
This will display the length of filament in metres and the weight in grammes.
B: Standard Scale.
Two selection options are applicable.
B2: With the D switch in the Weigh position.
The display will show only the live weight in grammes.
B1: With the D switch in the entry/pause position.
The display will show "Standard Scale" and "Set D to Weigh"
Set the D switch into the Weigh position.
The display will show only the live weight in grammes.
In either Scale mode.
Measurement can be held displaying the length and/or weight at that instant by setting of the D switch to entry/pause.
Set the D switch to Weigh to return to live measurement.
Power cycle or press the Reset button to return to the main option menu.
Finally
Hope you find this of interest.