Setting up a headless Raspberry Pi Zero (W) with Camera

I received my Raspberry Pi Zero W a couple of weeks ago and finally had the chance to set it up. My goal is to to setup some cameras in my basement and garage.

Prerequisites

Here are links to the products and prices I purchased on Amazon and CanaKit at the time. The prices might vary slightly if you purchase them.

Bringing the total cost of this setup to: $69.35 (including shipping). If you’re looking for something with more features, you can purchase indoor wireless IP camera’s online. Some of them even have 2-way audio which I use to keep tabs on my dogs and general security. For my purposes, and where they’ll be placed, I don’t need that type of functionality. Also, you get the reward of building something yourself with greater control.

Setup

I decided to use the Raspbian Jessie Lite distribution for my setup since it’s a smaller SD card and there won’t be any GUI. You can download it here from the Raspberry Pi website by selecting “Download ZIP”. Alright, here we go:

  1. Connect the SD card to your computer. Note that it must be formatted as FAT32. The one I purchased above was already formatted in FAT32.
  2. Open “Disk Utility”. To do this, click on the magnifying glass in the top-right corner of your computer screen. Type “disk utility” in the search box that opens, then click on the “Disk Utility” Application that comes up and click on “APPLE SD Card Reader Media”.
  3. Note the “Device:”; it will look something like disk(n) where (n) is a number (for example, disk1). Make sure you take a note of this number. Mine was disk1.
  4. Now, right click on “NO NAME” or “Untitled” on the left and select “Unmount” from the menu. This will unmount the partition so that you can write to the disk.
  5. Now open terminal and run the following command:

    Remember to replace (n) with the number that you noted before and (PATH_OF_THE_IMAGE_YOU_DOWNLOADED.img) to the path of the Raspbian Jessie Lite image you downloaded. for example: my command was:

    The image file will be copied to the SD Card. You won’t get any feedback while it copies, and it can take several minutes. Leave terminal open and let it do its thing.

Headless setup on the Raspberry Pi Zero (W)

Once it’s completed,

  1. Open the boot volume on your Mac (should auto mount after the disk image is finished writing).
  2. Create an ssh file to tell the Pi to enable SSH when it boots up by default:
  3. Next, create a wpa_supplicant.conf file in the boot volume to tell the Pi to connect to your WiFi network on boot:
  4. Insert the contents below into this new file:
  5. Eject the SD Card and insert it into your Raspberry Pi.

Connecting the Camera to the Pi

Connecting the camera to the pi is fairly easy. Use the supplied mini cable provided with the camera case.

Insert the Pi into the case

Finished Product

Booting Raspbian Jessie Lite

Ok, now it’s time to insert the power cord and boot up the Pi. For this step, you’re going to find the IP Address of your Pi to SSH into it. Most routers have a network map that displays connected devices. I was easily able to find mine. If you can’t find yours, try using a tool like nmap.

  1. SSH into your Pi:
  2. Once, you’ve logged in, update the OS:
  3. Now we’re going to configure the OS using the raspi-config tool.

    Below are the options I configured for my Pi:
    1. Set a new password.
    2. Set a hostname (e.g. kitchen-camera).
    4. I configured “Localisation Options” for my locale
    5. For ‘Interfacing Options’, select ‘P1 Camera’, then choose ‘Yes’ to enable the camera interface.
  4. Test it out by running:

Installing software for the camera

There are a couple of software options for using your Pi as a security camera. I opted for Motion. Adafruit has an excellent tutorial for setting it up with Dropbox. Follow that tutorial and become familiar with the Motion config options.

Setting up Raspberry Pi 3 with the 7″ Touchscreen Display

Today I received all the parts I need to begin setting up my own personal home dashboard. When I first began my career in programming, Home Automation was always something I’ve been very intrigued with; only it was very expensive and there weren’t many products out there to support it. Now, with the recent boom in IOT devices and products, its easier and far more cost effective to do this on your own.

Why am I doing this?

Apart from just tinkering and learning, It’s something to help my family and I organize our lives, control devices in our home and it’s just plain cool! Earlier this year, I purchased a SmartThings Hub and it’s been a lot of fun controlling my thermostat and door locks. I also have an Amazon Echo which is an amazing device as well! I have a lot of plans with this project, which I will document in future posts. So stay tuned! For now, lets start by setting up the hardware.

Prerequisites

Here are links to the products and prices I purchased on Amazon at the time. The prices might vary slightly if you purchase them.

Bringing the total cost of this setup to: $147.95 (including shipping)

  • You’ll need a USB keyboard and mouse.
  • HDMI cable. I connected my PI (after the OS install) to a 27in monitor I had laying around. You’ll need this temporarily. You can connect to a laptop or any other device that accepts HDMI. I used it just to make sure the OS installed properly before I connected the touchscreen to the Raspberry Pi.
  • A computer with an SD card reader to install the image before inserting it into the Raspberry Pi.

Installing Raspbian Jessie on the SD Card

I decided to use the Raspbian Jessie with Pixel distribution for my setup. (There are many 3rd party images you could choose from also). For this example, we are using Jessie so you can download it here from the Raspberry Pi website by selecting “Download ZIP”. When the image file completes downloading, we are going to install the Raspberry Pi operating system image on an SD card. The image contained in the ZIP archive is over 4GB in size, which means that the archive may use features which are not supported by older unzip tools, on some operating systems. If you find that the download appears to be corrupt or the file is not unzipping correctly, please try using 7Zip (Windows) or The Unarchiver (Macintosh). Both are free of charge! In this setup, I am using a Mac. After the download completes, unzip the file you downloaded. Alright, here we go:

  1. Connect the SD card to your computer. Note that it must be formatted as FAT32. The one I purchased above was already formatted in FAT32.
  2. Open “Disk Utility”. To do this, click on the magnifying glass in the top-right corner of your computer screen. Type “disk utility” in the search box that opens, then click on the “Disk Utility” Application that comes up and click on “APPLE SD Card Reader Media”.
  3. Note the “Device:”; it will look something like disk(n) where (n) is a number (for example, disk1). Make sure you take a note of this number. Mine was disk1.
  4. Now, right click on “NO NAME” or “Untitled” on the left and select “Unmount” from the menu. This will unmount the partition so that you can write to the disk.
  5. Now open terminal and run the following command:

    Remember to replace (n) with the number that you noted before and (PATH_OF_THE_IMAGE_YOU_DOWNLOADED.img) to the path of the Raspbian Jessie image you downloaded. for example: my command was:

    The image file will be copied to the SD Card. You won’t get any feedback while it copies, and it can take several minutes. Leave terminal open and let it do its thing. When the copy is finished enter

    to eject the disk (again remembering to replace (n) with the number that you noted before). Remove the SD Card and insert it into your Raspberry Pi 3.

Booting Raspbian Jessie

Ok so that wasn’t so bad. Now connect the Raspberry Pi to a monitor, plug in a USB keyboard and mouse and connect the power cord to the Raspberry Pi to boot it up. Here’s how mine looks connected to my monitor. That was quite exciting!

Before we install the screen, let’s make sure we have the latest and greatest. The last 2 commands update the UI. Open up terminal and run the following commands on your Raspberry Pi:

Connecting the Touchscreen to the Raspberry Pi

  1. Power down the Raspberry Pi and disconnect the power cable, USB keyboard and mouse.
  2. Unpack the touchscreen from the static bag and place it on top of the static bag so that the screen is face down. (don’t remove the protection on the screen)
  3. Take the white ribbon cable (supplied) and connect it to the connector on the board, with the blue mark on one end facing up towards the back of the screen like shown below. I had a tough time getting it in there so take your time. You don’t want to damage it.
  4. Next, connect the four jumper wires to the display driver board. Here I am using Black for GND, Yellow for SCL, Green for SDA and Red for 5V.
  5. Now, we’re going to connect the other end of the jumper wires to the Raspberry Pi.

    You can see the schematic for the Raspberry Pi 3 below
    pi3_gpio
  6. After you’ve done that, mount the Raspberry pi onto the four spacers with the screws (provided).
  7. Alright! We’ve got everything connected. Last thing to do is add the screen to the case and power it on. Here’s how mine looks:

The next step, I’m going to work on is writing some software so stay tuned!

Life happens

I haven’t written a post in over two years but to be fair, life happens. So cliche I know… So what’s happened?

I started a new job

