Setting Up the Pi Zero Wireless Pan-Tilt Camera

Pages
Contributors: SFUptownMaker
Favorited Favorite 12

Test the Camera Web Interface

Now let's make sure the camera is working before adding in the pan-tilt functionality. To do so, we first must determine the IP address of the Pi Zero W. Type this command:

language:bash
ifconfig

Doing so should bring up the following information:

ifconfig results

There's lots of information here but we're only concerned with one small chunk: the "inet addr" entry in the "wlan0" section. In the example image above, that value is 10.8.252.217. This is the IP address of your camera.

Open up a web browser and type in that number plus "/html", for the web address. For example, I'd type in "10.8.252.217/html" in the address bar. If everything works as expected, you should be presented with a login request. This is the username and password that you entered when setting up the camera web interface, not the login information for the Pi itself! You'll be rewarded with an interface screen similar to the one below.

RPi Cam Interface

Adding Pan-Tilt Support

The RPi Cam Interface software supports pan-tilt functionality, but it needs to be enabled. To do this, there are several steps required.

First, we must tell the software that we wish to enable pan-tilt functionality. This is done by renaming a file hidden deep within the directory structure using this command:

language:bash
sudo mv /var/www/html/pipan_off /var/www/html/pipan_on

After running this command, go back to your web browser and refreshing the camera interface. Upon reloading, the page should now have four directional arrows directly beneath the image, as seen below.

Pi Cam interface with arrows

Next, we need to create a system pipe in order to send commands to the interface software that controls the pan-tilt functionality. A pipe is like a file, only it has no static contents. Only contents defined at run time by the program will control the motors.

language:bash
sudo mknod /var/www/html/FIFO_pipan p
sudo chmod 666 /var/www/html/FIFO_pipan

Controlling Motors on the Pi Hat

Now that we've created the pipe from the interface software, we need to fetch the control software that runs the servo motors. We've created a simple python program that does just that. Again, we're going to fetch that file from GitHub, using the following commands:

language:bash
cd
git clone https://github.com/sparkfun/RPi_PanTilt_Camera_Kit.git
python RPi_PanTilt_Camera_Kit/Firmware/pantilt.py &

The first command ensures that you are in the /pi user home directory; later instructions will depend upon that being the case. The second command fetches the program from GitHub, and the third executes it. As soon as you enter the third command, you should see and hear the motors twitch a little as the software centers them.

Now go back to the interface webpage and click on the various arrows. As you click on them, you should see the pan-tilt mechanism respond.

Finally, we need to set up our system to launch the pan-tilt software with the startup of the computer. To do this, we need to edit the "rc.local" file, which handles various on-boot functionality. To open the "rc.local" file, enter this command:

language:bash
sudo nano /etc/rc.local

This will launch the nano text editor with "rc.local" loaded into it. Use the down arrow key to scroll to the bottom of the file and add the following text just above the line that reads "exit 0":

language:bash
python /home/pi/RPi_PanTilt_Camera_Kit/Firmware/pantilt.py &

It's important that you place that line above the "exit 0" line or it will never be executed. Now, hit CTRL+o to save the file and CTRL+x to quit nano text editor.


Congratulations!

You've completed the initial setup of your Raspberry Pi Zero W Pan-Tilt Camera! This is outside the scope of the tutorial but there are a few more things you might want to do:

  • Set up motion activation - The page documenting the interface software has useful information about setting up motion activated image capture.
  • Set a static IP address - By default, the Pi Zero W may be assigned different IP addresses by the DHCP server on your network each time it boots. This can make interacting with the camera difficult, as you need to check the camera to figure out its IP address after each reboot. Setting up a static IP address is a complex topic and dependent upon the settings of your network, and is left as an exercise for the reader.
  • Communicate with the camera over SSH - Now that the camera is up and connected to your WiFi network, you no longer need to connect to it via the serial cable. Connecting via SSH is relatively simple, and we won't go into the details here.