"Raspberry Eye" - a webcam on a servo

Original author: Matt Stultz
  • Transfer


Webcams are a fun and useful thing. And the ability to remotely control their viewing angle further expands their usefulness. There are many options for use, most often cameras are used to look after a house on vacation or for animals. Or, for example, you can give your friends the opportunity to control the camera installed in another country so that they “participate” in a certain event. In any case, a camera connected to the Internet on a turntable gives you the opportunity to better control the situation. This post describes one of many do-it-yourself managed webcam projects.

We bring Pi to the network


The Raspberry Pi is an excellent base platform for designing internet-connected devices. Also for such tasks, the Flask framework is very convenient . It allows you to use existing Python applications (the preferred language for development for Raspberry Pi) and add HTML templates to them to create a web interface for the end user. This project uses a clean template, so you can easily figure it out and modify it at your discretion.

Streaming video from Pi


First you need to find a way to broadcast a video stream through Pi to the Internet. When using such a low-power system, every bit counts, and therefore compression and streaming in real time can be too heavy a load on the system. As a result, MJPG-Streamer was chosen because it showed very high performance.

Servo control


Also needed a way to control the servomotors to pan / tilt the camera. The standard library in the Raspberry Pi for accessing I / O pins is called GPIO . Although it’s easier to perform simple actions with it, it provides too low accuracy for controlling servomotors. After many trial and error, an alternative library called RPIO was chosen . With its help, I got access to a semi-hardware-controlled PWM signal . It was the last mosaic element to build a fully functional project and a great starting point for connecting to the Internet!

All code for this project can be downloaded from Github , and 3D models from Thingiverse .

NOTE: ELinux has a list of Pi compatible USB webcams . This project uses the C260 webcam, which may already not be available. C525 , according to reviews, “works well without add. Power ”, but not tested with our design. C270 "works well with ext. Power ”as an active USB hub. 3D models of the design are sharpened for C260 / 270, but you can modify them to fit your camera.

Step # 1: Burn the image to the SD card




• Raspbian, adapted for the Raspberry Pi Linux distribution, was chosen as the OS for this project. Most of the standard settings are still in place, including the password (raspberry). After the installation is complete, you will need to log in, run raspi-config, change the password and other settings to your liking.
• A lot of changes need to be made to the Raspbian image to make this project work. You can download the finished PiCam image from cdn.makezine.com/make/WeekendProjects/HomeSentrySecurityCamera/PiCam.img and write it to your SD card.
• The story of the image recording itself draws to a separate article. In this case, you can follow the guide from the Raspberry Pi Foundation at http://elinux.org/RPi_Easy_SD_Card_Setup .

Step # 2: Print, Make, or Buy a Case




• In order to place Pi and create a base for the pan / tilt mechanism, I developed a case model for a 3D printer. This is a redesigned version from Thingiverse user Josh Campbell . You can download and from here http://www.thingiverse.com/thing:274468 .
• If you do not have access to a 3D printer, you can buy a case at Shapeways or any other online store. Or glue yourself from plastic scraps.

Step # 3: Prepare the power cable for the servomotors


• Cut a small Micro-B plug from one of your two USB cables.



• Remove about 2.5 centimeters of external insulation, inside you will find four wires (black, red, white, green).
• Strip about 6 mm of insulation from the black and red wires. Using a multimeter, make sure that it is really “+” and “earth”.
• Remove the cable shielding and cut the white and green wires.



Step 4: Soldering the cable


• Cut three pieces of heat shrink tubing: one 13 mm and two 9 mm each.
• Trim the tips from the two double jumpers.



• Wear a heat-shrink wire 13 mm and push a couple of centimeters so as not to hurt when soldering.



• Carefully separate and wind the end of the red wire around both short leads of one of the jumpers.
• Solder the wire to the jumper and make sure it is firmly connected to both terminals.
• Do the same with the black wire.
• Put the remaining heat shrink tubing on each set of jumpers and pull them out a little, covering the weld point. Lift the long tube so that it covers the white and green wires that you cut earlier.
• Heat shrink.



Step # 5: Install the rotation motor


• Pass the wire of one of your servomotors through a large rectangular hole and insert a motor into it. If it gets stuck, use a small file or sandpaper.
• When the servomotor is in place, screw in the 2 long screws to secure the motor.







Step 6: Add the tilt motor


• Pass the connector of the second servomotor through a small rectangular hole. Both wires from the motors should now go into the middle of the case.
• Do not install this motor yet.



Step number 7: Connecting motors


• Pass the end of the jumper wire through the round hole in the side of the housing.



