{"id":96,"date":"2017-12-21T10:53:31","date_gmt":"2017-12-21T15:53:31","guid":{"rendered":"http:\/\/thinkleet.net\/?p=96"},"modified":"2026-04-13T07:06:18","modified_gmt":"2026-04-13T11:06:18","slug":"squirrel-camera","status":"publish","type":"post","link":"https:\/\/thinkleet.net\/index.php\/2017\/12\/21\/squirrel-camera\/","title":{"rendered":"Squirrel Camera!"},"content":{"rendered":"<p>This morning I awoke and discovered that our local neighborhood squirrels have been attacking our pumpkins that have been on the porch.\u00a0 Not that it is a major concern, squirrels need to eat also, but this lead me to today&#8217;s project.\u00a0 Today I decided to create the squirrel cam.\u00a0 Most of the functionality was already widely available, the only major thing was putting it all together.\u00a0 Most of the parts for this were just laying around not being used, but I&#8217;m running out of Raspberry Pi&#8217;s to use in these projects.\u00a0 Between replacing multiple machines with one, running the 3-D printer off another, RetroPie\/Kodi setups, I only have a Pi Zero W remaining.\u00a0 I think I&#8217;ll have to find a way to rectify this at some point.\u00a0 Anyway, back to the squirrel camera.<\/p>\n<p>Items Needed<\/p>\n<ol>\n<li>\u00a03D printer<\/li>\n<li>\u00a0<a href=\"http:\/\/amzn.to\/2zbLive\">PLA Filament<\/a><\/li>\n<li>\u00a0Raspberry Pi <\/li>\n<li>\u00a0USB Power Bank<\/li>\n<li>\u00a0<a href=\"http:\/\/amzn.to\/2zbR5kA\">Webcam<\/a> (case will mount a Logitech C310 or C270)<\/li>\n<\/ol>\n<p>My first attempt at making this work involved only printing the <a href=\"https:\/\/www.thingiverse.com\/thing:1729459\">webcam mount<\/a>. This failed almost immediately when I attempted to put it on the tripod plate.\u00a0 The screw hole immediately stripped out and would not stay attached.\u00a0 With that, I then moved onto Plan B.\u00a0 A bit more involved than simply printing a mount, I was able to take the mount STL files, and using TinkerCAD, remix it with a snap together &#8220;<a href=\"https:\/\/www.thingiverse.com\/thing:1719550\">Simple Raspberry Pi 3<\/a>&#8221; case, to create a <a href=\"https:\/\/www.thingiverse.com\/thing:2725149\">case with a built in mount<\/a>. Admittedly, my remix could have been done better, but I was in a rush after being frustrated by the stripped screw hole. Fair warning, the case requires a bit of clean up and has a lot of support structures, but it fits and does the job, so it is a partial win.\u00a0 At some point I&#8217;ll redo it so it is prettier, and prints with less support, but for now, it&#8217;ll do.<\/p>\n<figure id=\"attachment_100\" aria-describedby=\"caption-attachment-100\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-100\" src=\"https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/IMG_20171222_094135-300x225.jpg\" alt=\"Case\" width=\"300\" height=\"225\" srcset=\"https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/IMG_20171222_094135-300x225.jpg 300w, https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/IMG_20171222_094135-768x576.jpg 768w, https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/IMG_20171222_094135-1024x768.jpg 1024w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><figcaption id=\"caption-attachment-100\" class=\"wp-caption-text\">I made this myself<\/figcaption><\/figure>\n<p>Next up was getting the software installed to the micro SD card.\u00a0 Raspbian Stretch Lite was my choice to use.\u00a0 Burn the image to the micro SD card in whatever way you want.\u00a0 Since we are going to be running the Pi headless, we need to enable SSH access before we boot the Pi. \u00a0 With all versions of Raspbian since Nov. 2016, ssh access is disabled by default.\u00a0 The way to enable it, without a display, is to create a file in the boot partition named &#8220;ssh&#8221; without quotes.\u00a0 This will allow us to access the pi over the network and proceed with the rest of the configuration.<\/p>\n<p>Once we are connected to the network with the Pi, we will update the OS, and then install all the needed software.\u00a0 This Pi will be running a program called motion, which will take pictures automatically when enough pixels change in the image.\u00a0 Ideally, this won&#8217;t cause unwanted images to be taken since I decided it will also be a Twitter bot, tweeting the images whenever a photo is taken.<\/p>\n<p>Up next, we will install motion.\u00a0 I followed a very straightforward guide, located <a href=\"https:\/\/web.archive.org\/web\/20171119063624\/http:\/\/sjj.azurewebsites.net\/?p=701\">here<\/a>.\u00a0 I followed along until the part where it describes adding network storage to the mix as the sd card available to me was large enough to not worry about that.<\/p>\n<p>Next was deciding on how to post the photos that were taken to Twitter.\u00a0 This created an issue as I have never tried to run a Twitter bot before.\u00a0 A little bit of research later,\u00a0 and I found an easy to run twitter bot <a href=\"https:\/\/github.com\/joaquinlpereyra\/twitterImgBot\">here<\/a>.\u00a0 I love Github.<\/p>\n<p>One key thing I found with the bot though is that the starting tweet number has to be set.\u00a0 It didn&#8217;t want to default to 1 on the initial run, causing errors whenever I tried to start it.<\/p>\n<p>Following the instructions in the readme file, I set up Twitter API access, plugged in the required information, ran the script once with the &#8211;tweetnumber variable set to 1 and success!\u00a0 The pi tweeted on its own.\u00a0 Next up, configuring cron jobs to run the script at regular intervals.<\/p>\n<p>For this,\u00a0 I chose to have the script run every 5 minutes.\u00a0 Many walkthroughs exist for setting up cronjobs so this will not be covered.\u00a0 Lastly, we put it all together and set it up.\u00a0 The Squirrel cam is tweeting at @TLPorchCam<\/p>\n<p>Things I want to change:<\/p>\n<p>Make the squirrel cam tweet the most recent image if it hasn&#8217;t been posted previously.\u00a0 The bot I used just picks randomly from the folder, without regard to the most recent.\u00a0 I guess eventually the pictures will get posted, but it isn&#8217;t the most effective way in my mind.<\/p>\n<p>&nbsp;<\/p>\n<p>UPDATE:\u00a0 Success!\u00a0 I have squirrel pictures.\u00a0 58-20171222123131<\/p>\n<figure id=\"attachment_103\" aria-describedby=\"caption-attachment-103\" style=\"width: 300px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00.jpg\"><img loading=\"lazy\" decoding=\"async\" class=\"size-medium wp-image-103\" src=\"https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00-300x169.jpg\" alt=\"Squirrel\" width=\"300\" height=\"169\" srcset=\"https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00-300x169.jpg 300w, https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00-768x432.jpg 768w, https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00-1024x576.jpg 1024w, https:\/\/thinkleet.net\/wp-content\/uploads\/2017\/12\/58-20171222123137-00.jpg 1280w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><figcaption id=\"caption-attachment-103\" class=\"wp-caption-text\">This is what I do with days off from work!<\/figcaption><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This morning I awoke and discovered that our local neighborhood squirrels have been attacking our pumpkins that have been on the porch.\u00a0 Not that it is a major concern, squirrels need to eat also, but this lead me to today&#8217;s project.\u00a0 Today I decided to create the squirrel cam.\u00a0 Most of the functionality was already &hellip; <a href=\"https:\/\/thinkleet.net\/index.php\/2017\/12\/21\/squirrel-camera\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Squirrel Camera!<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":103,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,9],"tags":[],"class_list":["post-96","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-3d-printer","category-pi"],"_links":{"self":[{"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/posts\/96","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/comments?post=96"}],"version-history":[{"count":12,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/posts\/96\/revisions"}],"predecessor-version":[{"id":224,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/posts\/96\/revisions\/224"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/media\/103"}],"wp:attachment":[{"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/media?parent=96"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/categories?post=96"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thinkleet.net\/index.php\/wp-json\/wp\/v2\/tags?post=96"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}