I started working at Buddy Media in 2011 which has since been acquired by Salesforce on August of 2012. It’s been really exciting and challenging learning about new technologies and how to scale application and infrastructure. I really feel it’s important to challenge yourself everyday. That’s how we grow as individuals and improve our skill-sets. So do yourself a favor, try not to remain stagnant in anything you do. If you aren’t being challenged, it’s time for something to change.

I bought a house

Home ownership is very exciting. It’s probably one of the biggest investments you can make in life. My only regret is not doing it sooner. My daughters are in better schools, we have a better life, we are building equity and we aren’t contributing to paying off someone else’s mortgage. Often, we are reluctant to make such a big commitment. After-all, it is 30 years. There’s also fear of not being able to afford all of the expenses that come with home ownership.

In my case, this was so far from the truth. I realized that I was spending money on foolish things and could cut-back on some expenses. When my wife and I decided to buy instead of renting, we took some time to go over our finances and see what our expenditures were to determine what we could afford (this is important to do at least once a year). We realized things that we could sacrifice for the sake of home ownership. We did it, and couldn’t be happier!

I unplugged

I went off the grid for several months. I didn’t use any social networks and stayed off-line. Spending quality time with those that are important to you is necessary.

One Of The Best Arguments Ever!

An atheist professor of philosophy speaks to his class on the problem science has with God, The Almighty. He asks one of his new students to stand and…..

Prof: So you believe in God?

Student: Absolutely, sir.

Prof: Is God good?

Student: Sure.

Prof: Is God all-powerful?

Student: Yes…

Prof: My brother died of cancer even though he prayed to God to heal him. Most of us would attempt to help others who are ill. But God didn’t. How is this God good then? Hmm?
(Student is silent.)

Prof: You can’t answer, can you? Let’s start again, young fella. Is God good?

Student: Yes.

Prof: Is Satan good?

Student: No.

Prof: Where does Satan come from?

Student: From…. God…

Prof: That’s right. Tell me son, is there evil in this world?

Student: Yes.

Prof: Evil is everywhere, isn’t it? And God did make everything. Correct?

Student: Yes.

Prof: So who created evil?
(Student does not answer.)

Prof: Is there sickness? Immorality? Hatred? Ugliness? All these terrible things exist in the world, don’t they?

Student: Yes, sir.

Prof: So, who created them?
(Student has no answer.)

Prof: Science says you have 5 senses you use to identify and observe the world around you. Tell me, son…Have you ever seen God?

Student: No, sir.

Prof: Tell us if you have ever heard your God?

Student: No, sir.

Prof: Have you ever felt your God, tasted your God, smelt your God? Have you ever had any sensory perception of God for that matter?

Student: No, sir. I’m afraid I haven’t.

Prof: Yet you still believe in Him?

Student: Yes.

Prof: According to empirical, testable, demonstrable protocol, science says your GOD doesn’t exist. What do you say to that, son?

Student: Nothing. I only have my faith.

Prof: Yes. Faith. And that is the problem science has.

Student: Professor, is there such a thing as heat?

Prof: Yes.

Student: And is there such a thing as cold?

Prof: Yes.

Student: No sir. There isn’t.
(The lecture the after becomes very quiet with this turn of events.)

Student: Sir, you can have lots of heat, even more heat, superheat, mega heat, white heat, a little heat or no heat.. But we don’t have anything called cold. We can hit 458 degrees below zero which is no heat, but we can’t go any further after that. There is no such thing as cold. Cold is only a word we use to describe the absence of heat. We cannot measure cold. Heat is energy Cold is not the opposite of heat, sir, just the absence of it .
(There is pin-drop silence in the lecture theater.)

Student: What about darkness, Professor? Is there such a thing as darkness?

Prof: Yes. What is night if there isn’t darkness?

Student: You’re wrong again, sir. Darkness is the absence of something. You can have low light, normal light, bright light, flashing light… But if you have no light constantly, you have nothing and it’s called darkness, isn’t it? In reality, darkness isn’t. If it were you would be able to make darkness darker, wouldn’t you?

Prof: So what is the point you are making, young man?

Student: Sir, my point is your philosophical premise is flawed.

Prof: Flawed? Can you explain how?

Student: Sir, you are working on the premise of duality. You argue there is life and then there is death, a good God and a bad God. You are viewing the concept of God as something finite, something we can measure. Sir, science can’t even explain a thought.. It uses electricity and magnetism, but has never seen, much less fully understood either one.To view death as the opposite of life is to be ignorant of the fact that death cannot exist as a substantive thing. Death is not the opposite of life: just the absence of it.
Now tell me, Professor. Do you teach your students that they evolved from a monkey?

