How to use camera in Ubuntu Core18

Hello

How to use the camera function in Ubuntu Core 18 RPi ?.

Currently in my snap I have a plug for camera, then I set the interface using: snap connect dkentry-python3:camera.

I was expecting to see device node: /dev/video0, but it was not created.

Note: I was able to use the camera with Rasbian.

Thanks

what kind of camera is this ? USB cameras should be detected automatically by the kernel, the /dev/video0 node should exist right after boot.

if you are using a raspberry camera directly attached throught the ribbon cable, you need to enable this in the firmware, you can do this by running:

snap set system start_x=1
sudo reboot

and the camera should be detected after reboot …

$ snap set system start_x=1
error: cannot perform the following tasks:

  • Run configure hook of “core” snap (invalid option name: “start_x”)

What is the “Run configure hook”, this file is empty
/snap/core/current/meta/hooks/configure

hmm, strange, could you try

snap set system pi-config.start_x=1

instead … ?

if this also does not work this sounds like a bug, effectively the option only edits /boot/uboot/config.txt so as a workaround you can just edit the file by hand and add start_x=1 to it …

Same problem when using the below:
$ snap set system pi-config.start_x=1
error: cannot perform the following tasks:

  • Run configure hook of “core” snap (invalid option name: “start_x”)
    $ snap set core pi-config.start_x=1
    error: cannot perform the following tasks:
  • Run configure hook of “core” snap (invalid option name: “start_x”)

Not sure were the configuration problem is ?
$ snap version
snap 2.42.5
snapd 2.42.5
series 16
kernel 4.4.0-1127-raspi2

I will edit the config.txt manually for now.

What interface should I look for when using the Raspberry camera ?.

for a quick test and as basic example you can try my picamera-streaming-demo snap:

source is at:

IIRC the CSI camera is directly accessible via /dev/vchiq (or friends), that should be fully accessible through the opengl interface, but if in doubt, also add the camera one.

Hello
After changing the config.txt, I do see /dev/vchiq

But after installing picamera-streaming-demo, the demon errors out at start, see below

Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: mmal: mmal_vc_component_create: failed to create component ‘vc.ril.camera’ (1:ENOMEM)
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: mmal: mmal_component_create_core: could not create component ‘vc.ril.camera’ (1)
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: Traceback (most recent call last):
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/camera.py”, line 456, in _init_camera
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: self._camera = mo.MMALCamera()
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/mmalobj.py”, line 2279, in init
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: super(MMALCamera, self).init()
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/mmalobj.py”, line 633, in init
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: prefix=“Failed to create MMAL component %s” % self.component_type)
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/exc.py”, line 184, in mmal_check
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: raise PiCameraMMALError(status, prefix)
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: picamera.exc.PiCameraMMALError: Failed to create MMAL component b’vc.ril.camera’: Out of memory
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: During handling of the above exception, another exception occurred:
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: Traceback (most recent call last):
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/bin/pistream”, line 82, in
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: with picamera.PiCamera(resolution=‘1280x720’, framerate=24) as camera:
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/camera.py”, line 431, in init
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: self._init_camera(camera_num, stereo_mode, stereo_decimate)
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: File “/snap/picamera-streaming-demo/1/lib/python3.5/site-packages/picamera/camera.py”, line 460, in _init_camera
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: "Camera is not enabled. Try running ‘sudo raspi-config’ "
Jan 9 06:34:14 localhost picamera-streaming-demo.pistream[11117]: picamera.exc.PiCameraError: Camera is not enabled. Try running ‘sudo raspi-config’ and ensure that the camera has been enabled.
Jan 9 06:34:14 localhost systemd[1]: snap.picamera-streaming-demo.pistream.service: Main process exited, code=exited, status=1/FAILURE
Jan 9 06:34:14 localhost systemd[1]: snap.picamera-streaming-demo.pistream.service: Unit entered failed state.
Jan 9 06:34:14 localhost systemd[1]: snap.picamera-streaming-demo.pistream.service: Failed with result ‘exit-code’.
Jan 9 06:34:14 localhost systemd[1]: snap.picamera-streaming-demo.pistream.service: Service hold-off time over, scheduling restart.
Jan 9 06:34:14 localhost systemd[1]: Stopped Service for snap application picamera-streaming-demo.pistream.
Jan 9 06:34:14 localhost systemd[1]: Started Service for snap application picamera-streaming-demo.pistream.

FYI there is also a permissions error at the start of the demon
Jan 10 04:58:16 localhost systemd[1]: Started Service for snap application picamera-streaming-demo.pistream.
Jan 10 04:58:17 localhost kernel: [47663.875817] audit: type=1400 audit(1578632297.683:14138): apparmor=“DENIED” operation=“open” profile=“snap.picamera-streaming-demo.pistream” name="/proc/15351/mounts" pid=15351 comm=“python3” requested_mask=“r” denied_mask=“r” fsuid=0 ouid=0

to make the denial go away, check with snap connections picamera-streaming-demo if you did not forget to connect all the interfaces, connect them using the snap connect picamera-streaming-demo:<interface name>

though the syslog output looks like the camera is either not a CSI camera or start_x is not set correctly since it still claims that it is not enabled/found …

here is a tutorial, perhaps that helps to find the issue:

OK
I think I will start over and use the image the link you provided is using ubuntu-core-18-armhf+raspi3.img.xz.
I started with ubuntu-core-16-armhf+raspi3.img.xz, then added core18 snap.

And sense the camera works with Raspian the hardware should be ok.

1 Like

Hello

After installing the latest “Ubuntu Core 18” ubuntu-core-18-armhf+raspi3.img.xz

I setup the account, and was able to boot, and remote login “no problems”

I then changed the config and added start_x=1, according to https://ubuntu.com/blog/getting-started-with-ubuntu-core-streaming-video-from-a-raspberry-pi

And now at boot the rainbow screen comes up. If I then remove the start_x=1, it boots ok.

The other commands still do not work:
snap set system start_x=1
snap set system pi-config.start_x=1

Both give the error below
error: cannot perform the following tasks:
Run configure hook of “core” snap (invalid option name: “start_x”)

Thanks ogra

If got it to work, i set my config.txt to:
disable_splash=1
start_debug=1
start_x=1

I was then able to see the cursor on top of the screen blinking during boot ( probability load software ).
After install of picamera-streaming-demo, it worked.

1 Like

i did some more research today, seemingly the underscore is the issue here:

ogra@pi4:~$ grep start_x /boot/uboot/config.txt 
ogra@pi4:~$ snap set system pi-config.start_x=1
error: cannot perform the following tasks:
- Run configure hook of "core" snap (invalid option name: "start_x")
ogra@pi4:~$ snap set system pi-config.start-x=1
ogra@pi4:~$ grep start_x /boot/uboot/config.txt 
start_x=1
ogra@pi4:~$

obviously using a dash works fine …

additionally start_debug=1 should not be needed at all and AFAIK our images default to disable_splash=1, not sure how you had it unset in your image …