I changed to clogged_nozzl3's webcam mount on my Neptune 4pro printer recently but wanted to set the camera into fixed focus mode so it wouldn't keep getting fuzzy while the print head was moving. I wanted the printer to stay focused at the distance of the nozzle.
Over at the OpenNept4une Discord, user Aeros wrote how he managed to do it, which after some effort I got to work for me. So I've expanded that into more detailed instructions for others like me who aren't so fluent in Klipper's Linux command line. This may look like a lot to do, but it really isn't. Shouldn't take more than minutes.
(The stl of the knurled bolt/knob is one that I designed and is included here because Printables required a model file! And because if, like me, you bought your C920 used and the original owner had lost the original bolt!)
I'm pretty sure (but not completely sure) that this will work with other printers that use Klipper and likely also with C910, C922 and C930 cameras and maybe others.
You might need to install v4l2-ctl to your Klipper setup if it's not there already, but if so it's easy -- see https://medium.com/@petehouston/install-v4l-utils-on-debian-based-distros-d4f5c2fdcf61
In the following, the words in square brackets [] are directions for you, not the computer! I'm using Windows to log into the printer with ssh or PuTTY, you'll need different tools to do that if you are in another system.
So, without further ado:
________________________________________________________________________________________________
[Use ssh or putty app to log into [email protected].?.? (use your printer's IP address)]
[The password is "makerbase". You'll be asked for this several times during the process]
[Execute the following line, the prompt should look something like "mks@znp-k1:~$"]
v4l2-ctl --list-devices
[if that responds with an error message, you need to first install v4l2-ctl ! ]
[Otherwise, determine which video# corresponds with your camera. Mine is "video3"]
[It will probably be the first one that appears under your webcam's name.]
[Or you can find out by trial-and-error with the following two lines.]
[See which video# works on your cam:]
v4l2-ctl -d /dev/video3 --set-ctrl=focus_automatic_continuous=0
v4l2-ctl -d /dev/video3 --set-ctrl=focus_absolute=255
[once you know the video#, do the following commands:]
mkdir custom_scripts
cd custom_scripts
[The prompt should change to "mks@znp-k1:~/custom_scripts$"]
sudo nano webcam_set.sh
[Nano editor opens]
[Use Ctrl-C here to copy the following (what is between the dashed lines):]
----------------------
#!/bin/bash
v4l2-ctl -d /dev/video3 --set-ctrl=focus_automatic_continuous=0
v4l2-ctl -d /dev/video3 --set-ctrl=focus_absolute=40
----------------------
[Go back to the nano editor in the terminal and paste that in with a mouse right-click]
[You may need to change that last number (40) for "focus_absolute" for your camera position.]
[It should be between 0 (very far) and 250 (very close).]
[Some other lines you can optionally put in with the above to control contrast and brightness]
[between 0 and 255, nominally 128:]
----------------------
v4l2-ctl -d /dev/video3 --set-ctrl=contrast=32
v4l2-ctl -d /dev/video3 --set-ctrl=brightness=140
----------------------
[Then use Ctrl-X and "Y" to exit and save, and accept the file name]
[Execute these two lines:]
chmod +x /home/mks/custom_scripts/webcam_set.sh
cd\
[use Enter key twice. The prompt should go back to "mks@znp-k1:~$"]
cd /etc/systemd/system/
[The Prompt should change to "mks@znp-k1:/etc/systemd/system$"]
sudo nano webcam-setup.service
[Nano editor opens]
[Use Ctrl-C here to copy this (between the dashed lines):]
-------------------------------
[Unit]
Description=Set webcam parameters
After=multi-user.target
[Service]
Type=oneshot
ExecStart=/home/mks/custom_scripts/webcam_set.sh
RemainAfterExit=yes
[Install]
WantedBy=multi-user.target
------------------------------
[go back to the nano editor and paste all that in with a right-click]
[then use Ctrl-X and "Y" to exit and save, and accept the file name]
[execute in the terminal:]
sudo systemctl daemon-reexec
sudo systemctl daemon-reload
sudo systemctl enable webcam-setup.service
[Exit the terminal]
[Then reboot the printer, the focus should hold now]
[…If you need to change the focus range, contrast or brighntess, ]
[ use ssh or PuTTY and Nano to edit:]
sudo nano ~/custom_scripts/webcam_set.sh
The author marked this model as their own original creation.