picar-X: setup, vilib, & camera issues

Greetings,

I’m new. I’m a novice, too. Pi5 + picar-x ai cam. I’ve followed the sunfounder tutorials, but have run into serious problems.

So, I’ve already done a new image and reinstall which came back to the same issue. As I’ve gone through the python tutorials, I hit a wall when I run example 7 with the camera. My first install, I actually had my controller app connect and fail to work with the camera. Anyways, I saw this forum thread…

There seems to be typos causing some troubles in the code. I checked my picarx.py file and found the same “_flie” error. Fixing the 3-4 typos in that file didn’t make the core problem go away in itself. I am not sure exactly what the next steps are here.

I need help.

I’m eager to both get the camera working and also see the sunfounder app work properly, so that I can move onto new projects. Any tips?

Here’s the log from running ~/picar-x//example/7.display.py

sudo python3 7.display.py
vilib 0.3.9 launching ...
picamera2 0.3.22
Local display failed, because there is no gui.

Web display on:
      http://192.168.1.22:9000/mjpg

Starting web streaming ...

Input key to call the function!
    q: Take photo
    1: Color detect : red
    2: Color detect : orange
    3: Color detect : yellow
    4: Color detect : green
    5: Color detect : blue
    6: Color detect : purple
    0: Switch off Color detect
    r: Scan the QR code
    f: Switch ON/OFF face detect
    s: Display detected object information

 * Serving Flask app 'vilib.vilib'
 * Debug mode: off
[1:08:28.344452443] [2811] ERROR RPI pipeline_base.cpp:1364 Camera frontend has timed out!
[1:08:28.344475016] [2811] ERROR RPI pipeline_base.cpp:1365 Please check that your camera sensor connector is attached securely.
[1:08:28.344480979] [2811] ERROR RPI pipeline_base.cpp:1366 Alternatively, try another cable and/or sensor.
Error on request:
Traceback (most recent call last):
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 335, in run_wsgi
    execute(self.server.app)
  File "/usr/lib/python3/dist-packages/werkzeug/serving.py", line 324, in execute
    for data in application_iter:
  File "/usr/lib/python3/dist-packages/werkzeug/wsgi.py", line 500, in __next__
    return self._next()
           ^^^^^^^^^^^^
  File "/usr/lib/python3/dist-packages/werkzeug/wrappers/response.py", line 50, in _iter_encoded
    for item in iterable:
  File "/usr/local/lib/python3.11/dist-packages/vilib-0.3.9-py3.11.egg/vilib/vilib.py", line 88, in gen
    frame = get_frame()
            ^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/vilib-0.3.9-py3.11.egg/vilib/vilib.py", line 70, in get_frame
    return cv2.imencode('.jpg', Vilib.flask_img)[1].tobytes()
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
cv2.error: OpenCV(4.10.0) :-1: error: (-5:Bad argument) in function 'imencode'
> Overload resolution failed:
>  - img is not a numpy array, neither a scalar
>  - Expected Ptr<cv::UMat> for argument 'img'

Traceback (most recent call last):
  File "/home/FigBot/picar-x/example/7.display.py", line 134, in <module>
    main()
  File "/home/FigBot/picar-x/example/7.display.py", line 94, in main
    key = readchar.readkey()
          ^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/readchar/_posix_read.py", line 37, in readkey
    raise KeyboardInterrupt

The same thing is now happening with my 2.keyboard_control.py

sudo python3 2.keyboard_control.py 
Traceback (most recent call last):
  File "/home/FigBot/picar-x/example/2.keyboard_control.py", line 27, in <module>
    px = Picarx()
         ^^^^^^^^
  File "/usr/local/lib/python3.11/dist-packages/picarx-2.0.5-py3.11.egg/picarx/picarx.py", line 71, in __init__
    self.cali_dir_value = self.config_flie.get("picarx_dir_motor", default_value="[1, 1]")
                          ^^^^^^^^^^^^^^^^
AttributeError: 'Picarx' object has no attribute 'config_flie'. Did you mean: 'config_file'?

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/FigBot/picar-x/example/2.keyboard_control.py", line 73, in <module>
    px.set_cam_tilt_angle(0)
    ^^
