Replies: 2 comments 1 reply
-
This is some great tinkering! I will move this over to discussions since it isn't really any feature request. |
Beta Was this translation helpful? Give feedback.
-
I have created something similar but using MQTT, an M5Atom, an M5 QR board and some NodeRed. It's a more complex setup as I have QR codes for printers and spools, scanning a printer then a spool (or vise versa) would activate this spool on the printer. I don't like my solution as it pretty custom and require additional infrastructure to run an MQTT broker and NodeRed. Your solution would use a more generic scanner but I still don't like it being wired to the printer (personal preference). The main reason I created the export CSV MR was to quickly print custom labels using a Brother label printer. |
Beta Was this translation helpful? Give feedback.
-
First of all - thank you @Donkie for creating Spoolman! The lack of a filament manager coming from Octoprint to Klipper was a downgrade in that regard, and now this tool is everything I wanted and much much more!
I wanted to share with everyone a use case that I set up and find it better than using a phone to scan a QR code or setting a spool id in software. Perhaps someone might find it useful as is, or as an inspiration for creating their own way of setting active spools.
Preface
My implementation is a bit janky, made specifically for my use case that might be different from yours, but it works for me and might work for you. Writing this up took longer than getting this to work in the first place. Feel free to create a git project to make it better :)
General idea
Usage
Swapping spools for me means physically interacting with the spool - either by placing it on a roller, or feeding filament from an airtight container. Having a barcode scanner close by means I can just scan a label either on the spool or container and in turn have that spool set as the active one without fumbling with my phone, setting it in software, etc.
Labels
I don't have a large format label maker, but do have a DYMO 280 label maker and am using a 12mm roll. Using their software I just make a bunch of labels like this with the QR code having a text value of
SM:SPOOL=<spool id>
Setup
Spoolman server and printer(s)
I installed Spoolman alongside Klipper on the same Pi (I only have one FDM machine). However this barcode scanner method is still viable for multiple printers, just that the listener code would need to be altered to first require scanning of a QR code to set the desired printer and then scanning a spool. This would allow routing the gcode request to the corresponding printer.
Barcode scanner
Depending on the barcode type you wish to use - you'll need either a 1D or 2D scanner. 1D scanners cannot do QR, dot matrix and other similar formats, while 2D scanners can do essentially any format. I opted for a wireless 2D scanner with a 2.4ghz dongle as it doesn't require to be tethered to my Pi.
Pi and listener setup
Scanner HID
First you need to validate that the Pi recognizes the scanner, in my case it shows up as a generic HID device.
The path for the scanner will likely be
/dev/hidraw0
, but depending on what devices you have plugged in it may be different. You can check each device by running the following after replacinghidraw0
withhidraw1
,hidraw2
etc. You should be able to identify the scanner as it will report as an HID/Keyboard/Generic input device.I'll be using
hidraw0
in this write up moving forward.pi@voron:~ $ cat /sys/class/hidraw/hidraw0/device/uevent DRIVER=hid-generic HID_ID=0003:0000FFFF:00000035 HID_NAME=ARM CM0 USB HID Keyboard HID_PHYS=usb-3f980000.usb-1.1.3/input0 HID_UNIQ=0123456789AB MODALIAS=hid:b0003g0001v0000FFFFp00000035
Depending on what user permissions you'll be running the listener on it may be required to
sudo chmod 666 /dev/hidraw0
for your user to be able to listen to that device. This will however reset on boot, so you can addchmod 666 /dev/hidraw0
to the end of/etc/rc.local
and it will do that automatically each boot.You then should be able to listen to the device. Run
cat /dev/hidraw0
and scan a valid QR/barcode. You should see what appear as random characters that don't make any sense, but if you see them - it's working. If not - check connections, permissions, paths, etc.pi@voron:~ $ cat /dev/hidraw0 �������(
Listener
I threw this listener together, it's not great code, but it does work. It's a NodeJS script. You can skip this and make on yourself, the Octoprint USB Keyboard plugins listener written in Python comes to mind as a viable alternative to get started. A bash script could work just as well.
Installation and initial setup
Install NodeJS and NPM if you haven't installed them before.
Create a project directory
If running on a Pi - a convoluted step is sort of required here. We'll be using the
node-hid
library for listening to the scanner, however it doesn't ship with binaries compatible with a Pi. On top of that we'll be usingnode-hid-stream
that utilizesnode-hid
. The convoluted part is thatnode-hid-stream
includesnode-hid
in a way that as far as I can tell doesn't offer a way to compile it on install.So we'll be manually installing
node-hid
, compiling the binary, installingnode-hid-stream
and then copying over the binaries to it's module directory..Listener
It is what it is. Copy this to
listener.js
. Change the scanner device path and printer IP if needed.Run the listener, wait for
start
to show up in console, scan something. It should show up as normal text and not the garbled mess from before.pi@voron:~/barcodeScanner $ node listener.js start 123456
You can try to scan a QR code that has
SM:SPOOL=<spool id>
as it's value. If successful you should see the command in the output, an OK response from Moonraker and your printer should beep.Run listener on boot
Install PM2
Start the listener via pm2
pm2 start ~/barcode/listener.js
Make pm2 run the listener on boot
You can view the output from the listener
And restart the listener if needed
Closing thoughts
I hope someone finds this useful in some way. I personally find this method for setting active spools much more preferable. Routinely I slice in SuperSlicer and directly Send & Print from without interacting with Mainsail at all, and I cannot be bothered to do this via my phone.
As this method essentially just sends gcode commands to Moonraker - it can be used to not just to set the active spool but to run any gcode you want. Perhaps turning on/off lights if you have them, heating up the bed, etc.
If you decide to write your own listener just be aware the scanner will output HID byte codes and not keystrokes. In turn you have to convert them to characters and strings. The format of the buffer is in my experience usually:
xx
- modifiers (shift, ctrl, etc.)yy
- key codeBeta Was this translation helpful? Give feedback.
All reactions