Last active
June 11, 2023 02:37
-
-
Save sgeraldes/985ffa6044a407313388853576aa40cd to your computer and use it in GitHub Desktop.
Setting up Octoprint on a Raspberry Pi 4 (4GB) with touchscreen and 16MP Autofocus Arducam Camera (IMX519)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Download the lastest nightly of octoprint or use Raspberry Imager to burn the lastest nightly with the new camera module. | |
Https://unofficialpi.org/Distros/Octopi/nightly/ | |
Install it through an imager, just like normal octoprint image. | |
For your touchscreen (must be done first) | |
Sudo apt install xorg* | |
Than rest of your touchscreen stuff as normal. | |
Check if it works. And take a look in /boot/config.txt. | |
For camera to work in Boot/config.txt add | |
dtoverlay=imx519 | |
My Config.txt looks like this: | |
# Uncomment this to enable infrared communication. | |
#dtoverlay=gpio-ir,gpio_pin=17 | |
#dtoverlay=gpio-ir-tx,gpio_pin=18 | |
# Additional overlays and parameters are documented /boot/overlays/README | |
# Enable audio (loads snd_bcm2835) | |
dtparam=audio=on | |
# Automatically load overlays for detected cameras | |
camera_auto_detect=1 | |
# Automatically load overlays for detected DSI displays | |
display_auto_detect=1 | |
# Enable DRM VC4 V3D driver | |
dtoverlay=vc4-kms-v3d | |
max_framebuffers=2 | |
# Disable compensation for displays with overscan | |
disable_overscan=1 | |
[cm4] | |
# Enable host mode on the 2711 built-in XHCI USB controller. | |
# This line should be removed if the legacy DWC2 controller is required | |
# (e.g. for USB device mode) or if USB support is not required. | |
otg_mode=1 | |
[all] | |
[pi4] | |
# Run as fast as firmware / board allows | |
arm_boost=1 | |
[all] | |
# enable raspicam | |
start_x=1 | |
## total RAM gpu_mem recommended maximum | |
## 256MB 128 | |
## 512MB 384 | |
## 1GB or greater 512, 76 on the Raspberry Pi 4 | |
# for raspberry pi 4: | |
gpu_mem=76 | |
--- End of config.txt --- | |
Take all the commands and write them down or copy them in an other file. It can happen that they disappear after the next installations and than you can put them back in the file after all installations are done. | |
Than the Camera. | |
I used this guide | |
https://forum.arducam.com/t/using-libcamera-imx519-on-octopi/2272/2 | |
wget -O install_pivariety_pkgs.sh https://github.com/ArduCAM/Arducam-Pivariety-V4L2-Driver/releases/download/install_script/install_pivariety_pkgs.sh | |
chmod +x install_pivariety_pkgs.sh | |
./install_pivariety_pkgs.sh -p imx519_kernel_driver | |
It ask for reboot, select yes. | |
When rebooted | |
./install_pivariety_pkgs.sh -p libcamera | |
Note: Only if using an older version of octoprint use this one instead: | |
./install_pivariety_pkgs.sh -p libcamera_dev | |
./install_pivariety_pkgs.sh -p libcamera_apps | |
Check if it appears | |
Ls /dev/video* | |
Video 0 and 1 should be visible. | |
Than | |
libcamera-still -t 5000 -o test.jpg -n | |
It probably gives some errors, but as long it doesn't do nothing or say no camera found you are good. | |
Now for some reason, webcamd doesn't seem to be present. Two options, install webcamd and add as service, or: | |
git clone https://github.com/ArduCAM/mjpg-streamer.git mjpg-streamer-libcamera | |
cd mjpg-streamer-libcamera/mjpg-streamer-experimental | |
make | |
sudo install -m 755 _build/mjpg_streamer /opt/mjpg-streamer | |
sudo find _build -name "*.so" -type f -exec install -m 644 {} /opt/mjpg-streamer ; | |
sudo cp -a -r ./www /opt/mjpg-streamer | |
sudo chmod 755 /opt/mjpg-streamer/www | |
sudo chmod -R 644 /opt/mjpg-streamer/www | |
Than | |
Sudo nano /boot/octopi.txt | |
On the bottom at the next lines. The -r or -f can be changed for you to play with. | |
camera="libcamera" | |
camera_libcamera_options="-r HD -afmode continuous -afrange macro" | |
camera_http_webroot="./www" | |
camera_http_options="" | |
Save the file. In the link of the guide is also mentioned what you can change and how for those commands. But this worked for me. | |
Here are some options for camera_libcamera_options. Use ./mjpg_streamer -i "input_libcamera.so -h" to see what they are. | |
MJPG Streamer Version: git rev: 0c03adde834bbd949bfa8f78f89a0b305d8001fe | |
--------------------------------------------------------------- | |
Help for input plugin..: Libcamera Input plugin | |
--------------------------------------------------------------- | |
The following parameters can be passed to this plugin: | |
[-r | --resolution ]...: the resolution of the video device, | |
can be one of the following strings: | |
QQVGA QCIF CGA QVGA CIF PAL | |
VGA SVGA XGA HD SXGA UXGA | |
FHD | |
or a custom value like the following | |
example: 640x480 | |
[-c | --camera ].......: Chooses the camera to use. | |
[-f | --fps ]..........: frames per second | |
[-b | --buffercount ]...: Set the number of request buffers. | |
[-q | --quality ] .....: set quality of JPEG encoding | |
[-rot | --rotation]....: Request an image rotation, 0 or 180 | |
[-s | --snapshot ] .....: Set the snapshot resolution, if not set will default to the maximum resolution. | |
--------------------------------------------------------------- | |
Optional parameters (may not be supported by all cameras): | |
[-br ].................: Set image brightness (integer) | |
[-co ].................: Set image contrast (integer) | |
[-sa ].................: Set image saturation (integer) | |
[-ex ].................: Set exposure (integer) | |
[-gain ]...............: Set gain (integer) | |
[-afmode]..............: Control to set the mode of the AF (autofocus) algorithm.(manual, auto, continuous) | |
[-afrange].............: Set the range of focus distances that is scanned.(normal, macro, full) | |
[-lensposition]........: Set the lens to a particular focus position, expressed as a reciprocal distance (0 moves the lens to infinity), or "default" for the hyperfocal distance --------------------------------------------------------------- | |
input_init() return value signals to exit | |
Now: Let's install webcamd service | |
cd ~ | |
sudo mv /root/bin/webcamd /root/bin/webcamd.bak | |
sudo wget -O webcamd https://github.com/ArduCAM/mjpg-streamer/releases/download/v1.0.0/webcamd | |
sudo mv webcamd /root/bin/ | |
sudo chmod 755 /root/bin/webcamd | |
Don't reboot yet as stated in the guide. | |
Sudo nano /boot/config.txt | |
Check if your touchscreen parameters are still present or otherwise add them again | |
Also under [all] add or change, note the cma can be changed lower or higher, but this is max for pi zero 2. It can also work if you remove the ,cma-128 on a pi 4 with more ram | |
dtoverlay=vc4-fkms-v3d,cma-128 | |
dtoverlay=imx519 ( should be there already) | |
Save and exit. | |
Now would be time setup the connection to your printer if needed. Mine is setup through GPIO pins, so I don't know how it should be done through USB. | |
After that | |
sudo reboot | |
After reboot open octoprint server in you webbrowser Camera should already be working now. | |
Goto settings --> plugin manager --> get more. | |
On the bottom is "from URL" | |
https://github.com/The-EG/OctoPrint-CameraSettings/archive/main.zip | |
And install. | |
Now you have a plugin accessible from the setting menu to focus the camera manually. | |
Have fun, hopefully this works for you aswell. Also if somethings written a bit in weird english or grammer errors, it is not my native language, just ask if you don't understand. | |
Credits to the people of octoprint and wong on the arducam forum. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment