Updated for 3.6 (tested on 3.6.0rc1): WeighFilament.zip.txt (as usual you will need to take the .txt off the end of this file - I'm circumventing the forum restrictions).
Functionally it's the same (so read the first post in this thread for what it does). Actually the only change is to renumber it to a 3.6 version and set the requisites to 3.6. The calibration file is unchanged so if you put that somewhere safe you could copy it back after putting the new plugin in and wouldn't need to calibrate.
As before, this plugin is purely DSF, no DWC component at all. I still can't get endpoints working so this one still uses the kludge of writing a global variable instead. You can define a macro containing e.g. M291 P{global.filWeight^"g filament on spool"} R"Filament Weight"
to get the weight (or read the object model).
Installation
The 3.6.0RC1 package repository does not have 3.6.0 DSF (at time of writing), and the 3.5.1 DSF one does not work with 3.6.0, so you need to add DSF manually. The 3.6.0 RC1 version is on pypi: https://pypi.org/project/dsf-python/3.6.0rc1/ so sudo pip3 install --break-system-packages dsf-python==3.6.0rc1
should install it.
python3-dsf-python (3.6.0~rc1-1) is in the repository now so can just sudo apt install python3-dsf-python
(or sudo apt upgrade
) it.
You need some python libraries. At a command prompt: sudo apt install python3-numpy
. The previously required python3-rpi.gpio and python3-setuptools seem to already be part of the latest DuetPi image.
You need to download and install the HX711 library from https://github.com/tatobari/hx711py This is pure python and relatively straightforward. Having downloaded and unpacked you cd into the library top folder and sudo python3 setup.py install --record files.txt
.
To install the plugin drop the zip onto the 'Install Plugin' button in Plugins / external plugins in DWC - but DO NOT START the plugin yet.
The plugin won't create the necessary global variable, only update an existing one, so you need to add creation of the variable to config.g, e.g. with the following. The value you set here doesn't matter. You can use a different variable name, but in that case must edit the value near the start of /opt/dsf/plugins/WeighFilament/dsf/weighfilament.py to match.
if !exists(global.filWeight)
global filWeight = 0
You need to calibrate the routine before use. The plugin has a helper script to do that, and it's easiest to put this into /usr/local/bin so you can run it directly. At a command prompt run sudo cp /opt/dsf/plugins/WeighFilament/dsf/weigh /usr/local/bin
and then sudo chmod a+rx /usr/local/bin/weigh
.
With nothing on the spool holder at a command prompt run weigh zero
or weigh z
, this records the tare reading of the holder alone.
Then you need something of a known weight not dissimilar to a spool of filament (preferably nearing the end) on the holder - I use a 200g weight - and run weigh calib
or weigh c
. It will ask you what the weight is.
Then preferably put an empty spool on the holder and run weigh spool
or weigh s
. If you don't have an empty spool but do know what one weighs you can run weigh manual
or weigh m
and enter a weight value.
Some semi-cryptic entries should now have shown up in the weighfilament_calib.txt file in the system directory.
You can re-run any of these (e.g. when you change to a spool with a different empty weight), but you must stop the plugin first. There is no locking, and the script and plugin will scramble each other's communication with the HX711 if they run simultaneously, normally resulting in a hang or garbled data. The calibration file grows forever, if you do a lot of resetting the calibration you can open it and delete older lines - the routine just uses the last of each 'zero', 'calib' and either 'spool' or 'spoolwt' lines it finds in the file.
If you get wildly varying (or complete garbage) answers or the weigh script hangs, the plugin is probably running. Stop the plugin before running the script. Also, the plugin only reads the calibration file on startup - so you need to start the plugin after changing calibration values for it to get the new values anyway.
However, there is apparently the possibility of problems with bit ordering and byte ordering which can also lead to garbage values - if you still get garbage values see the discussion on the HX711 library github page and make changes in definitions near the top of both the helper script and the weighfilament.py file in the plugin zip file.
After all that you should be able to start the plugin. Apart from 'Status' changing to 'started' nothing visible will happen, but if you look in the object model browser or run M291 P{global.filWeight}
you should get a weight.