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
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...).
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 sm2ss.
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.
One way to do this is to use the Android app Spoolman Companion.
One can also use the write_tags.py
program included here.
It fetches Spoolman's filaments, 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