Dienstag, 30. Dezember 2014

RaspberryPI Webcam on Archlinux

This blog post describes how to set up the RaspberryPI camera and use it with Motion. Motion is a motion detecting web cam software.

As prerequisite we need a prepared SD card with the latest ArchLinux system.
The installation is described on http://archlinuxarm.org/platforms/armv6/raspberry-pi (tab Installation).

Insert the SDcard into the PI and power it.
Logon to the console with user/pwd root .

btw: My favorite editor is nano.

First we set a new password

Welcome to Arch Linux ARM

     Website: http://archlinuxarm.org
       Forum: http://archlinuxarm.org/forum
         IRC: #archlinux-arm on irc.Freenode.net
[root@alarmpi ~]# passwd
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
[root@alarmpi ~]#

Now we set a meanigful hostname for the PI to identify it easily on the network ( i normally do this right after preparing the SD card on my laptop to be able to easily ssh on to).

[root@alarmpi ~]# nano /etc/hostname

Change the name "alarmpi" to something else if you like. I call mine "flypi"
save with ^O and exit nano with ^X

Enabling the RaspberryPi Camera

Enabling the RaspberryPI camera is done via the boot configuration file /boot/config.txt

[root@alarmpi ~]# nano /boot/config.txt

Add the following line at the end of the file

#enable PI camera

save with ^O and exit nano with ^X

To have the camera as video device under /dev we need to make sure the the corresponding module (bcm2835-v4l2) is loaded at boot.

For this we edit /etc/modules-load.d/raspberrypi.conf

[root@alarmpi ~]# nano /etc/modules-load.d/raspberrypi.conf

Add the following line at the end of the file


save with ^O and exit nano with ^X

Now we reboot and check if the camera is enabled.

[root@alarmpi ~]# reboot now
Connection to alarmpi closed by remote host.
Connection to alarmpi closed.


Reconnect to console again.

Welcome to Arch Linux ARM
Last login: Tue Dec 30 09:30:13 2014 from xxxxxxx
[root@flypi ~]#

Check if the camera is enabled is done by checking if /dev/videox exists.

[root@flypi ~]# ls -l /dev/vid*
crw-rw---- 1 root video 81, 0 Dec 30 09:55 /dev/video0
[root@flypi ~]#

Lucky me, it's there! ;-)

Software update

Now it's time to bring all software packages to the latest version

[root@flypi ~]# pacman -Syu

Confirm all choices with Y. ..and wait until upgrade has been finished.

We install and enable the ntp package to have the correct time.

[root@flypi ~]# pacman -S ntp
resolving dependencies...
looking for inter-conflicts...

Packages (1): ntp-4.2.8-1

Total Download Size:    1.58 MiB
Total Installed Size:   3.76 MiB

:: Proceed with installation? [Y/n] Y
[root@flypi ~]# systemctl enable ntpd
Created symlink from /etc/systemd/system/multi-user.target.wants/ntpd.service to /usr/lib/systemd/system/ntpd.service.
[root@flypi ~]# systemctl start ntpd

[root@flypi ~]#

Installation and setup of Motion

[root@flypi ~]# pacman -S motion

Confirm all choices with Y. ..and wait until installation has been finished.

Now we reboot to be sure that all the latest software is running.

[root@alarmpi ~]# reboot now
Connection to flypi closed by remote host.
Connection to flypi closed.


Reconnect to console again.

Edit configuration

Change into the Motion config directory /etc/motion and backup the original config

[root@flypi ~]# cd /etc/motion
[root@flypi motion]# cp motion.conf motion.conf.old
[root@flypi motion]# 

Edit the configuration file

[root@flypi motion]# nano motion.conf

Depending on the orientation of the camera module you need to change rotate from 0 to 180°:

rotate 180

Change the directory where images/video is saved according your needs. I like mine to be saved under /srv/http.

target_dir /srv/http

If you like you can change the http port to 80. This allows you to access the live picture with the address http://name_of_raspberrypi (as set in /etc/hostname)

webcam_port 80

Allow access via the network

webcam_localhost off

save with ^O and exit nano with ^X

Configuration options are documented on the Motion web-home under Config File Options.

Enable Motion and start it. Afterward the red LED on the camera module should light up.

[root@flypi motion]# systemctl enable motion
Created symlink from /etc/systemd/system/multi-user.target.wants/motion.service to /usr/lib/systemd/system/motion.service.
[root@flypi motion]# systemctl start motion
[root@flypi motion]# 

Now you can test it from another PC on the network by opening the following URL:


if you have not changed webcam_port in the config file you need to use


Have Fun!

Keine Kommentare:

Kommentar veröffentlichen