warpstar22
Posts: 10
Joined: Mon Jun 03, 2019 10:59 pm

Raspberry Pi Camera I2C Resource Conflict (?)

Mon Jan 20, 2020 7:20 pm

Hi,

I am building a prototype with Raspberry Pi. I have a TOF sensor using i2c that will record a distance. When an object is within a certain range measured by the TOF sensor, some LEDs will light up and a camera will capture. It has been working fine except with a few minor bugs. I then tried to use this with ArduCAM's motorized camera (https://www.arducam.com/docs/cameras-fo ... cus-camera) so that we can focus the camera depending on the distance. I've already talked with ArduCAM's support and have been unable to resolve this issue with them.

The problem is that there seems to be some sort of resource conflict when I am trying to capture. The process goes that I will find the distance, focus the camera, and then capture. It works fine but every now and then my application gets stuck. If I kill the process with sudo kill -9, I am unable to restart the application. When I do, my TOF sensor will not be able to start up. If I kill the process again, ps aux will show that the program is stuck in D state. According to this https://unix.stackexchange.com/a/5648, I am stuck waiting for some kernel call. I never encountered this problem prior to adding this device to my application. I have also not been using the I2C interface so close to capturing the image. This leads me to believe the issue is somewhere in I2C. In talking with ArduCAM, they don't think the problem is on their end or in my code controlling the focusing. Anytime this issue occurs, I have to use the magic sysrq key to reboot the Pi.

To interface with the camera, I am using this: https://sourceforge.net/projects/raspicam/ with version 0.1.6.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 8123
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: Raspberry Pi Camera I2C Resource Conflict (?)

Tue Jan 21, 2020 9:28 am

Which I2C bus is your TOF sensor connected to?

i2c-0 is designated as i2c_vc (VideoCore) for a reason, as it is nominally assigned to the VideoCore GPU for its exclusive use.
Arducam are already being a little optimistic with their use of i2c_vc for the AF actuator, as you've now got two processors both responding to interrupts and trying to configure the one peripheral. Trying to do "live" autofocus whilst the camera is running is likely to cause collisions between exposure/gain setting and AF(*)

It's also worth saying that the GPU will alter the pinmuxing for i2c-0 as it requires (remember it believes it has exclusive use of it), and the camera is not connected to the externally available GPIOs 0&1 muxing for i2c-0.
If your sensor is connected to i2c-1 (GPIOS 2&3), then there should be no conflict.

(*) I'm expecting HermannSW to pipe up and say he's never had issues, but it is likely to cause unpredictable behaviour.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

warpstar22
Posts: 10
Joined: Mon Jun 03, 2019 10:59 pm

Re: Raspberry Pi Camera I2C Resource Conflict (?)

Tue Jan 21, 2020 7:56 pm

My TOF sensor is connected to i2c-1. So I guess the issue isn't related to my sensor.

I'm also not doing any exposure gain or anything before capturing. I set those manually once when the camera is opened.

So is it likely that this is just a bug on ArduCAM's part? Or more of an issue since they are using the same bus that the camera interface is using?

One more thing:
I was trying to find the exact function where the conflict occurs. I used a bunch of print statements and when using endl, the buffer is flushed each time. The problem didn't occur when I had a bunch of print statements. And I'd be guessing that is some extra delay between the control of the focusing and when the GPU grabs the image so there isn't likely a conflict. I've already got a 200ms delay (using bcm2835 API) between focusing and capturing but that doesn't seem to be stopping the issue or maybe it is keeping it from being less frequent. Could that be the reason? I'm just trying to wrap my head around this. And if this is the reason, does that mean there is no solution unless ArduCAM changed the way they controlled the motor?
Last edited by warpstar22 on Thu Jan 23, 2020 6:58 pm, edited 1 time in total.

warpstar22
Posts: 10
Joined: Mon Jun 03, 2019 10:59 pm

Re: Raspberry Pi Camera I2C Resource Conflict (?)

Tue Jan 21, 2020 11:32 pm

So I tried to simplify my application and now I don't encounter the issue.
The other things involved will be some threading and using PWM for LEDs. I don't think these would cause issues. The partial process described in the original post is not threaded at all. And the LEDs would only be changed before and after that part. Also I wouldn't think that the GPIO pins would cause something with the camera to get stuck. Could it just be that I'm also doing a lot for the Raspberry Pi and then something is going wrong under all that?

Return to “Interfacing (DSI, CSI, I2C, etc.)”