Hardware to buy
Almost all of the hardware for the Pyball is available off the shelf at Adafruit. Feel free to shop around though; these are generic items and you might find better prices at Amazon or one of the big-time suppliers like Mouser, Digi-Key, etc.
Here's the list:
- Raspberry Pi 2 Model B
- It's worth spending the extra $5-10 to get the upgraded Pi 2, Model B. It has substantially more compute horsepower, which will come into play for analyzing the images on the fly or sending video.
- Raspberry Pi Camera
- USB WiFi
- If your mounting location has acccess to hard-wired Ethernet, this isn't necessary. If your Pyball is mounted some distance from a WiFi station, getting a WiFi adapter with a long antenna makes a substantial improvement in the connection.
- 5V 2A Micro-USB power supply.
- You'll want the 2A version to make sure the Pi has enough juice to run the peripherals (camera & WiFi). Adafruit specs the power supplys up a bit (5.1V) to account for power loss in the cord. Not a bad idea.
- Case
- I used the Adafruit weatherproof case, but really, look at where you'll be mounting it. If you can see what you want from an office window, you might not need a case at all.
- Camera mount
- I found the Pimoroni Camera Mount useful for mounting the camera in the case.
- 16G Micro-SD card
- These are available for cheap from Amazon. You'll want at least 16G to have working space for your captured data. Even 16G is still less than $10.
All tolled, the hardware runs about USD$100.
Software Setup
The Raspberry Pi comes without any software or boot media. Installing Raspbian is just the first step of many for getting the system put together. I installed Raspbian (vs. NOOBS) because I'm not experimenting with any other OS configuration.
For the first Raspbian boot-up, plug the Pi into a screen and keyboard. You'll be presented with a dialog to install various system components. You'll want to add ssh
support, for remote access, and definitely enable the camera drivers and configuration.
My router requires the hardware MAC (media access control) address for authentication. To get these, use the command:
$ ifconfig | grep HWaddr
eth0 Link encap:Ethernet HWaddr b8:27:eb:ea:7c:b9
wlan0 Link encap:Ethernet HWaddr ac:a2:13:39:ce:f1
$
The hex numbers give the hardware addresses; eth0
is the wired address and wlan0
is for the WiFi. Note: I learned the hard way the Rasp Pi can't easily support two network connections. If you're using WiFi, unplug the Ethernet cable, and vise-versa.
You'll need to set up new users. You should add whatever user you choose to the "sudoers" list, so the adminstrative command sudo
is available:
$ sudo bash
# cat >> /etc/sudoers eyeball ALL=(ALL) NOPASSWD: ALL
^D
To make sure you're running the latest software:
$ sudo apt-get update
$ sudo apt-get upgrade
To set your time zone (important for this project):
$ sudo cp /usr/share/zoneinfo/America/Los_Angeles /etc/localtime
(Substitute your favorite time-zone city for Los_Angeles
, use ls /usr/share/zoneinfo/*/*
to see the full list)
To make sure enough USB power is available to drive the Wifi, add the line
max_usb_current=1
to the file /boot/config.txt
and reboot the Pi.
The camera fails if the user taking the picture isn't a member of the video
group. Fix this with
$ sudo usermod -G video <username>
$ sudo usermod -G video www-data
The second line is to make sure the web server can access the video hardware. Note: May need to do the second step after installing the apache2 web server; see below.
Finally, I removed some software I had no use for (Scratch, a toy programming language & Supercollider, an audio tool):
$ sudo apt-get remove scratch
$ sudo apt-get remove supercollider
$ sudo apt-get autoremove
Hardware Setup
Once you've collected the items from the shopping list (under "Components") the configuration of the hardware largely depends on where it's deployed. If you have a comfortable office or home window overlooking what you want to watch, you may be able to get away with something a simple as duct taping the camera to the window. In my case, I wanted to mount the camera outdoors, just under the eves of our garage roof. This requires mounting the project in a weather-proof case.
To cut down on internal reflection, I found a piece of thick black cardboard, and trimmed it to fit just inside the clear top of the case. I cut a hole in the cardboard for the camera to peer through, then beveled this and colored it black with marker (again, to cut down on internal reflection). Using the Pimoroni camera moiunt, I taped the camera onto the back of the cardboard. The Ras-Pi is mounted to the back of the case with foam mounting tape; and a hole just large enough for the micro-usb jack to pass through was made for the power connection.
I use pegboard to fashion a mounting plate. This is thin, soft pressboard with pre-drilled holes on a 1" grid. I attach it to the back of the plastic case with wood screws, then use screws to mount it to the wood at the back of the eves. Adjusting the position of the camera on the board vertically aims the camera.
The power cord is routed through a thin gap in the flap at the top corner of the garage door. While it's a bit unsightly to have the cord visible, this was much simpler than drilling holes in the stucco walls of the garage. The power cord is carefully duct-taped to the inside of the garage wall to keep it clear of the moving door mechanism. The wall-wart at the end attaches to an extension cord supported by cable hangers.
WiFi Issues
The first WiFi adapter I used was a small USB adapter about the size of a thumb drive. While it worked, the Pyball is located about 80' (24 m) from our WiFi base station. The connection worked, but just barely, typically experiencing packet loss of up to 60%. Using ssh or telnet to talk the RasPi was painfully slow. Switching to Mosh helped considerably for talking to Pyball, but retrieving the data wasn't working reliably.
The solution was to use a WiFi adapter with a longer antenna. This adapter has a longer antenna (about 8") and a more powerful transmitter. This solved the communications problems!