Error when attempting to use C++ raspicam API

I am using https://github.com/cedricve/raspicam API for a project which uses Raspicam. I generate a binary of my C++ project and run it in the end using CMD. I am getting the following error:

[Logs]    [9/25/2020, 9:47:13 AM] [camera-test] Opening Camera...
[Logs]    [9/25/2020, 9:47:13 AM] [camera-test] Failed to set I2C address
[Logs]    [9/25/2020, 9:47:13 AM] [camera-test] Sleeping for 3 secs
[Debug]   Device state not settled, retrying in 1000ms
[Debug]   Device state not settled, retrying in 1000ms
[Logs]    [9/25/2020, 9:47:16 AM] [camera-test] Measuring fps ... 
[Live]    Device state settled
^C[Live]    Cleaning up device...

Raspicam is supposed to take screenshots after printing Measuring fps ... but the program just hangs after that. You can also see I get Failed to set I2C address.

I want to use a 32-bit system as I am also using some older version of libraries which do not support 64 bit. Balena OS version I am using is: Raspberry Pi 3 BalenaOS 2.58.3+rev1 armv7hf development. The base image I am using is balenalib/raspberrypi3-debian. I used all the steps mentioned in the docs to make use of Raspicam and i2c. Here is my docker-compose file:

version: "2"
services:
  camera-test:
    build:
      context: .
      dockerfile: Dockerfile.balena
    privileged: true
    restart: always
    network_mode: "host"
    labels:
      io.balena.features.kernel-modules: '1'

And here is the CMD command I am using to run the binary in Dockerfile:

CMD modprobe i2c-dev && /bin/camera-test

Any help would be appreciated. Thanks in advance.

Hey there Prateek,

I used all the steps mentioned in the docs to make use of Raspicam and i2c

Can you please confirm you are referring to these instructions I2C and Other Interfaces - Balena Documentation ?

How did you set it up? It seems like your device is in local mode, so perhaps the variables were not applied?

Could you also please describe what i2c being used in your program? Are you trying to retrieve the camera info?

Perhaps you could share your dockerfile?

Thanks

Hey @rahul-thakoor. I actually got it working. The issue was with my code. Thanks a ton.

Though the fact that variables are not applied in local mode simply by editing /boot/config.txt as those variables are written in the first boot itself in the supervisor should be mentioned in the docs. I only found it in one of the other answers in the forums. If it already is in docs, feel free to ignore it.

Awesome project though. Keep it up, peeps !!!

He Prateek,

More information about working in local mode here:

Phil

After I run a container, and reboot my pi after that, and push the same container again, it hangs on:

[Live]    Waiting for device state to settle...
[Info]    Streaming device logs...
[Live]    Watching for file changes...
[Debug]   Device state not settled, retrying in 1000ms
[Live]    Device state settled

And does not execute the shell script file. Any idea about this?

Hey there,
Can you please clarify which shell script? It looks like you are running a binary from the Dockerfile you provided? When in local mode, you should see logs if the service running is logging some.