• Connect the leads of the black wire to the holes in the servo connectors corresponding to the brown wires.
• Connect the leads of the red wire to the holes in the servo connectors corresponding to the orange wires.



• Take the two purple wires with jumpers and insert each into the holes corresponding to the yellow wires.



Step 8: Install the tilt motor


• Insert the tilt servo motor into the same shaped hole on the larger of the two printed holders.



• Fasten the motor with two long screws.



Step # 9: Connect Servo Motors to Pi



• Two purple wires must be connected to the Raspberry Pi. These are control wires through which the signal for changing the position of the motors will be sent.
• The signal wire from the turning motor must be connected to terminal 23. This is the eighth terminal in the outer row.
• The signal wire from the tilt motor must be connected to terminal 22. This is the eighth terminal in the inner row.



Step # 10: First Turn On


• Insert your formatted SD card into the Pi and connect the Ethernet cable. If this is the first OS launch, you may need a USB keyboard, mouse, and HDMI monitor.
• Plug both (one from Raspberry, the other from motors) the USB cable into the dual USB charger and connect the USB cable to the Raspberry Pi next to the SD card. Now Pi should turn on.



Step # 11: Resetting Servo Motors


• To connect remotely to a Pi, use the SSH utility built into Mac and Linux. (If you are a Windows user, you can use Putty as an SSH client. Hey Microsoft, give us a native SSH!)
• In the terminal window, type: ssh pi@picamand press Enter. If you are unable to connect, try the command ping picam. If you get an error message ping: cannot resolve picam: Unknown host, connect a monitor and keyboard to find your IP-address (using ifconfig utility), and then connect using your IP-address, like this: ssh pi@192.168.1.10.
• After connecting, go to picam directory: cd picam
• Run the script picam.py on behalf of the root: sudo python picam.py. You should see the output of the script:
Using hardware: PWM
PW increments: 10us
Initializing channel 0...
add_channel_pulse: channel=0, gpio=23, start=0, width=154
init_gpio 23
add_channel_pulse: channel=0, gpio=22, start=0, width=154
init_gpio 22
* Running on 0.0.0.0:80/

• After running the script, you should hear how both servomotors return to their starting position.
• Press Ctrl + C to end the program. After that, enter sudo shutdown -h nowto turn off Pi. After shutting down (usually takes about 30 seconds), disconnect the power wires from the Raspberry.

Step 12: Install the framework


• Now that the servomotors are in the zero position, you can attach frames to them. Start with the bigger one, from the frame of the rotary motor. Position it so that the long side is parallel to the chassis and the servomotor is on the same side as the USB and Ethernet ports on the Pi. Secure the frame with a small screw.



• Pass the screed through the lower holes of the tilt frame. The ends should be pointing up until they connect.



• Put on the tilt frame to the servomotor on the swing frame. Tighten with a small screw.



Step 13: Mounting the Camera


• Mount the camera on a frame and secure with a tie. Make sure you tighten it tightly so that it does not touch the screw head or the second frame.





• Connect the camera to one of the USB ports and insert the SD card, power cable and Ethernet cable.



Step 14: Camera Launch


• After loading Pi, reconnect via SSH.
• First, go to the folder containing the program with which you will stream the video. In the terminal, type: cd ./mjpg-streamer/mjpg-streamer
• Now run mjpg-streamer with the command: ./mjpg_streamer -i "./input_uvc.so" -o "./output_http.so -w ./www" &



You will see some errors, but they relate to unused modules. The LED on the webcam should light up and at the end of the program output you should see: • Now press Ctrl + C to return back to the terminal. Type and press Enter to return to the root directory.
o: www-folder-path...: ./www/
o: HTTP TCP port.....: 8080
o: username:password.: disabled
o: commands..........: enabled

cd

Step # 15: Appearance


• Now that everything is assembled and working, it's time to give it some sort of look.
• In the terminal, return to the picam: directory cd picam
and launch the PiCam application: sudo python picam.py
• When the application starts, go to the browser in the address picam. You should see the video from your camera and control buttons. Each press rotates the camera 10º.



• To access the camera from the Internet, you need to configure port forwarding on the router. One port must be forwarded to port 80 (for a web page), and one port to port 8080 (for broadcast video). Details about port forwarding and server startup on Pi can be found at http://raspberrywebserver.com/serveradmin/get-your-raspberry-pi-web-site-on-line.html. However, do not forget that in this case the camera is not protected from intruders in any way, and you will need to somehow solve the security problem.

In the end


You can add Wi-Fi to this remote webcam project, use a weatherproof case for outdoor use, or even hide the camera in an ordinary thing like a book.

Experiment!

Also popular now: