BbPiCam
Raspberry Pi Baby Monitor
Install / Use
/learn @jasaw/BbPiCamREADME
bbPiCam
Raspberry Pi Baby Monitor.
Features:
- True day and night vision.
- 1280 x 960 HD video quality.
- RGB LED shows temperature at a quick glance.
- RTSP & RTMP audio video stream (playable on web browsers and Android devices).



Hardware
Setting up the hardware requires a fair bit of soldering and drilling. Let's get started ...
Bill of Materials
- Raspberry Pi Model B (rev 2)
- SD card
- Pi NoIR camera board - http://www.adafruit.com/products/1567
- AudioCODEC for mbed - RS Components part number: 754-1974
- RDing TEMPer2 Temperature sensor
- Diffused RGB (tri-color) LED - http://www.adafruit.com/products/159
- 5V 1A DC voltage regulator (e.g. LM7805) or DC-DC converter
- Electret Microphone Amplifier - MAX9814 with Auto Gain Control - http://www.adafruit.com/products/1713
- CS Mount Dual IR-Cut Optical Filter for CCTV CMOS Board Camera - http://www.camera2000.com/en/cs-mount-dual-ir-cut-optical-filter-for-cctv-cmos-board-camera.html
- IR Light Board for CCTV Camera Housing - http://www.camera2000.com/en/24-leds-45deg-25m-view-ir-light-board-for-dia-60mm-camera-housing.html
- PCA9635 LED controller
- 12V DC 1A regulated power adaptor
- Panel Mount Tactile Pushbutton
- Panel Mount 2.5mm Bulkhead Male DC Power Connector
- Enclosure
- Heatshrink
Pi NoIR Camera, IR Light and IR-Cut Controller
There are 3 headers on the IR-Cut Controller board:
J1 (Power input):
- pin 1: 12V
- pin 2: GND
J2 (Power output):
- pin 1: 12V
- pin 2: GND
- pin 3: Day/Night control signal input (solder to photovaristor switch IC output of the IR board)
- pin 4: Standard power level output (under IR-CUT condition)
J3 (IR-CUT connection)
Pin 3 of J2 (yellow wire) needs to be soldered to the output of the 3-pin photovaristor switch IC on the IR Light board. I recommend soldering it via a 1-pin connector so it can be disconnected when mounting to an enclosure.
Connect the J2 12V output connector (pin 1 & 2) to the IR Light board 12V input. Warning: My 12V connector had the wrong polarity. Make sure you check it and switch the wires on the connector if required.
Remove the protective tapes on the Pi camera and IR filter.
Now we just need to line up the 3 components this way: Pi Camera --- 3mm Spacer --- IR Filter --- Spacer --- IR Light Board
The IR LEDs emit IR light mostly at the front, but some light are reflected back through the LED plastic case. This reflection is strong enough to interfere with the Pi camera if you don't have a something to block the light from the sides. I used heatshrink on the IR LEDs to stop the light reflection.
I2S Audio Codec
A reliable way to enable audio input on the Pi is via the I2S interface. I2S is short for Inter-IC Sound. Only the Rev 2 and Model B+ Pi expose the I2S signals.
The I2S signals are exposed via P5 header, next to the P1 header. Solder a header on it. Refer to RPi Low-level peripherals for pinouts.
As for the audio codec, I used the mbed AudioCodec board based on TI TLV320AIC23B. I had to make a few modifications to the board, which may not suit everyone. Those who are not comfortable with soldering can explore other codecs like the PROTO audio codec board based on WM8731. This I2S guide by Koalo may be helpful.
Modifications made to the mbed AudioCodec board:
- MIC Bias (pin 17) and MIC Input (pin 18) of the IC are not exposed on a connector, so I soldered wires from the MIC BIAS and MIC IN pins to the unused header. I also soldered a wire from the GND via to the unused header.

- The 12MHz crystal was removed and MCLK (pin 25) and wires soldered from the MCLK pin to an unused header pin.
The crystal was removed so GPCLK0 signal can be fed as the MCLK to ensure MCLK and I2S BCLK are synchronous. This was done after I discovered both clocks were drifting, causing clicks on the 1st channel of the audio input. I did not manage to remove the clicking noise completely, so I ended up configuring ffmpeg to only use channel 2 and output mono audio.
Connection between the mbed AudioCodec and the Raspberry Pi B:
mbed AudioCodec | Raspberry Pi
----------------- +---------------------
BCLK (I2S) | P5 - 03
CS | 3V3
DIN (I2S) | P5 - 06
DOUT (I2S) | P5 - 05
LRCOUT (I2S) | P5 - 04
MODE | GND
|
SCLK (I2C) | P1 - 05
SDIN (I2C) | P1 - 03
|
MCLK | GPCLK0
If using Raspberry Pi B+ or Pi2 B:
mbed AudioCodec | Raspberry Pi
----------------- +---------------------
BCLK (I2S) | J8 - 12
CS | 3V3
DIN (I2S) | J8 - 40
DOUT (I2S) | J8 - 38
LRCOUT (I2S) | J8 - 35
MODE | GND
|
SCLK (I2C) | P1 - 05
SDIN (I2C) | P1 - 03
|
MCLK | GPCLK0
The 4 I2S wires and MCLK wire have to be kept as short as possible to reduce electrical interference as they will be carrying high speed signals.

