Set loaded spool & filament in klipper from NFC/RFID tags.
In the cloned repository's dir run:
virtualenv venv
venv/bin/pip3 install -r requirements.txt
Update the config in nfc2klipper-config.json5
.
I use a PN532 based reader (Elechouse PN532 NFC RFID Module V3, if you want to use the same) connected via UART to the raspberry pi where this program is running.
Many pages suggest connecting its VCC pin to 5V on the RPi. Don't! It can run from 3.3V and then it won't risk slowly destroying the RPi's GPIO pins.
See here for how to configure a raspberry pi for it (but change VCC pin...).
Run sudo rpi-update
to avoid problems with older firmware on the pi.
There is a model for attaching it to the printer here.
When running it on a raspberry pi's mini-uart (ttyS0 as device), it works fine. When using the other UART (ttyAMA0), I can only run the programs once. I have to power cycle the PN532 to get them to run again. Just rebooting the pi doesn't help.
This seems to be due to a bug in nfcpy (version 1.0.4), see (nfcpy/nfcpy#186).
A workaround that works for me is to change
venv/lib/python3.7/site-packages/nfc/clf/pn532.py
around line 390, from:
change_baudrate = True # try higher speeds
to:
change_baudrate = False # try higher speeds
When a tag has been read, it will send these gcodes to Klipper:
- SET_ACTIVE_FILAMENT ID=n1
- SET_ACTIVE_SPOOL ID=n2
See klipper-spoolman.cfg for the klipper
config for them. Klipper must also have a [save-variables]
section
in its config, see
Klipper's documentation.
For every filament, add a custom start gcode that calls:
ASSERT_ACTIVE_FILAMENT ID=<id>
where <id>
is its filament id in Spoolman.
This can be done automatically by using spoolman2slicer.
The tags should contain an NDEF record with a text block like this:
SPOOL:3
FILAMENT:2
The numbers are the id numbers that will be sent to the macros in klipper via the Moonraker API.
It is possible to enable an experimental web server in nfc2klipper.py
.
It will then serve a web page for writing to the tags.
The default address will be http://mainsailos.local:5001/
,
where mainsailos.local
should be replaced with the computer's name (or IP address).
The program uses a development web server with no security at all so it shouldn't be run if the computer is running on an untrusted network.
The program has a configuration file (nfc2klipper-config.json5) for enabling the web server, setting the port number, addresses to moonraker and mainsail, the webserver's address and NFC device to use.
There is an Android app, Spoolman Companion, for writing to the tags.
The write_tags.py
program fetches Spoolman's spools, shows a simple
text interface where the spool can be chosen, and when pressing return,
writes to the tag.
Use the write_tag
script to stop the nfc2klipper service, run the
write_tags.py
program and then start the service again after.
Copy nfc2klippper.service to /etc/systemd/system
, then run:
sudo systemctl start nfc2klipper
sudo systemctl enable nfc2klipper
To see its status, run:
sudo systemctl status nfc2klipper