Autofocus issues

Not sure if this is the place to post this since i don’t know if its a hardware or code issue but I figured I’d give it a go since I’m pretty lost.

I’m messing around with the code using B0121 camera and have successfully ran it and captured focused images. But now I’m trying to tweak the code such that it refocuses periodically whenever image clarity is reduced by X amount of frame. I thought this would be done by replacing the break in line 70 of the original code. But the camera won’t refocus after the initial autofocus.

Any insight or tips for this?


The current focusing scheme is implemented by software, and the speed of repeated refocusing will be very slow.


Thanks for the reply. So can it speed up through software? or is the speed limited?


Because the speed of software image processing is relatively slow, it has a lot to do with CPU performance.

Thanks for the reply!


Follow up questions which may be related;

I keep running into the issue where the camera cuts out after the initial autofocus and image capture. I have to manually unplug the camera to regain control and manually stop the script.

here is my setup:

the HDMI cables are needed for the end product


I’m not too sure what’s causing this issue but it’s only when I use the focusing functional. It doesn’t cut out when I do multiple image capture without it.



Due to the sensor and the focus motor share the same i2c bus, which will exist occupied.

I advise you disable the camera’s auto exposure and auto awb functions and retry.



I tried this but I am still getting the same issue. I’m able to refocus at a set time period but when i add in the camera capture into the code if causes the freeze up/display cut out. Is there a way to reset the camera after taking the image?


Due to the the sensor’s driver is on GPU instead of CPU, so we can’t change the driver directly.

So, at present, we can’t reset the camera. I’ll discuss it with my team and see what the solution is.


Thank you.


Another questions:

Is it possible to have the autofocus run over the CSI to HDMI Cable Extension and hdmi cable? Right now I just have the sda/scl on the camera connected directly to the raspberry pi but that won’t be possible in the end product i’m working on. Can I solder wires from the csi extension module to camara on one end and then do the same on the other csi module to the Pi? If so, would I just do pin A on the CSI module to SDA and B to SCL? And then pin a and b on the other csi module to the pi?


Of course, In fact On the CSI to HDMI cable extension board, There is a i2c0 interface and which can driver the sensor and the motor, You can remove the i2c1 connect line. Just use the i2c0. Using this demo

Notice you should enable the i2c0 using

Maybe using the same i2c0 can avoid your previous problems. You can try it.


Let me know if you need more help.



Thank you.

How exactly would i wire the module to the camera and the other module to the pi board? Which spots on the adapter board do I use for this?


Hello, Just need to connect the CSI cable to the camera CSI interface following here


Thank you for the reply. So no additional connections are needed from the camera or csi/hdmi extension to the pi (3b+) other than the csi connections ribbon to run the autofocus?

Yes, In fact, the focus motor and the sensor use the same i2c bus.