Raspberry Pi Puppy Cam v.2.0

I promised to write an updated post about the Raspberry Pi Puppy cam v.1.0. I’m a man of my words so here’s the story. The nice part about this project was that so much of the material was available online (both hardware and software). I didn’t put the words “Rather secure” in the topic anymore, as all my RPi’s are secure from now on due to the Raspberry Pi OpenVPN-server project I wrote about earlier. The earlier camera was pretty useless so it was updated to Raspberry Pi’s own camera module. I also wanted servos so I could move the camera around (remotely).



        Fig 1. Raspberry Pi with camera module attached to Pi-Pan.


          Fig 2. Same thing, another view.




Basic steps:

  • Assembled the Pi-Pan and fitted it to the case (Fig 1), http://www.openelectrons.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=20
  • Installed the controller board on the GPIO pins, and the servo wires to the controller board, http://www.openelectrons.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=24 
  • Configured Raspbian (from raspi-config)
    • Expanded Filesystem (to fill the whole SD card)
    • Changed user password
    • Changed Internationalisation Options according to my needs
    • Enabled Camera
    • Advanced options:
      • Changed hostname
      • Enabled SSH
      • Enabled I2C (needed for servos)
  • Updated the Pi:
    • sudo rpi-update (firmware)
    • sudo apt-get update && sudo apt-get upgrade –y (software)
  • Installed necessary software for Pi-Pan (servoblaster), http://www.openelectrons.com/index.php?module=pagemaster&PAGE_user_op=view_page&PAGE_id=24
    • checked that the servos were working – they worked just fine.
  • Installed the amazing RPi Cam Web Interface. Just followed instructions from http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276. Everything worked “out of the box”.
  • “Installed” the Pi-Pan addon for RPi Cam Web Interface, http://www.raspberrypi.org/forums/viewtopic.php?f=43&t=63276
    • modified it a bit; commented out everything that had to do with Pi-Light as I don’t use that. (If you’re reading this you probably know how to comment code so I won’t go into that).
  • My Camera is hanging upside down, so the Web Interface controllers had to be inverted. Easy task, just change the code below <input id=”halt_button” type=”button”>” in /var/www/index.php (not index.html) to:
    <input type="button" value="up" onclick="servo_down();"><br>
    <input type="button" value="left" onclick="servo_right();">
    <input type="button" value="down" onclick="servo_up();">
    <input type="button" value="right" onclick="servo_left();">
    • Up now inverts to down and left inverts to right (and so on).
  • That’s it for the software part! I did a test run a noticed that the Pi won’t work properly with the default settings (records in Full HD). If there’s “too much” movement while the video is saving/processing, and you also play with the servos, the Pi will freeze. I don’t need Full HD so I just changed the default resolution/recording resolution to a lower one (720p). This is done from /etc/raspimjpeg. My changes:

      # Video Options
      video_width 1280
      video_height 720
      video_fps 15
      video_bitrate 17000000
      MP4Box true
      MP4Box_fps 15

  • This is much smoother and the videos won’t be silly large either (like ~40MB for 15 seconds in Full HD). Now 30 seconds of video is about 10MB on disk.



I noticed that the servos go back to neutral position if you touch the action buttons after you’ve viewed your saved videos and return to the main page. This is very frustrating – when you hit a movement button (left, right, down, up), the servos will go to neutral and not continue where they left off before you went to download videos (same if you refresh the page). You can change the coordinates default position in the file /var/www/pipan.js. Trial and error will get your desired position.

Another thing you should change is the start-up behaviour of motion;

[warn] Not starting motion daemon, disabled via /etc/default/motion … (warning).

Just change this to “yes” and you are good to go;

# set to ‘yes’ to enable the motion daemon


I also decided to do some modifications to the index.php file regarding the pull-down menu with resolutions. As I already mentioned, I don’t like Full HD as it gets slow. The options are quite self-explanatory: 

/var/www/index.php: (original)

            Load Preset: <select onclick=”set_preset(this.value)”>
              <option value=”1920 1080 25 25 2592 1944″>Select option…</option>
              <option value=”1920 1080 25 25 2592 1944″>Std FOV</option>
              <option value=”1296 0730 25 25 2592 1944″>16:9 wide FOV</option>
              <option value=”1296 0976 25 25 2592 1944″>4:3 full FOV</option>
              <option value=”1920 1080 01 30 2592 1944″>Std FOV, x30 Timelapse</option>


/var/www/index.php: (modified)

            Load Preset: <select onclick=”set_preset(this.value)”>
              <option value=”1280 0720 15 15 2592 1944″>Select option…</option>
              <option value=”1280 0720 15 15 2592 1944″>16:9, 720p, HD-ready</option>
              <option value=”1920 1080 25 25 2592 1944″>Std FOV</option>
              <option value=”1296 0730 25 25 2592 1944″>16:9 wide FOV</option>
              <option value=”1296 0976 25 25 2592 1944″>4:3 full FOV</option>
              <option value=”1920 1080 01 30 2592 1944″>Std FOV, x30 Timelapse</option>


The value 15 15 is actually the frame rate. 15 is more than enough for a cam like this and the videos will be much smaller in size. You won’t choke the Pi with the encodings either.


Finally here’s a picture of the whole thing in action at home 🙂


Fig 3. RPi Cam v.2.0 in action (mounted under a shelf).


…and here’s a picture of the webcam interface (unfortunately not mine, and the Pi-Pan addon controls are missing)


Fig 4. RPi Cam Control (Source: http://www.sweetpi.de/blog/783/raspberry-pi-kamera-als-live-webcam-mit-aufnahmefunktion)