Although the Raspberry Pi camera is a cheap mobile phone sensor, and not up to the quality of dedicated hardware, nevertheless it can record full HD video and take 5 megapixel photos. Probably the main advantage is that, being Pi-driven, it is programmable, so it can be triggered by any event, such as web based events like an email or through GPIO inputs.

AndyPi has put together a MultiCam, envisaged initially with a couple of applications, first of all, as a helmet cam for bike riding, and with options for timelapse and futhermore full control of all camera options via a webpage. AndyPi’s MultiCam has a detachable illuminated switch to enable remote control, without the use of any keyboard or SSH terminal. It also features a wifi network so videos and images  can be transferred to other devices wirelessly, and also gives the option of full control via SSH if needed.

There is no audio input for a few reasons – firstly, Raspberry Pi has no audio input built in, secondly this would have to be provided via USB (and the only port is being used by the wifi stick), or by a breakout board from the GPIO, both of which would require extra space and power. Bike riding and timelapse videos usually end up removing the sound and placing music over it anyway, so its not very important in this case.

Kit list:

  • Raspberry Pi, Model A
  • Raspberry Pi Camera
  • Comfast Wifi adpator (£3.70 on eBay)
  • Small box, Maplin (£3.89 from Maplin)
  • Illuminated switch, (£2.49 from Maplin)
  • Low profile SD card adapter (£6.89 on eBay)
  • 16GB micro SD card (£8 on eBay)
  • USB cable & socket (from my junk box)
  • Female – Female PCB connector wires
  • Instamorph moldable plastic
  • Sugru
  • Battery Power supply (2A)

PART A: Initial Setup of Wifi Hotspot (and script to switch back to router network)

First of all the camera will act as a wifi hotspot so it can be controlled by SSH if required, and files can be downloaded to another device wirelessly. We’ll also make a couple of scripts to switch between the standard network and the hotspot, since a) we’ll need internet access to install some software later and b) if you’re using this at home its preferable to access the camera over your normal network so you can have internet access on your laptop/tablet whilst accessing the camera too. So – first follow my instructions for Raspberry Hotspot!

OPTION A: Web-based

Originally, I created my own hardware trigger (see Option B below), which was great to learn GPIO stuff! However, there are a couple of new options which actually make things a lot more versatile.

1. The RPi Cam web interface. This is very versatile, it can stream and record video, and is available on any device:

http://www.raspberrypi.org/forums/viewtopic.php?t=63276

2. The RasPi Cam remote. This does not require any additional software installing onto the Pi, however, it is only available for Android,

https://play.google.com/store/apps/details?id=com.pibits.raspberrypiremotecam

OPTION B: Hardware Setup

I wanted a very simple trigger to start whatever camera capture I programmed with som100_4780e kind of indication. So I’m using an illuminated push to make switch. I’ve wired the LED to between GPIO003 and GND and the button between GPIO004 and GND. I wired this switch to a USB cable and covered the solder tabs with sugru to make it neat. The GPIO ports are then connected to a USB socket, so the button can be easily detached. It’s also got a reasonably long wire so it can be activated from a distance (i.e. if the camera is mounted to my head whilst biking!). The rest of the setup is just fitting the raspberry pi, camera etc into a small box. I needed to cut a hole for the camera and mounting screws, power socket and my homemade usb socket. I also cut away some of the screw mounting spacers in the100_4782 box to give enough space for the wifi usb stick. I used Instamorph (a type of moldable plastic which goes soft in boiling water) to mount the Pi to the box, and to provide an insulated mount for my homemade usb socket. I used a low profile SD card, and just left a hole for the camera and power supply, so a battery pack can be used.

I’ve also disabled the front facing LED on the camera board itself:

sudo nano /boot/config.txt

add the line:

disable_camera_led=1

Python Scripting

The python script is the heart of this project – have a look at how the script works. Basically if you press the button, the GPIO triggers a function to turn off the LED and start the video (standard options, saving the file named by time and date

1. You can download it with

wget http://download.andypi.co.uk/camscript.py

2. Make the script executable

sudo chmod +x camscipt.py

3. Set your pi to autologin (following http://elinux.org/RPi_Debian_Auto_Login), and add the script to .bashrc (this assumes the script is in your home directory)

sudo nano /etc/inittab

scroll down to

1:2345:respawn:/sbin/getty 115200 tty1, and comment out the line with  #add the line1:2345:respawn:/bin/login -f YOURUSERNAMEHERE tty1 </dev/tty1 >/dev/tty1 2>&1

Ctrl-X to exit, Y to save and press enter.

sudo nano .bashrc

add the lines

sudo ./camscript.py

 

4. Reboot your pi, and when it loads up and the script is ready, the LED will light up. Pressing the button will turn the LED OFF but turn the camera ON (so we can tell when the pi is ready for a button press).

5. If you want to be able to access the file remotely, you’ll need to install and setup samba:

sudo apt-get install samba

My samba settings file is pretty open , so you may want to modify this (/etc/samba/smb.conf)

[global]
workgroup = WORKGROUP
usershare allow guests = yes
security=share
follow symlinks = yes
wide links = yes
unix extensions = no
[home]
browsable = yes
read only = no
guest ok = yes
path = /home/
force user = camera

 

Some extra info on converting the video

I use Adobe Premiere Elements 9 / Freemake video converter for my video editing, but you can’t directly use this video file created by the raspberry pi camera (although it does play directly in Windows Media Player and VLC). I got around this by converting to an mp4 codec, using ffmpeg. You can download and install this on pretty much any platform (including the pi, although I did the conversion on my windows 7 laptop).

Command is: ffmpeg -r 30 -i MYVIDEO_IN.h264 -vcodec copy MYVIDEO_OUT.mp4

Linux .bash script to do all the videos in one folder (doesn’t seem to output videos as smooth as the windows version for some reason):

#!/bin/bash
for f in *.h264; do ffmpeg -r 30 -i “$f” -vcodec copy “${f%.h264}.mp4”; done;

Windows .bat file to to the same job, putting into a subfolder called newfiles:

for %%a in (“*.h264”) do ffmpeg -r 30 -i “%%a” -vcodec copy “newfiles%%~na.mp4”
pause

 

More options!

If you log into the pi using SSH (I used the ConnectBot app on my Android tablet), you can obviously now access all of the usual camera functions (see official docs) using the command line.

1. A series of timelapse pictures (every minute, for 60 minutes, each file individually named):

sudo raspistill -t 600000 -tl 60000 -o image%04d.jpg

Of course, you could easily put this code inside the python script (where the instructions for the raspivid are currently), if you wanted to be able to trigger the start of the timelapse from the button rather than via another computer.

2. You could also stream video from the MutliCam to another computer, using VLC media player (See Raspi.tv for the excellent tutorial):

install VLC on the Raspberry MultiCam

sudo apt-get update
sudo apt-get install vlc

Start the stream (infinite length):

raspivid -o - -t 0 -hf -w 640 -h 360 -fps 25|cvlc -vvv stream:///dev/stdin --sout '#standard{access=http,mux=ts,dst=:8090}' :demux=h264#

Go to VLC on your computer or tablet, or other media player, and open a new network stream (Ctrl-N in windows):  http://192.168.xx.yy:8090 (Where 192.168.xxx.yyy is the IP address of your raspberry pi on the network)