Robert Cudmore    archive    tags    search    software

Home Cage Activity

Record video 24/7 with a Raspberry Pi

The parts list and implementation details are in the original blog post.

The Raspberry Pi is running Debian Linux and is networked

username: pi

The IP should not change, this was set up with the network office.

When the Pi boots, it will tweet with its ip address. Subscribe to @cudmore_io (or is it to receive the tweets.

To login to the Pi

On Windows, download and then use Putty

On OSX, use the terminal application in /Applications/Utilities/ and type:

ssh pi@

Logout of the Pi


Mount the pi hard-drive as a file-server

On Windows, in the start menu, type:


On OSX, ‘Connect to Server…’ and type:


Saved files

File are saved in /home/pi/video/

Super simplified

Login to the pi and there are three commands

start : Start lights and video stop : Stop lights and video running : Tells you if the lights/video are running

Running the code (old, not needed)

Run to control the lights

cd /home/pi/Sites/homecage
#exit screen with ctrl+a then d

Run to record video

cd /home/pi/Sites/homecage
#exit screen with ctrl+a then d

Both programs need to be run inside a screen session. This way when your ssh session logs out, the programs will continue to run. If you do not run these programs within a screen session, the programs will stop recording when you log out.

To exit screen mode, hold down ‘ctrl’ and then ‘a’ key at the same time. Let go of ‘ctrl’ and ‘a’ keys. Then press ‘d’ key

To return to a screen session

1) List the sessions with ‘screen -r’

screen -r
~/homecageactivity $ screen -r
There are several suitable screens on:
  1255.pts-5.homecage	(07/20/2016 04:41:04 PM)	(Detached)
  1186.pts-1.homecage	(07/20/2016 04:40:06 PM)	(Detached)
Type "screen [-d] -r [pid.]" to resume one of them.

2) Return to a particular screen with

screen -r 1255.pts-5.homecage


screen -r 1186.pts-1.homecage

To stop a program

Return to its screen (with screen -r …) and press ctrl+c

Converting .h264 files to .mp4

Video files in .h264 need to be converted to .mp4 so they have meaningful fps. Do this with a bash script on osx.

	mkdir mp4

	for file in *.h264 ; do
		echo $filename
		ffmpeg -r 15 -i "$file" -vcodec copy "mp4/$file.mp4"
		sleep 3
	done will make an mp4/ folder with .mp4 copies of all your video files

To start over

The following sequence will start the video recording and lights again

1) pull power and plug back in
2) login with putty/terminal
3) cd Sites/homecage
4) screen
5) python
6) [exit screen with ctrl+a then d]
7) screen
8) python
9) [exit screen with ctrl+a then d]
10) exit

The source code for and


This was originally written as readme for Valerie in the Bergles lab, 20160723.

Other systems


Adding a crontab entry

Open up crontab in editor

crontab -e

Append these lines

@reboot (sleep 15; python /home/pi/code/ &)
@reboot (sleep 15; cd /home/pi/Sites/triggercamera; python /home/pi/Sites/triggercamera/ &)


<IMG SRC=”images/homecage/1.jpg” width=400>

Tags: analysis

©2019. Robert Cudmore.