Difference between revisions of "Mouse Cage Imaging"

From Wiki
Jump to navigation Jump to search
Line 40: Line 40:
  
 
== Timelapse Scripts ==
 
== Timelapse Scripts ==
 +
 
 +
  cd; mkdir timelapse;mkdir bin
 +
 +
 +
Create a /home/pi/bin/camera.sh and add the following text
 +
 +
  DATE=$(date +"%Y-%m-%d_%H%M")
 +
 
 +
  raspistill --annotate 12 -w 1296 -h 972 -hf -vf -o /home/pi/timelapse/$DATE.jpg
 +
  /bin/bash /home/pi/bin/sync_files.bash
 +
 +
 +
Create a /home/pi/bin/sync_file.bash and add the following text
 +
 +
  #!/bin/bash
 +
 
 +
  if [ -d /home/pi/timelapse ]
 +
  then
 +
        if [ ! -d /media/mouse ]
 +
        then
 +
                pmount /dev/sda1 /media/mouse
 +
        fi
 +
 
 +
        if [ ! -d /media/mouse ]
 +
        then
 +
                pmount /dev/sdb1 /media/mouse
 +
        fi
 +
 
 +
        if [ ! -d /media/mouse ]
 +
        then
 +
                pmount /dev/sdc1 /media/mouse
 +
        fi
 +
 
 +
        if [ ! -d /media/mouse ]
 +
        then
 +
                pmount /dev/sdd1 /media/mouse
 +
        fi
 +
 
 +
        if [ -d /media/mouse ]
 +
        then
 +
                if [ ! -d /media/mouse/timelapse ]
 +
                then
 +
                        mkdir /media/mouse/timelapse
 +
                fi
 +
 
 +
                if [ -d /media/mouse/timelapse ]
 +
                then
 +
                        rsync -aq /home/pi/timelapse/*.jpg /media/mouse/timelapse/
 +
                fi
 +
        fi
 +
 
 +
        if [ -d /media/mouse ]
 +
        then
 +
                pumount /media/mouse
 +
        fi
 +
  fi
 +
 +
Edit a crontab for user PI and add the following text:
 +
 +
  # m h  dom mon dow  command
 +
  0,10,20,30,40,50 * * * * sh /home/pi/bin/camera.sh 2>&1
 +
  0 17 * * 5 rm -rf /home/pi/timelapse/*.jpg 2>&1
  
 
== 3D Printed Parts ==
 
== 3D Printed Parts ==

Revision as of 20:18, 5 February 2019

This is a mouse imaging system designed to take timelapse photos every 10 minutes, even overnight in complete darkness. It uses 3D parts to mount a Raspberry Pi, and an Infrared Camera to a mouse cage.

Parts:

Real Time Clock Setup

 echo "dtoverlay=i2c-rtc,ds3231" >>/boot/config.txt

edit the /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines"

 if [ -e /run/systemd/system ] ; then
 exit 0
 fi

so they become:

 #if [ -e /run/systemd/system ] ; then
 # exit 0
 #fi


Update the HW Clock from system time, assuming the Raspberry PI had is network connected.

 sudo hwclock -w 

reboot and then run:

 sudo hwclock -r

Infrared Camera Setup

Timelapse Scripts

 cd; mkdir timelapse;mkdir bin


Create a /home/pi/bin/camera.sh and add the following text

 DATE=$(date +"%Y-%m-%d_%H%M")
 
 raspistill --annotate 12 -w 1296 -h 972 -hf -vf -o /home/pi/timelapse/$DATE.jpg
 /bin/bash /home/pi/bin/sync_files.bash


Create a /home/pi/bin/sync_file.bash and add the following text

 #!/bin/bash
 
 if [ -d /home/pi/timelapse ]
 then
       if [ ! -d /media/mouse ]
       then
               pmount /dev/sda1 /media/mouse
       fi
 
       if [ ! -d /media/mouse ]
       then
               pmount /dev/sdb1 /media/mouse
       fi
 
       if [ ! -d /media/mouse ]
       then
               pmount /dev/sdc1 /media/mouse
       fi
 
       if [ ! -d /media/mouse ]
       then
               pmount /dev/sdd1 /media/mouse
       fi
 
       if [ -d /media/mouse ]
       then
               if [ ! -d /media/mouse/timelapse ]
               then
                       mkdir /media/mouse/timelapse
               fi
 
               if [ -d /media/mouse/timelapse ]
               then
                       rsync -aq /home/pi/timelapse/*.jpg /media/mouse/timelapse/
               fi
       fi
 
       if [ -d /media/mouse ]
       then
               pumount /media/mouse
       fi
 fi

Edit a crontab for user PI and add the following text:

 # m h  dom mon dow   command
 0,10,20,30,40,50 * * * * sh /home/pi/bin/camera.sh 2>&1
 0 17 * * 5 rm -rf /home/pi/timelapse/*.jpg 2>&1

3D Printed Parts