The I2C pins are used for configuring the codec.
MIC Input
I made my own mic front-end circuit, but I recommend one with automatic gain.
You can use this mic resistor network but the input gain is not high enough even with the 20dB gain enabled on the TLV320AIC23B.

The components in the grey box can be replaced with a mic pre-amp circuit with automatic gain control.
Adjust the R1 resistor to set the gain.
RGB Temperature LED
RGB LED is controlled by PCA9635 driver. There are other more suitable LED driver alternatives. I chose this part because I have left over from another project.

Shutdown Button
The "Shutdown" button does the obvious, shuts down the device when pressed.
Button is connected to P1-11 and pulled up to 3.3V via 10K resistor.

Software
This guide only applies to Raspberry Pi B.
Software modifications I've done so far:
- I2S and rpi_mbed drivers to use GPCLK0 as MCLK.
- Reduced the ffmpeg's default max_interleave_delta value. By default, ffmpeg buffers both audio and video stream in attempt to synchronize them, but ffmpeg is unable to synchronize the streams because raspivid video output does not contain timestamp information. By reducing the max_interleave_delta value, the de-sync between audio and video can be reduced. The only problem is, setting max_interleave_delta from command line did not do anything, so I just changed the default value as a quick workaround.
Before we start, you'll need a Linux based Raspberry Pi Operating System. I strongly recommend Raspbian unless you know what you are doing. I use Raspbian Wheezy 2014-06-20.
If you're using model B+ or 2 B, I recommend the latest Raspbian Jessie image with device-tree enabled. You can load the I2S driver by adding dtoverlay=i2s-mmap to /boot/config.txt. I haven't got time to migrate this project to the Pi2, so you'll have to figure the rest out yourself. Sorry...
While waiting for the Raspbian installation onto an SD card, we download the required software on a PC.
git clone https://github.com/jasaw/bbPiCam.git
cd bbPiCam
git submodule init
git submodule update
This is going to take a while, so go do other things and come back later ...
Now apply patches.
patch -p1 -d kernel/linux < kernel/add-rpi-mbed.patch
patch -p1 -d kernel/linux < kernel/add-leds-pca9635.patch
patch -p1 -d programs/ffmpeg < programs/ffmpeg-reduce-max-interleave-delta.patch
patch -p1 -d programs/TEMPered < programs/TEMPered-fix-broken-cmakelists.patch
patch -p1 -d programs/TEMPered < programs/TEMPered-add-temper2led.patch
Configure the Pi
Enable I2C and Camera on the Pi. On the Pi, run:
sudo raspi-config
Install build tools
sudo apt-get install build-essential
Kernel and Drivers
The kernel needs to be configured and cross compiled, then transfered to the Pi.
Change into the kernel directory and set things up:
cd kernel
mkdir modules
Important: Edit the build_env file to reflect your directory structure.
Load environment variables:
. build_env
Clean up
cd linux
make mrproper
Get kernel config from Pi running Raspbian. On the Pi, run:
zcat /proc/config.gz > /tmp/.config
Copy .config file to linux directory:
scp pi@rpi-cam:/tmp/.config ./.config
Restore the kernel config, then configure it:
make oldconfig
make menuconfig
Enable rpi_mbed under:
Device Drivers
> Sound card support
> Advanced Linux Sound Architecture
> ALSA for SoC audio support
> SoC Audio support for the Broadcom BCM2708 I2S module
Enable PCA9635 LED driver:
Device Drivers
> LED support
> LED support for PCA9635 I2C chip
Compile kernel
make -j4
Install kernel modules
make modules_install
Create kernel.img from zImage (for Pi Model A & B)
cd ../tools/mkimage
./imagetool-uncompressed.py ${KERNEL_SRC}/arch/arm/boot/zImage
cd ../..
Create kernel7.img from zImage (for Pi Model A+, B+, 2 B)
cd ../tools/mkimage
./mkknlimg ${KERNEL_SRC}/arch/arm/boot/zImage kern
