Plugin to control arducam motorized focus?

The ArduCamFocus is specifically written for a pi camera called, "ArduCam motorized focus camera" IMX219.
https://www.arducam.com/docs/cameras-for-raspberry-pi/motorized-focus-camera/

I don't think any other camera will be supported. Does the 8MP IMX21 have any focus capability? If so, please send documentation and I'll see if I can add support.

FYI, as far as the instructions I sent: the "sudo" command is the same as "su" but only for the single instruction. If you did not copy and paste those instructions all-at-once, then it won't work.

Hi Mike, yes it's a IMX219, sorry, I forgot the 9 :slight_smile: ! Thanks for the clarification, anyway I added the lines to my config.txt. Still is not working. Is there any specific libraries that need to be installed on Octopi? FYI when I run a i2cdetect -y 0 I have a 0x10, 0x64 and 0x0C.

please send your config.txt

# For more options and information see
# http://rpf.io/configtxt
# Some settings may impact device functionality. See link above for details

# uncomment if you get no picture on HDMI for a default "safe" mode
#hdmi_safe=1

# uncomment this if your display has a black border of unused pixels visible
# and your display can output without overscan
#disable_overscan=1

# uncomment the following to adjust overscan. Use positive numbers if console
# goes off screen, and negative if there is too much border
#overscan_left=16
#overscan_right=16
#overscan_top=16
#overscan_bottom=16

# uncomment to force a console size. By default it will be display's size minus
# overscan.
#framebuffer_width=1280
#framebuffer_height=720

# uncomment if hdmi display is not detected and composite is being output
#hdmi_force_hotplug=1

# uncomment to force a specific HDMI mode (this will force VGA)
#hdmi_group=1
#hdmi_mode=1

# uncomment to force a HDMI mode rather than DVI. This can make audio work in
# DMT (computer monitor) modes
#hdmi_drive=2

# uncomment to increase signal to HDMI, if you have interference, blanking, or
# no display
#config_hdmi_boost=4

# uncomment for composite PAL
#sdtv_mode=2

#uncomment to overclock the arm. 700 MHz is the default.
#arm_freq=800

# Uncomment some or all of these to enable the optional hardware interfaces
#dtparam=i2c_vc=on
#dtparam=i2c_arm=on
#dtparam=i2c0=on
#dtparamc=i2s=on
#dtparam=spi=on

# 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

[pi4]
# Enable DRM VC4 V3D driver on top of the dispmanx display stack
dtoverlay=vc4-fkms-v3d
max_framebuffers=2

[all]
#dtoverlay=vc4-fkms-v3d
# enable raspicam
start_x=1
gpu_mem=128

#ArduCamFocus
dtparam=i2c_vc=on
dtparam=i2c_arm=on

thank you. the config.txt appears correct. The original version of ArduCamFocus exhibited the bug you are seeing. I know you must have done this, and I am guessing now. Please uninstall the plugin and reinstall from this address:

https://github.com/moof-src/ArduCamFocus/archive/master.zip

The heart of the code that changes the focus is an i2c command sent in the OctoPrint python code. Here is a small python test program that will set the focus to a fixed value.

$ python test.py
<smbus.SMBus object at 0xb6785770>

It prints the value of the SMBus object to see if it was acquired properly. It then attempts to change the focus.

Put these lines below in a file called test.py and see if you get a similar output:

@moof attachments from email replies don't make it to the forum post I don't think.

Put these lines below in a file called test.py and see if you get a similar output:

#!/usr/bin/env python
import smbus
import pprint
bus = smbus.SMBus(0)
pprint.pprint(bus);
bus.write_byte_data(0xc, 0x06, 0x40)

Hi Mike,
I uninstalled the plugin and manually installed IT from the .zip file you sent.
I also ran the test and I got this: <smbus.SMBus object at 0xb678e710>
Also I noticed one thing; after I rebooted my Raspberry PI, I ran your test and I got no results, then I ran an i2cdetect -y 0 and the map was empty, I ran it again and then it got populated with the values I sent you already. BTW, I still have the arrow greyed out, so no luck so far but hey, thank you so much for helping me out with this issue, at least I'm learning something new! :slight_smile:

I've never seen the i2cdetect do that. That's mysterious. You might do some google searches on that. In the meantime, it appears that the small test did do something. Here's a sample app that will let you send a focus value to the camera from the command line. try numbers between 1 and 1023 like this:
python test.py 1
python test.py 500
you should see a change in the camera. If the camera is installed correctly, you should be able to open a web browser to port :8080 and see. On a MAC, I can access my camera with this URL: http://octopi3.local:8080/

When I repeatedly run the test alternating numbers 1 and 500, the image below the word "Stream" changes. Let's see if your camera is at least responding.

python code to put into test.py:
#!/usr/bin/env python
import sys
import smbus
import pprint

bus = smbus.SMBus(0)
pprint.pprint(bus);
focus = int(sys.argv[1])
bus.write_byte_data(0xc, (focus>>4)&0xff, (focus<<4)&0xff)

python test.py 1

python test.py 500

Maybe your raspberry pi is not getting enough power? many people have mentioned weird behavior on older 2b models?

I ran your test and I'm able to pass a value and changing the focus manually, still the arrows are greyed out but at least now I can set the focus on my 3d printer. I'd love to know why the plugin doesn't work on my configuration, that's weird. I can use the OctoPrint stream to check the focus, I also tried the 8080 port and it works too.


Thanks to your code snippet at least I can use the camera now at least!

All the control buttons are disabled in your view there. Are the buttons enabled when you aren't printing and connected to the printer?

Just took a quick look at the code and your printer has to be connected and in an operational state for the buttons to be enabled.

Ah ok, then I'll try later, my printer is in the garage and it gets hot so I was testing inside the house. Thanks for the clarification. Maybe I made up a problem that didn't even exist but at least I learned a tons thanks to you guys, really appreciate the support. Maybe include a disclaimer about this behavior?

glad we got it working

Halelujah! This finally got my Arducam OV5647 to focus AND I can see the result immediately in Octoprint. All previous attempts to use the Plugin failed as described in posts here. Buttons greyed, clicking them does nothing. Also, attempts to run the canned scripts provided by Arducam all failed as well with either "file not found" error or something to do with a keyboard; ELFCLASS32. The folks at Arducam claimed it was Octoprint interfering but the test.py script here works just fine and the results are being viewed in Octoprint sooooo....
Anyway, now to add some buttons in Octoprint to control focus.

1 Like

I just ran into a problem with the plugin that needed changing. I installed the ArduCam on my OctoPi and I was able to change the focus with the tools provided by Arducam, but I was getting

"Trouble accessing camera. I2C bus failure. Is camera plugged in?"

When trying to run "ArduCam Focus". I looked all over the place and then listed my i2c devices here:

$ ls -l /dev/i2c*

crw-rw---- 1 root i2c 89, 0 Mar 26 16:40 /dev/i2c-0
crw-rw---- 1 root i2c 89, 1 Mar 26 16:40 /dev/i2c-1
crw-rw---- 1 root i2c 89, 10 Mar 26 16:40 /dev/i2c-10
crw-rw---- 1 root i2c 89, 11 Mar 26 16:40 /dev/i2c-11

And noticed there was nothing on /dev/i2c-0 and /dev/i2c-1 with the following command gave me those devices too.

$ i2cdetect -l
i2c-1 i2c bcm2835 (i2c@7e804000) I2C adapter
i2c-11 i2c bcm2835 (i2c@7e205000) I2C adapter
i2c-0 i2c i2c-11-mux (chan_id 0) I2C adapter
i2c-10 i2c i2c-11-mux (chan_id 1) I2C adapter

With the test.py program:

#!/usr/bin/env python
import smbus
import pprint
bus = smbus.SMBus(0)
pprint.pprint(bus);
bus.write_byte_data(0xc, 0x06, 0x40)

Did not work for me and I had to change the following line

from
bus = smbus.SMBus(0)
to
bus = smbus.SMBus(10)

I'm not sure what's on the 0 bus but it will not work for me. But after changing to bus "10", the test.py program works.

So I edited my
"/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/__init__.py" script and changed the following
self.bus = smbus.SMBus(0)
to
self.bus = smbus.SMBus(10)

Now the "ArduCam Focus" plugin works great! I will be happy to work with you to share my Octopi's configs and anything else you need.

2 Likes

I'm just hopping in to say that I was experiencing the same error and it was driving me crazy. I went straight into the init.py file, made your suggested change, and it now works perfectly! Thank you for this information!

Ok itt seems im having the same issue, I have added the lines in ssh and get this
-bash: /boot/config.txt: Permission denied
I added them thru the telnet interface and double checked they are there.
I deleted and downloaded the plugin from the link you provided in another reply. Still same
I get the unable to use SMBus/I2C

This is driving me insane.
I even reinstalled octopi
Not sure what else to do
any suggestions

Chris