After binge-watching the Ben Heck Show, and hearing about this community constantly, I also stumbled on this blog entry by aaroNiGHTS, and decided that with a baby due in the next few months, it seemed like the stars had aligned, and now was a perfect time to stay up much too late working on a brand new project.
My only real experience with Linux up to this point has been with the Raspberry Pi 2. I've built a RetroPi for playing old video games in my living room TV, and that was terribly fun, and pretty doable for a newbie who's computer literate but not familiar with Linux. So far, getting these projects to work has felt a whole lot like playing .Conf Hunter. Using the Pi for projects that others have already undertaken is a good way to start, as far as I'm concerned, because the community is so strong, and people have run into, solved, and documented many of the issues you'll run into. I'm not writing this blog as an expert, but as a beginner+1 with the hopes that the information / links I collected will be helpful to others. Also, I just wanna show my work.
The Project
I built a baby monitor that streams video and audio to local browsers, and can see in the dark. It doesn't look creepy at all, see?
Hardware Ingredients
Raspberry Pi 2
Pi 2 Case
Cheapo Labtec clip-on mic
USB sound card
USB WiFi dongle
Camera Stand (with grabby legs)
Software Ingredients
Raspbian Jessie
I'm assuming you've got Raspbian installed on your Pi. If you need help with your OS, I'll need to send you hunting on the internet, as I'm not any of guru, let alone one that knows multiple flavors of Linux. I'm using Raspbian Jessie.
I was only able to get as far as I have with this project by breaking it down into small manageable chunks. If I had just plugged all the stuff in that I thought I needed, then turned the thing on, I would never have able to figure out which particular thing was misbehaving when it inevitably didn't work. Even so, it took a while to really iron the streaming out, and it was helpful to have gone through the components one by one beforehand so I had a feeling for each of them.
Camera Setup
So with that in mind, let's set up the camera first. Do it only when the Pi is off, and be gentle when doing so, as this type of connector can break when mishandled. I used double-sided foam tape to fasten the camera to the Pi case (for now).
Rather than me try and reinvent the wheel, follow this guide to make sure your Raspberry Pi is up to date. Then, follow this other guide to get yourself acquainted with the PiCam via Python. This group of pages will also be handy if you want to use commands instead of Python. I found it very easy to get the camera working. Once I knew it was working, I moved on to the microphone situation.
Sound Setup
I plugged in my USB Sound Card, which was a cheapo from Amazon, and tested the sound playback by plugging in speakers to it, to make sure it was operating. Then I used the command
$ arecord -l
(which is a lowercase L) to list all of the available sound devices. This info will come in handy.
I then plugged my little Labtec mic into the mic input on the usb sound card, and ran
$ alsamixer
which allowed me to set the levels and such for the device. I found this pretty easy to use, as the handful of commands were listed on the screen.
Without much trouble, my Pi (with speaker plugged in) was able to hear and play the mic's input.
Streaming Software Setup
Now that I've got sound and video inputs on my Pi, I'm using a terrific package called uv4l for Linux that allows you to stream video and audio from (in this case) your Raspberry Pi's camera and mic.
Here are the instructions I used for getting uv4l running with the required extras. I would recommend you follow those. If you followed the earlier posts as well, you've probably done your apt-get update . I installed:
uv4l
uv4l-raspicam
uv4l-raspicam-extras
uv4l-server
uv4l-uvc
uv4l-xscreen
uv4l-mjpgegstream
uv4l-dummy
uv4l-webrtc
uv4l-xmpp-bridge
These are all explained some on the uv4l installation page linked above, and also have their own information floating out there as well. I probably did not need all of these, but I wasn't quite sure what did what, and I didn't figure it would hurt to grab them.
Next I needed to set the .conf file for uv4l, with this command:
$ sudo nano /etc/uv4l/uv4l-raspicam.conf
I recommend you take some time to look at this file, and look up the various options in the Raspicam Documentation to see what they're all for. Once I got this far, I figured I ready to go. I fired up uv4l just by typing:
$ uv4l
then I found my local internal network IP address by using the command:
$ ifconfig
and finally I opened a browser on another computer in my home network and connected to the Pi's address via port 8080 (which looks like 11.23.0.9:8080 - your Pi's address will be different). I was greeted with a nice landing page offering several different ways to connect and stream.
For my purposes, I found that the Multi p2p conference option was the easiest to get working. Be aware that the multi p2p conference starts up MUTED, and when viewing it you need to un-mute to hear the microphone's sound. A lot of time was spent troubleshooting before I discovered this!
It seems that simply running $ uv4l was not grabbing the .conf file I had tweaked. I was able to view my stream, but not at the resolution I had specified, and some of the other options weren't quite right. Instead, I added an argument to force it to grab my config file:
$ uv4l --config-file /etc/uv4l/uv4l-raspicam.con
More Sound Settings
Despite discovering the sneaky mute button, I still wasn't getting the microphone's signal on the stream, even though the mic was working locally on the Pi itself. I tried lots of different things, and ultimately found how to make sure the mic input on my USBsound card was the default device. Here is a StackExchange post that helped me troubleshoot why my device wasn't using the microphone when streaming. This answer in particular did the trick for me.
Since I'm using Raspbian Jessie, I used this command to add the default audio settings (to what had been in my case a blank configuration file):
$ sudo nano /etc/asound.conf
and I added this, from the StackExchange post I linked to above:
pcm.!default {
type hw
card 0
}
ctl.!default {
type hw
card 0
}
Make sure to change the card number to match what you discovered when you ran arecord -l or aplay-l .
Finally, I was able to stream audio and video pretty clearly from any browser and device on my local network. I haven't set up any way to do this from outside my network because I don't want weirdos staring at my baby.
Illumination Circuit
The Pi NoIR offers 8 megapixels, and is sensitive to Infrared light, so it's great for a night-time camera. It plugs right into the Pi's camera input, and works out of the box. You need an IR light source in order to illuminate things in the dark, so for starters, I built a sloppy battery-powered circuit that I purposely don't have a picture of. It was based on this article, which helped me design my circuit, diagrammed below.
(I've updated this schematic to correct several silly errors)
NOTE: I want to caution you against taking my electronics schematic as advice, because I am very much a beginner with designing circuits. I used to build project kits in high school, but that's as much as I know. Instead, click on some of the links I'm sharing and go learn from all the smart people 
I have two resistors in parallel, because I needed around 62 Ohms of resistance and the RadioShack package of resistors i bought didn't have any. These two together offer 50 Ohms of resistance, which was close enough for my testing needs. I learned how to calculate resistance in series and parallel from this page. The resulting amperage on the LEDs should be ~ 60 mA, which is below the maximum of 100 for these.
The 3V DC is coming from two AA batteries in series, which each provide 1.5 volts. I've got a simple switch to allow me to turn the thing on and off. I don't know how the battery drain will be. Some fancier circuits I've seen have a light sensor attached that will open the circuit (turn it off) when it's not dark.
To understand how voltage, current, and resistance are related, follow this rabbit hole!
The circuit is effectively illuminating objects up to about 3 feet away, but beyond that, the picture gets dark, at least for the PiNoIR. I'm not sure it will do the job of lighting up the baby in the dark, so I may have to build a bigger one (muahaha) SEE BELOW! I am gathering the courage to try and tap into the Raspberry Pi's GPIO 5 volt pin, but I haven't learned enough about how to do that safely yet.
Of course, I want to find a way to save power and not have the IR on all the time, but I also don't want to leave the IR LEDs on all the time because it may not be great for baby's eyes. Since human eyes can't see the IR light, it could be very bright without baby's eyes realizing it and reflexively closing for protection. To adjust for this, I'll ultimately try to set up LEDs that are a little brighter, but add some diffusers in front of them to spread the light out some. If I can also get the light sensor integrated so it can automatically turn the circuit off in the day time, that will be even better.
Ultimately, if you aren't interested in the tinkering and experimenting I described above, you're probably better off shopping for some PiNoIR accessories. There are almost certainly pre-built circuits you can use for IR illumination.
Next Steps
So far, I'm very happy with the core functionality of this project. Possible improvements and additions for the future:
- Safe power-on and reset buttons on the Pi case
- GPIO-powered IR illumination circuit
- Media player on the Pi to allow us to trigger soothing sounds (like gentle rain, ocean waves, etc.) playing back to help the baby sleep. I'm already working on this, and will possibly use Mopidy to control playback, and the pictured speaker below. Maybe my wife and I can put the baby back to sleep without getting up from our beds!
Please don't be shy about commenting! I wouldn't want to misinform anyone here, and half of the useful information I've found came from comments in others' posts, blogs, and sites. I'll hope to update with new info as I get this fine-tuned.
UPDATE 9/29/2016
So, the 2 LEDs I used didn't appear to be enough, and I did indeed build a cleaner circuit with 4 instead. I then discovered how much of an effect the camera's ISO exposure, brightness, contrast, and saturation settings can have, and I may not have needed to do this. But now I have something I can show you. The resistors and LEDs are on two little square board chunks, separated by electrical tape and hot glue (they won't short, trust me!). I'll probably just velcro this to the top of the Pi case for the short term, with the little speaker behind it.
Even more exciting is that I was able to set up Mopidy as a way to control playback of digital music on the Pi. I have audio coming out of the USB sound card, and I'm playing some some modified following open-source sounds:
Raining In The Bart
Soft Rain on a Tent & Bird Ambiance
Gloucestershire, England » England: A River Spring in Spring!
Rain, thunder, then..."silence"
Feb 25 1988 730-750 a.m. or so (which, first of all, sounds just like the sounds they used in Star Trek 4, and second of all, could be re-punctuated "amoroso" because I bet the whales are totally flirting with each other.)
Rain Loop Ontario
Atmospheres » Dawn_1
I modified these in a few ways using Audacity to:
1) convert them to mono mp3 files at 320kbps
2) normalize their levels so they would all play at roughly equivalent volumes
3) ensure gentle fades for the sake of keeping baby asleep
4) removing or de-emphasizing moments that were extra loud and would be startling
I've got the MPDroid app on my Android and can trigger basic playback instructions for any of these mp3s. It's meant as a complete media server solution (and you can do lots with it!) and the documentation is pretty great (as is the documentatino for uv4l, by the way). Still, both packages were tricky for me to dial in, and the only advice I can give is if you're trying to troubleshoot something, only change one parameter at a time, so you know which tweak fixes your issue.











Top Comments
-
jkutzsch
-
Cancel
-
Vote Up
0
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
-
dammitmcgee
in reply to jkutzsch
-
Cancel
-
Vote Up
+1
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Comment-
dammitmcgee
in reply to jkutzsch
-
Cancel
-
Vote Up
+1
Vote Down
-
-
Sign in to reply
-
More
-
Cancel
Children