Difference between revisions of "Mouse Cage Imaging"

From Wiki
Jump to navigation Jump to search
 
(23 intermediate revisions by the same user not shown)
Line 11: Line 11:
 
* [https://www.adafruit.com/product/2256 Adafruit Base Case]
 
* [https://www.adafruit.com/product/2256 Adafruit Base Case]
 
* [https://www.adafruit.com/product/1995 Adafruit 5V 2.5A PS]
 
* [https://www.adafruit.com/product/1995 Adafruit 5V 2.5A PS]
 +
 +
 +
== HDMI ==
 +
 +
edit /boot/config.txt and uncomment "disable_overscan =1 "
  
 
== Real Time Clock Setup ==
 
== Real Time Clock Setup ==
 
    
 
    
   echo "dtoverlay=i2c-rtc,ds3231" >>/boot/config.txt
+
   add "dtoverlay=i2c-rtc,ds3231" to /boot/config.txt
  
 
edit the /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines"
 
edit the /lib/udev/hwclock-set file (sudo nano /lib/udev/hwclock-set) and "comment out" the following lines"
Line 28: Line 33:
 
   #fi
 
   #fi
  
 +
 +
Reboot
  
 
Update the HW Clock from system time, assuming the Raspberry PI had is network connected.
 
Update the HW Clock from system time, assuming the Raspberry PI had is network connected.
Line 45: Line 52:
 
    
 
    
 
   cd; mkdir timelapse;mkdir bin
 
   cd; mkdir timelapse;mkdir bin
 
 
 
   sudo apt-get install pmount
 
   sudo apt-get install pmount
  
Line 51: Line 57:
  
 
   DATE=$(date +"%Y-%m-%d_%H%M")
 
   DATE=$(date +"%Y-%m-%d_%H%M")
 +
  MOUSE="mouse1"
 
    
 
    
   raspistill --annotate 12 -w 1296 -h 972 -hf -vf -o /home/pi/timelapse/$DATE.jpg
+
   raspistill --annotate 12 -w 1296 -h 972 -hf -vf -o /home/pi/timelapse/${NAME}_${DATE}.jpg
  /bin/bash /home/pi/bin/sync_files.bash
 
  
  
Create a /home/pi/bin/sync_file.bash and add the following text
+
Create a /home/pi/bin/sync_files.bash and add the following text
  
 
   #!/bin/bash
 
   #!/bin/bash
Line 100: Line 106:
 
         fi
 
         fi
 
   fi
 
   fi
 +
 +
sudo chmod a+x /home/pi/bin/*
  
 
Edit a crontab for user PI and add the following text:
 
Edit a crontab for user PI and add the following text:
Line 105: Line 113:
 
   # m h  dom mon dow  command
 
   # m h  dom mon dow  command
 
   0,10,20,30,40,50 * * * * sh /home/pi/bin/camera.sh 2>&1
 
   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
+
   0 17 1 * * find /home/pi/timelapse -name "*.jpg" -type f -mtime +30 -exec rm -f {} \;
 
 
 
      
 
      
 
Edit usbstick.rules  
 
Edit usbstick.rules  
Line 129: Line 136:
 
   ExecStop=/usr/bin/pumount /dev/%I
 
   ExecStop=/usr/bin/pumount /dev/%I
  
Edit cpmount
+
Edit /usr/local/bin/cpmount and add the following lines:
  sudo vi /usr/local/bin/cpmount
 
  
Add the following lines:
 
 
   #!/bin/bash
 
   #!/bin/bash
 
   /usr/bin/pmount --umask 000 --noatime -w --sync $1 mouse
 
   /usr/bin/pmount --umask 000 --noatime -w --sync $1 mouse
 
+
 
   if mountpoint -q /media/mouse
+
   if mountpoint -q /media/mouse
 
   then
 
   then
                if [ ! -d /media/mouse/timelapse ]
+
      if [ ! -d /media/mouse/timelapse ]
                then
+
      then
                        mkdir /media/mouse/timelapse
+
          mkdir /media/mouse/timelapse
                fi
+
      fi
 +
      chown pi:pi /media/mouse/timelapse
 +
  fi
 +
 
 +
  # Copy Mouse Pictures and removes source files
 +
  /bin/bash /home/pi/bin/sync_files.bash
 +
 
 +
  # umount usb stick safely
 +
  if [ -d /media/mouse ]; then
 +
                  /usr/bin/pumount /media/mouse
 
   fi
 
   fi
  
Change cpmount permissions
+
 
   sudo chmod +x /usr/local/bin/cpmount
+
   sudo chmod a+x /home/pi/bin/sync_files.bash
 +
  sudo chmod a+x /usr/local/bin/cpmount
  
 
== 3D Printed Parts ==
 
== 3D Printed Parts ==
 +
 +
email Karl Bellvé for final STL files for 3D printing. These will be specific for one type of mouse cage, but one could adapt them.

Latest revision as of 18:52, 17 December 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:


HDMI

edit /boot/config.txt and uncomment "disable_overscan =1 "

Real Time Clock Setup

 add "dtoverlay=i2c-rtc,ds3231" to /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


Reboot

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

Enable Camera

 sudo raspi-config

Timelapse Scripts

 cd; mkdir timelapse;mkdir bin
 sudo apt-get install pmount

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

 DATE=$(date +"%Y-%m-%d_%H%M")
 MOUSE="mouse1"
 
 raspistill --annotate 12 -w 1296 -h 972 -hf -vf -o /home/pi/timelapse/${NAME}_${DATE}.jpg


Create a /home/pi/bin/sync_files.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
sudo chmod a+x /home/pi/bin/*

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 1 * * find /home/pi/timelapse -name "*.jpg" -type f -mtime +30 -exec rm -f {} \;
   

Edit usbstick.rules

 sudo vi /etc/udev/rules.d/usbstick.rules

Add the following line:

 ACTION=="add", KERNEL=="sd[a-z][0-9]", TAG+="systemd", ENV{SYSTEMD_WANTS}="usbstick-handler@%k"

Edit usbstick-handler@.service

 sudo vi /lib/systemd/system/usbstick-handler@.service

Add the following lines:

 [Unit]
 Description=Mount USB sticks
 BindsTo=dev-%i.device
 After=dev-%i.device
 
 [Service]
 Type=oneshot
 RemainAfterExit=yes
 ExecStart=/usr/local/bin/cpmount /dev/%I
 ExecStop=/usr/bin/pumount /dev/%I

Edit /usr/local/bin/cpmount and add the following lines:

 #!/bin/bash
 /usr/bin/pmount --umask 000 --noatime -w --sync $1 mouse
 
 if mountpoint -q /media/mouse  
 then
     if [ ! -d /media/mouse/timelapse ]
     then
         mkdir /media/mouse/timelapse
     fi
     chown pi:pi /media/mouse/timelapse
 fi
 
 # Copy Mouse Pictures and removes source files
 /bin/bash /home/pi/bin/sync_files.bash
 
 # umount usb stick safely
 if [ -d /media/mouse ]; then
                 /usr/bin/pumount /media/mouse
 fi


 sudo chmod a+x /home/pi/bin/sync_files.bash
 sudo chmod a+x /usr/local/bin/cpmount

3D Printed Parts

email Karl Bellvé for final STL files for 3D printing. These will be specific for one type of mouse cage, but one could adapt them.