Plugin to control arducam motorized focus?

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

#!/usr/bin/env python
import smbus
import pprint
bus = smbus.SMBus(0)
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 1
python 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
#!/usr/bin/env python
import sys
import smbus
import pprint

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

python 1

python 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 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 program:

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

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

bus = smbus.SMBus(0)
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 program works.

So I edited my
"/home/pi/oprint/lib/python3.7/site-packages/ArduCamFocus/" script and changed the following
self.bus = smbus.SMBus(0)
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.


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 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


I use the plugin put out by arducam directly and it worked last time I tried it after finding one fix on the system side. I updated the instructions on the plugin's listing accordingly.

talking about the link to github in thread history cause I tried that too. I think I might be updating wrong config.txt maybe. I pulled sd card out of pi put in reader and added the lines to the config on the sd card...Is that the right one??? First pi never messed with before couple days ago so bear with me. I am having to do a lot of googling to keep up...

I think I may have found it, I did not do this part till just now...
sudo raspi-config

after fighting with this for a day, I finally got past unable to use smbus now I am getting

Trouble accessing camera. I2C bus failure. Is camera plugged in?
I have a pic on the app so YES camera is plugged in you goofy plugin...

Ok, Finally got it changing SMBus(0) to (10) did the trick.

I am new to all of this, so I'm sorry if this is obvious - but how would I go about to edit the file? Would I be able to edit it via SSH using Putty? Thank you so much!

I won't do this to code from someone else.
With the next update your changes are gone...
Better get in contact with the author and discuss an optimization by them. (Github)