Prof: If you are referring to the natural evolutionary process, yes, of course, I do.

Student: Have you ever observed evolution with your own eyes, sir?
(The Professor shakes his head with a smile, beginning to realize where the argument is going.)

Student: Since no one has ever observed the process of evolution at work and cannot even prove that this process is an on-going endeavor, are you not teaching your opinion, sir? Are you not a scientist but a preacher? (The class is in uproar.)

Student: Is there anyone in the class who has ever seen the Professor’s brain?
(The class breaks out into laughter.)

Student: Is there anyone here who has ever heard the Professor’s brain, felt it, touched or smelt it? No one appears to have done so. So, according to the established rules of empirical, stable, demonstrable protocol, science says that you have no brain,sir. With all due respect, sir, how do we then trust your lectures, sir?
(The room is silent. The professor stares at the student, his face unfathomable.)

Prof: I guess you’ll have to take them on faith, son.

Student: That is it sir… The link between man & god is FAITH. That is all that keeps things moving & alive.

I believe you have enjoyed the conversation…and if so…you’ll probably want your friends/colleagues to enjoy the same…won’t you? This is a true story, and the student was none other than…

APJ Abdul Kalam, the former President of India

Create custom named events in Backbone.js

In Backbone, Events is a module that can be mixed in to any object, giving the object the ability to bind and trigger custom named events. Events do not have to be declared before they are bound, and may take passed arguments. For example:

Show hidden files on Lion

To enable hidden files/folders in finder windows:

  1. Open Finder
  2. Open the Utilities folder
  3. Open a terminal window
  4. Copy and paste the following line in
  5. Press return
  6. Now hold ‘alt’ on the keyboard and right click on the Finder icon
  7. Click on Relaunch

You should find you will now be able to see any hidden files or folders. To revert:

Taking Screenshots in Mac OS X

Take a screenshot of the screen, and save it as a file on the desktop

Take a screenshot of an area and save it as a file on the desktop

Take a screenshot of a window and save it as a file on the desktop

Take a screenshot of the screen, and save it to the clipboard

Take a screenshot of an area and save it to the clipboard

Take a screenshot of a window and save it to the clipboard

In Leopard and later, the following keys can be held down while selecting an area (via Command-Shift-4 or Command-Control-Shift-4):

  • Space, to lock the size of the selected region and instead move it when the mouse moves
  • Shift, to resize only one edge of the selected region
  • Option, to resize the selected region with its center as the anchor point

Clear the terminal’s command history

Sometimes you just need to clear your history in Terminal. It’s actually pretty easy to do.

If you’d rather not have your history saved to a file at all, add the following line to your ~/.bash_profile:

This way, your command history is limited to only those commands you used during the current session. More information and options can be found on the bash man page

Ubuntu Package Management

Chances are good that you’re already familiar with apt-get, a command which uses the “advanced package tool” to interact with the operating system’s underlying package system. The most relevant and useful commands are, (to be run as root):

This command installs the package(s) specified, along with any dependencies.

This command removes the package(s) specified, but does not remove dependencies.

This command removes any “orphaned” dependencies which remain installed but are not used by any applications.

Removes downloaded package files (.deb) for software that are already installed.

Combines the functions of remove and clean for a specific package. Also removes configuration files for the given package.

Reads the /etc/apt/sources.list file and updates the system’s database of packages available for installation. Run this after changing sources.list.

Upgrades all packages if there are updates available. Run this after running apt-get update.
While apt-get likely provides the most often used functionality of the package management, apt provides additional information that you may find useful in the apt-cache command.

If you know the name of a piece of software but apt-get install fails or points to the wrong software, use search to look for other possible names, if you need to find out the name of a package that you know is in the system.

The search interface only provides package names. If you need to learn more about a package, including dependency information, version numbers and a basic description, run this.

Lists the packages that the specified packages depends upon in a tree. These are the packages that will be installed with the apt-get install command.

Generates and outputs a list of packages that that depend upon the specified package. This list can often be rather long.

Generates a list of the currently installed packages on your system. This list is often rather long, so it is best to pipe its output through a command like less.