Webcams are a fun and useful tool. Being able to control where they’re looking remotely, though, takes their usefulness to a whole new level. Whether you’re watching your pets while you’re away or allowing friends to participate in an event from the other side of the world, a web-enabled camera puts the end user in control of the experience.
Put a Pi on the Web
The Raspberry Pi provides a perfect base platform for creating internet-connected devices. When researching how I was going to connect my device to the web, I ran into Make:’s very own Matt Richardson’s post describing how to use the Flask framework to easily create projects for the web on the Raspberry Pi. Flask allows you to take your existing Python apps (the preferred language for developing applications on the Raspberry Pi) and add in an HTML template to provide a web-page interface for the end user. In this project I provide an HTML template document that’s pretty bare-bones, so it’s easily understood by anyone who wants to look under the hood and also provides a good starting point if you want to customize it for yourself.
Stream Video from the Pi
The next tool needed was a way to send video from the Pi across the web. When using a less powerful system like the Pi, every little bit counts, and the real-time compression and streaming of video can be a huge drain on a system. After trying a couple of different options I opted to use MJPG-Streamer. The performance from MJPG-Streamer was hands-down the best of any service I tried on the Raspberry Pi.
Control the Servomotors
Finally I needed a way to control the servos for the pan/tilt mechanism. The standard library on the Pi for accessing the I/O pins is called GPIO. While GPIO makes it easy to do basic actions, its software-based PWM system is very inaccurate and temperamental for controlling servomotors. After running into problems and having a few friends review my code to ensure I wasn’t going mad, I decided to abandon GPIO in search of a better solution. The winner was an alternative to GPIO called RPIO. With RPIO, I had access to a semi-hardware driven PWM signal. This final piece brought it all together into a fully functional project and a great starting point for connecting your world to the web!
All the code for this project can be downloaded from Github and the 3D models from Thingiverse.
NOTE: eLinux has a list of Pi-compatible USB webcams. This project was built using the C260 webcam, which may no longer be available. The C525 reportedly “works fine without powered hub” but was un-tested with our design. The C270 reportedly “works fine with external power” in the form of a powered USB hub. The 3D design files are for the C260/270 but the premise for the design can be modified for the webcam of your choice.
1. Flash the SD card.
2. Make (or buy) the 3D-printed case.
3. Prepare the servo power cable.
4. Soldering the cable.
5. Mount the pan motor.
6. Add the tilt motor.
7. Wire the motors.
8. Attach the tilt motor.
9. Connect the servos to the Pi.
10. Power it up.
11. Zero the servos.
12. Attach the servo arms.
13. Attach the camera.
14. Launch the camera.
15. Wrap it up.
Each Friday is PiDay here at Adafruit! Be sure to check out our posts, tutorials and new Raspberry Pi related products. Adafruit has the largest and best selection of Raspberry Pi accessories and all the code & tutorials to get you up and running in no time!
Have an amazing project to share? Join the SHOW-AND-TELL every Wednesday night at 7:30pm ET on Google+ Hangouts.
Join us every Wednesday night at 8pm ET for Ask an Engineer!
Learn resistor values with Mho’s Resistance or get the best electronics calculator for engineers “Circuit Playground” – Adafruit’s Apps!
Maker Business — “The Entire History of Kickstarter Projects, Broken Down by City”
Wearables — Glow with fur
Electronics — USB Powered Mayhem!
Biohacking — mPort is Making a 3D Body Scanner Booth
No comments yet.
Sorry, the comment form is closed at this time.