posts projects about

Подключение камеры к Raspberry Pi Zero W

20 февраля 2018 г. raspberry_pi

Приехала камера с Aliexpress для подключения к Raspberry Pi через разъем DSI. Пока подключал прошел по некоторым “граблям”. Расскажу подробней.

Подключение и настройка

Камера из вот этого набора.

Подключил камеру к DSI разъему и пошел в утилиту raspi-config. В ней, в разделе Interfaces options есть пункт P1 Camera которая включает этот разъем в системе.

raspi-config

После включения можно попробовать воспользоваться утилитой raspistill. Это простая консольная программа для снятия изображения с камеры. Для видео также есть raspivid. В Raspbian она есть уже “из коробки”, для других дистрибутивов, возможно, потребуется установить:

#apt-get install libraspberrypi-bin

Однако с ходу получить изображение с камеры не получилось. Ругается:

#raspistill -o img1.jpg
mmal: Cannot read camera info, keeping the defaults for OV5647
mmal: mmal_vc_component_create: failed to create component 'vc.ril.camera' (1:ENOMEM)
mmal: mmal_component_create_core: could not create component 'vc.ril.camera' (1)
mmal: Failed to create camera component
mmal: main: Failed to create camera component
mmal: Camera is not enabled in this build. Try running "sudo raspi-config" and ensure that "camera" has been enabled

Смотрим определяется ли камера в системе:

#vcgencmd get_camera
supported=0 detected=0

Если нет, то скорее всего должно помочь обновление firmware. Обновляю:

#rpi-update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** Performing self-update
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100 13403  100 13403    0     0  30595      0 --:--:-- --:--:-- --:--:-- 30670
 *** Relaunching after update
 *** Raspberry Pi firmware updater by Hexxeh, enhanced by AndrewS and Dom
 *** We're running for the first time
 *** Backing up files (this will take a few minutes)
 *** Backing up firmware
 *** Backing up modules 4.9.41+
#############################################################
This update bumps to rpi-4.9.y linux tree
Be aware there could be compatibility issues with some drivers
Discussion here:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=167934
##############################################################
 *** Downloading specific firmware revision (this will take a few minutes)
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   168    0   168    0     0    196      0 --:--:-- --:--:-- --:--:--   196
100 54.1M  100 54.1M    0     0   750k      0  0:01:13  0:01:13 --:--:-- 1308k
 *** Updating firmware
 *** Updating kernel modules
 *** depmod 4.9.75-v7+
 *** depmod 4.9.75+
 *** Updating VideoCore libraries
 *** Using HardFP libraries
 *** Updating SDK
 *** Running ldconfig
 *** Storing current firmware revision
 *** Deleting downloaded files
 *** Syncing changes to disk
 *** If no errors appeared, your firmware was successfully updated to 9f5eea78c4776fe82511284754887187a22d78c7
 *** A reboot is needed to activate the new firmware

После обновления - ребут, и камера начинает работать:

#vcgencmd get_camera
supported=1 detected=1

#raspistill -o img1.jpg

Изображение с камеры выводится на экран: raspberry pi camera image

Здесь подробная документация про raspistill: https://www.raspberrypi.org/app/uploads/2013/07/RaspiCam-Documentation.pdf

Также можно пользоваться python-библиотекой picamera для работы с Rpi камерой: http://picamera.readthedocs.io/en/release-1.12/install.html