NameError: name 'px' is not defined

The flie typographical error is not a real issue as Sunfounder have been consistent in the misspelling. The last set of error messages suggest that you’ve made these edits in some files but not all. I’d suggest reinstalling originals

The error that you cross referenced was a user os compatability issue i.e
OSError: [Errno 6] No such device or address
Did you get this exact same error that you quoted? t’s unusual as usually caused by a process spawned by a service manager like init, systemd, or upstart.

You also get a “no local gui” error. From where are you running? Are you running headless?

The majority of errors in your 7.display.py are caused by the camera not taking the initial photo. Does the camera work from the command line?
libcamera-still -o test.jpg

This is what happens.

libcamera-still -o test.jpg
[0:01:36.783842988] [1942]  INFO Camera camera_manager.cpp:325 libcamera v0.3.2+27-7330f29b
[0:01:36.791383762] [1948]  INFO RPI pisp.cpp:695 libpisp version v1.0.7 28196ed6edcf 29-08-2024 (16:33:32)
[0:01:36.808574781] [1948]  INFO RPI pisp.cpp:1154 Registered camera /base/axi/pcie@120000/rp1/i2c@80000/ov5647@36 to CFE device /dev/media0 and ISP device /dev/media2 using PiSP variant BCM2712_C0
Preview window unavailable
Mode selection for 1296:972:12:P
    SGBRG10_CSI2P,640x480/0 - Score: 3296
    SGBRG10_CSI2P,1296x972/0 - Score: 1000
    SGBRG10_CSI2P,1920x1080/0 - Score: 1349.67
    SGBRG10_CSI2P,2592x1944/0 - Score: 1567
Stream configuration adjusted
[0:01:36.809597173] [1942]  INFO Camera camera.cpp:1197 configuring streams: (0) 1296x972-YUV420 (1) 1296x972-GBRG_PISP_COMP1
[0:01:36.809694510] [1948]  INFO RPI pisp.cpp:1450 Sensor: /base/axi/pcie@120000/rp1/i2c@80000/ov5647@36 - Selected sensor format: 1296x972-SGBRG10_1X10 - Selected CFE format: 1296x972-PC1g
[0:01:37.893543364] [1948]  WARN V4L2 v4l2_videodevice.cpp:2095 /dev/video4[16:cap]: Dequeue timer of 1000000.00us has expired!
[0:01:37.893571754] [1948] ERROR RPI pipeline_base.cpp:1364 Camera frontend has timed out!
[0:01:37.893576717] [1948] ERROR RPI pipeline_base.cpp:1365 Please check that your camera sensor connector is attached securely.
[0:01:37.893581551] [1948] ERROR RPI pipeline_base.cpp:1366 Alternatively, try another cable and/or sensor.
ERROR: Device timeout detected, attempting a restart!!!

The camera has been consistently off since my first installation. This is the ai camera with 22-pin MIPI connection, not the older one. I’ve assumed there is a simple solution somewhere in the code alignment and thus looked to find related problems.

I suppose the camera could be broken or defective. I don’t imagine that to be true, but it’s a possibility I hadn’t considered.

libcamera-still --version
rpicam-apps build: v1.5.2 a8ccf9f3cd9d 03-10-2024 (22:33:44)
libcamera build: v0.3.2+27-7330f29b
uname -a
Linux NAME 6.6.51+rpt-rpi-2712 #1 SMP PREEMPT Debian 1:6.6.51-1+rpt3 (2024-10-08) aarch64 GNU/Linux

I may try another clean install to undo all those “flie” changes. At that time, I may try to redo the board connection and recheck camera cable on the camera’s side (as it came attached).

Sorry, missed that it was AI cam

Have you installed the firmware?
sudo apt install imx500-all

Still surprised you’re not getting a preview window.

If that doesn’t help, Sunfounder will be back in the office tomorrow, and are far more knowledgeable than I

Please check whether the camera wiring is correct and ensure that the connection direction is properly aligned.

After verifying the connections, restart the system and execute the command libcamera-hello to test the camera. This will help determine if the camera is being recognized properly.