laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

[Tutorial] How to plug two camera modules on a Raspberry Pi

Tue Jan 08, 2019 10:53 pm

As a preamble, some warm-ups :
  • I'm sorry for my English. I hope to be understood by every readers and if it's not the case, please, feel free to ask any question.
  • I wrote this tutorial while my project was (near) finished. So I possibly forgot some steps or some reported steps could not works, so feel free again to ask me.
  • I'm not providing any SD image file in this tutorial, since I not advice to accept any image found on the web, for such sensitive applications. The aim of this tutorial is to allow you to build (and tweak) your own.
  • Although I use Linux as my main OS at home since many years, I'm not a sysadmin expert, and absolutely not a web developer. If you have better ways of making some of this tutorial steps, please, feel free to tell me how to improve this project, I'll really appreciate
Now, let's start this tutorial.
Theoretically, it may even be possible to add more camera modules. No doubt that you'll find how after reading this tutorial.
First, let me introduce my requirements with a concrete application: a dual baby monitor.

Few months ago, I became the lucky father of my two beautiful twin daughters. I faced to the difficulty of having twins finding a good baby monitor capable of monitoring my both babies at the same time.
As an absolute nerd a Raspberry Pi enthusiast, I decided to solve this annoying issue with a Raspberry Pi and cameras. It also offers an interesting possibility : the use of a wired connection, instead of wireless link like most baby monitors.

I first considered many solutions before the crazy idea to attach two official Raspberry Pi cameras to a Raspberry Pi 3... with a Raspberry Pi zero between them !
The official camera is so well supported and documented, resources are there to achieve my project in time ! The official case which encloses the Pi Zero and the camera is so cute and suits so well with a child's room.
And, last but not least: the Raspberry Pi Zero has a magical power that regulars Pi doesn't have: the ability of running without any µSD card !
This is the heart of the current project and tutorial.

For this project, you'll have to acquire the following parts :
  • A regular Raspberry Pi (3B,3B+)
  • Two Raspberry Pi NoIR cameras
  • Two Raspberry Pi Zero (not the Zero W)
  • Official cases
  • A very good/fast SD card (the fastest you can find: Evo+, Samsung Pro or whatever, but very very fast)
  • A very good power supply (the official one)
  • A set of micro USB cables (thick enough to feed the required power)
No need to buy anything since you certainly already own every part, aren't you ? ;p

This tutorial does (almost*) not require any soldering skill, but just assembly and a lot of configuration/system skills.
(* IR illumination is mandatory for night vision and may need soldering skills. It is not covered in this tutorial. Already made parts exists, though)

Let's see the project overview's picture:
Image
Can't be simpliest, isn't it ?
(Credits : images taken from Raspberry Pi magazines and Fritzing project)

With real parts, here is what does it takes:
Image

Some explanations:
The main Raspberry Pi runs from its µSD, properly flashed as usual, with the latest Raspbian (2018-11-13 at the time of writing).
This µSD also hosts the two attached Pi Zero's images (this is why a fast and good µSD card is important).
All the magic is done by a foundation's mysterious tool : rpiboot (link at the end of the tutorial).
This tool allows a Pi Zero booting without any µSD card, pushing on it, thru the USB cable, the necessary for starting and running up.
CAUTION: you must plug the Pi Zeroes by their USB/OTG ports and not their USB power ones !
Once a Pi Zero is powered and some minimal files feeded thanks to the rpiboot utility, it's recognized as a USB to Ethernet gadget and can communicate with the hosting Pi through a usbxx interface.
The rootfs of each Pi Zero are then shared with NFS, and accessed through the emulated network usb0/1/x interfaces.
This solution keep the overall cost down, avoiding the need of a µSD card for each Pi Zero.
So you just need to add a 5$ Pi Zero for each camera you want to connect to your Pi, no more :)

But this solution needs a lot of configuration steps. We'll try to walk through every of them.

In order to start this tutorial, we can consider you have a Raspberry Pi 3/3B(+) running with a fresh Raspbian properly installed and functional.
NOTE: this tutorial is mainly inspired from the following blog : https://dev.webonomic.nl/how-to-run-or- ... an-sd-card

Step I: Prepare the Pi Zero's remote images.

The original tutorial mentioned above recommands starting from a fresh new downloaded Raspbian image, but I followed an another way: flashing a regular µSD card, running and Pi Zero from it, in order to achieve all needed configurations (camera, SSH at startup and so on), and retrieving back those SD partitions images.
A bit tricky but easiest for me, especially for the configuration (I wasn't able to figure out the SSH at startup problem), but you need a spare µSD only for this, and a way to communicate with your Pi Zero (serial cable or usb/ethernet adapter).

I-1 Configure as following your Pi Zero :

Code: Select all

$ sudo raspi-config
Go to "5 Interfacing Options" -> "P1 Camera" -> Select "Yes"
Go to "5 Interfacing Options" -> "P2 SSH" -> Select "Yes"
Go to "7 Advanced Options" -> "A3 Memory Split" -> Enter "256" -> Select "Ok"

Edit the config.txt :

Code: Select all

$ nano /boot/config.txt
Uncomment and edit the following line, in order to run the Pi Zero at 700 MHz

Code: Select all

#uncomment to overclock the arm. 700 MHz is the default.
arm_freq=700
Reducing arm frequency helps to save some power (don't forget both Pi Zeroes are powered by the main Raspberry Pi's USB ports), I tried lower values but 700 seems to be the best tradeoff.
Also add the following lines on the config.txt :

Code: Select all

dtoverlay=dwc2
initramfs initrd.img followkernel
Save the file and restart the Pi Zero. You should be able to log with ssh and verify the ARM frequency by :

Code: Select all

$ vcgencmd measure_clock arm
$ frequency(45)=700000000
Finally, you'll have to figure out an internet connection on your Pi Zero in order to install Picamera for Python packages (you need to be connected for that):

Code: Select all

$ sudo apt-get update
$ sudo apt-get install python-picamera python3-picamera
After this point, you won't have to boot up directly from your Pi zero.
Turn off your Raspberry Pi zero, remove the µSD card, and insert it on a USB or SD adapter in a regular Linux computer or even your Raspberry Pi (you'll need some disk space, though) for the next step.

I-2 Disk image tweaking
Insert the µSD on your Linux computer or Main Raspberry Pi (which IS a Linux computer indeed).
Type "dmesg" on terminal and find an output similar to this, with the device name apearing ("sda" in our case)

Code: Select all

[ 4927.859480] scsi host0: usb-storage 1-1.1.2:1.0
[ 4928.873892] scsi 0:0:0:0: Direct-Access     Generic- SD/MMC/MS PRO    1.00 PQ: 0 ANSI: 4
[ 4928.893853] sd 0:0:0:0: Attached scsi generic sg0 type 0
[ 4929.508361] sd 0:0:0:0: [sda] 30703616 512-byte logical blocks: (15.7 GB/14.6 GiB)
Type the following command to confirm both µSD's partitions :

Code: Select all

$ ls /dev/sda*
/dev/sda  /dev/sda1  /dev/sda2
The boot partition is on /dev/sda1 and the rootfs is on /dev/sda2.

Next, we'll make an image of both partitions (caution : the second dd is time and disk space hungry) :

Code: Select all

$ sudo dd if=/dev/sda1 of=boot.img
89854+0 records in
89854+0 records out
46005248 bytes (46 MB, 44 MiB) copied, 1.53241 s, 30.0 MB/s

$ sudo dd if=/dev/sda2 of=rootfs.img
30605312+0 records in
30605312+0 records out
15669919744 bytes (16 GB, 15 GiB) copied, 1511.61 s, 10.4 MB/s
As you can see, the image has the size of the whole µSD card. This is why this process is quite disk space hungry. Let's shrink this disk image to a reasonable size.

Code: Select all

$ sudo truncate --size=3G rootfs.img
After that, verify the image size :

Code: Select all

$ ls -lh rootfs.img
-rw-r--r-- 1 root root 3.0G Dec 10 19:49 rootfs.img
CAUTION: never truncate a disk image without knowing exactly how much free space is remaining on it ! Verify if needed by a "df -h" command !
I first ran the fdisk utility to reduce partition size before truncating it, but it doesn't seems to be necessary.

Finaly, duplicate those images, since we need one image for each Pi Zero.

Code: Select all

$ mv boot.img boot1.img
$ cp boot1.img boot2.img
$ mv rootfs.img rootfs1.img
$ cp rootfs1.img rootfs2.img

I-3 Prepare directories and mounting scripts
We need to have one directory for boot and another for the rootfs, for each Pi Zero :

Code: Select all

$ mkdir boot
$ mkdir boot/1-1.3
$ mkdir boot/1-1.2
$ mkdir root1
$ mkdir root2
The naming scheme for the boot directory is quite special: it relates to the physical USB port. So you'll have to connect each Pi Zero on the correct port (on Pi 3B they are the two ports next to the Ethernet port, and on 3B+ they are the two ports on the right).
Edit the following mounting script :

Code: Select all

$  nano mount.sh

Code: Select all

#!/bin/sh
/bin/mount -o loop /home/pi/boot1.img /home/pi/boot/1-1.3
/bin/mount -o loop /home/pi/boot2.img /home/pi/boot/1-1.2
/bin/mount -o loop /home/pi/rootfs1.img /home/pi/root1
/bin/mount -o loop /home/pi/rootfs2.img /home/pi/root2
Make this script executable by :

Code: Select all

$ chmod +x mount.sh
Let's test this mounting script, we'll need those images mounted for the next configuration step :

Code: Select all

$ ./mount.sh
To verify, you can type :

Code: Select all

$ df -h
And you can see those lines :

Code: Select all

/dev/loop0       44M   29M   15M  67% /home/pi/boot/1-1.3
/dev/loop1       44M   29M   15M  67% /home/pi/boot/1-1.2
/dev/loop2      3.0G  1.2G  1.7G  42% /home/pi/root1
/dev/loop3      3.0G  1.2G  1.7G  42% /home/pi/root2
It means that everything worked as expected.

I-4 Create the initramfs
On the main Pi, run:

Code: Select all

$ sudo apt install initramfs-tools
Edit modules in initramfs:

Code: Select all

$ sudo nano /etc/initramfs-tools/modules

Code: Select all

g_ether
libcomposite
u_ether
udc-core
usb_f_rndis
usb_f_ecm
Then type:

Code: Select all

$ uname -r
copy-paste the kernel version, removing the "-v7" suffix in the following command:

Code: Select all

$ sudo update-initramfs -c -k "version_returned_without_v7_suffix"
In my version, it gives :

Code: Select all

$ sudo update-initramfs -c -k "4.14.79+"
Copy the initramfs :

Code: Select all

$ sudo cp /boot/initrd.img-4.14.79+ /home/pi/boot/1-1.3/initrd.img
$ sudo cp /boot/initrd.img-4.14.79+ /home/pi/boot/1-1.2/initrd.img
I-5 Finalize

We need some extra configuration of the cmdline.txt for each Pi Zero, for network and nfs configuration:
Pi Zero 1:

Code: Select all

$ nano boot/1-1.3/cmdline.txt
Edit in one single line (VERY important) in order to have this, exactly:

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.1.254:/home/pi/root1 rw ip=192.168.1.1:192.168.1.254::255.255.255.0:::static elevator=deadline modules-load=dwc2,g_ether fsck.repair=yes rootwait
Pi Zero 2:

Code: Select all

$ nano boot/1-1.2/cmdline.txt
As above, edit in one single line in order to have this, exactly:

Code: Select all

dwc_otg.lpm_enable=0 console=serial0,115200 console=tty1 root=/dev/nfs nfsroot=192.168.2.254:/home/pi/root2 rw ip=192.168.2.1:192.168.2.254::255.255.255.0:::static elevator=deadline modules-load=dwc2,g_ether fsck.repair=yes rootwait
We also need to tweak the original mounting configuration file of each Pi Zero, to avoid mounting the boot/rootfs on the missing µSD card, and to mount the boot partition remotely, by nfs:
Pi Zero 1:

Code: Select all

$ nano /root1/etc/fstab

Code: Select all

proc            /proc           proc    defaults          0       0
192.168.1.254:/home/pi/boot/1-1.3       /boot   nfs     defaults        0       0
#PARTUUID=f38c7dd9-01  /boot           vfat    defaults          0       2
#PARTUUID=f38c7dd9-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
Pi Zero 2:

Code: Select all

$ nano /root2/etc/fstab

Code: Select all

proc            /proc           proc    defaults          0       0
192.168.2.254:/home/pi/boot/1-1.2       /boot   nfs     defaults        0       0
#PARTUUID=f38c7dd9-01  /boot           vfat    defaults          0       2
#PARTUUID=f38c7dd9-02  /               ext4    defaults,noatime  0       1
# a swapfile is not a swap partition, no line here
#   use  dphys-swapfile swap[on|off]  for that
Step II: Prepare the Main Raspberry Pi

II-1 rpiboot
Just follow the instructions on the official github:
https://github.com/raspberrypi/usbboot

Code: Select all

$ git clone --depth=1 https://github.com/raspberrypi/usbboot
$ cd usbboot
$ sudo apt-get install libusb-1.0-0-dev
$ make
Let's include the proper command in an executable script :

Code: Select all

$ nano rpiboot.sh

Code: Select all

#!/bin/sh
/home/pi/usbboot/rpiboot -d /home/pi/boot/ -o -l 

Code: Select all

$ chmod +x rpiboot.sh
II-2 Make it all run at statup with rc.local

Code: Select all

$ nano /etc/rc.local

Code: Select all

#!/bin/sh -e
#
# rc.local
#
# This script is executed at the end of each multiuser runlevel.
# Make sure that the script will "exit 0" on success or any other
# value on error.
#
# In order to enable or disable this script just change the execution
# bits.
#
# By default this script does nothing.

# Print the IP address
_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
/usr/bin/tvservice -o
/home/pi/mount.sh
/home/pi/rpiboot.sh
exit 0
Yes, I added a "tvservice -o" to draw a little less power here too.

II-3 Network configuration
In Raspbian Stretch, the network configuration file not seem to be /etc/network anymore, but /etc/dhcpcd.conf.
Add the following lines in this configuration file:

Code: Select all

$ sudo nano /etc/dhcpcd.conf

Code: Select all

interface usb0
static ip_address=192.168.1.254

interface usb1
static ip_address=192.168.2.254
This will make static separate networks for our 2 Pi Zero once they will be online (very important).

II-4 NFS
In order to allow the Pi Zeroes to access to their rootfs and boot partitions, you must install NFS and edit the appropriate configuration file:

Code: Select all

$ sudo apt install nfs-kernel-server

Code: Select all

# /etc/exports: the access control list for filesystems which may be exported
#               to NFS clients.  See exports(5).
#
# Example for NFSv2 and NFSv3:
# /srv/homes       hostname1(rw,sync,no_subtree_check) hostname2(ro,sync,no_subtree_check)
#
# Example for NFSv4:
# /srv/nfs4        gss/krb5i(rw,sync,fsid=0,crossmnt,no_subtree_check)
# /srv/nfs4/homes  gss/krb5i(rw,sync,no_subtree_check)
#
/home/pi/root1 192.168.1.1(rw,sync,fsid=0,insecure,no_subtree_check,no_root_squash)
/home/pi/root2 192.168.2.1(rw,sync,fsid=0,insecure,no_subtree_check,no_root_squash)
/home/pi/boot/1-1.3 192.168.1.1(rw,sync,insecure,no_subtree_check,no_root_squash)
/home/pi/boot/1-1.2 192.168.2.1(rw,sync,insecure,no_subtree_check,no_root_squash)
Restart the NFS service:

Code: Select all

$ sudo systemctl restart nfs-server.service
$ sudo exportfs -a


II-4 Nginx
As usual, a hosted web page will allow viewing both video streams. But we have another key requirement that nginx can cover particulary well.
As we have 2 separated networks (192.168.1.1 and 192.168.2.1) for a unique public address reachable from our local network, we have to route each stream to the end user.
I first tried to achieve this with iptables but it was a nightmare. Fortunately, Nginx offers the functionnality I need : the "proxy_pass" feature !

First, you have to install the nginx server:

Code: Select all

$ sudo apt-get install nginx
Then, edit the current default enabled site configuration file :

Code: Select all

$ sudo nano /etc/nginx/sites-enabled/default
on the "server { }" section, search the "location / {" section and add just after both Pi zeroes location, like this :

Code: Select all

location / {
                # First attempt to serve request as file, then
                # as directory, then fall back to displaying a 404.
                try_files $uri $uri/ =404;
        }

location /camera1/ {
                proxy_pass http://192.168.1.1:8000/;
        }

location /camera2/ {
                proxy_pass http://192.168.2.1:8000/;
        }

II-5 Scripts and website
Video streams from Pi Zeroes:
First, in order to provide a video stream, you have to choose your way. I found many solutions : cvlc, mjpegstreamer, raspivid and so on.
There is something weird : H264 is far more efficient, but if you want to be compatible with most web browser, you'll have to go with MJPEG format !
So the solution is to use a python script involving the excellent picamera library :
https://picamera.readthedocs.io/en/rele ... -streaming

I modified this script in order to meet my requirements (including video mode) :

Code: Select all

import io
import picamera
import logging
import socketserver
from threading import Condition
from http import server
import datetime as dt
import threading

PAGE="""\
<html>
<head>
<title>Camera MJPG Stream</title>
</head>
<body>
<img src="stream.mjpg" width="1280" height="720" />
</body>
</html>
"""

class StreamingOutput(object):
    def __init__(self):
        self.frame = None
        self.buffer = io.BytesIO()
        self.condition = Condition()

    def write(self, buf):
        if buf.startswith(b'\xff\xd8'):
            # New frame, copy the existing buffer's content and notify all
            # clients it's available
            self.buffer.truncate()
            with self.condition:
                self.frame = self.buffer.getvalue()
                self.condition.notify_all()
            self.buffer.seek(0)
        return self.buffer.write(buf)

class StreamingHandler(server.BaseHTTPRequestHandler):
    def do_GET(self):
        if self.path == '/':
            self.send_response(301)
            self.send_header('Location', '/index.html')
            self.end_headers()
        elif self.path == '/index.html':
            content = PAGE.encode('utf-8')
            self.send_response(200)
            self.send_header('Content-Type', 'text/html')
            self.send_header('Content-Length', len(content))
            self.end_headers()
            self.wfile.write(content)
        elif self.path == '/stream.mjpg':
            self.send_response(200)
            self.send_header('Age', 0)
            self.send_header('Cache-Control', 'no-cache, private')
            self.send_header('Pragma', 'no-cache')
            self.send_header('Content-Type', 'multipart/x-mixed-replace; boundary=FRAME')
            self.end_headers()
            try:
                while True:
                    with output.condition:
                        output.condition.wait()
                        frame = output.frame
                    self.wfile.write(b'--FRAME\r\n')
                    self.send_header('Content-Type', 'image/jpeg')
                    self.send_header('Content-Length', len(frame))
                    self.end_headers()
                    self.wfile.write(frame)
                    self.wfile.write(b'\r\n')
            except Exception as e:
                logging.warning(
                    'Removed streaming client %s: %s',
                    self.client_address, str(e))
        else:
            self.send_error(404)
            self.end_headers()

class StreamingServer(socketserver.ThreadingMixIn, server.HTTPServer):
    allow_reuse_address = True
    daemon_threads = True

with picamera.PiCamera(sensor_mode=5, framerate=24) as camera:
    output = StreamingOutput()
    camera.annotate_background = picamera.Color('black')
    camera.annotate_text = "CAMERA 1"
    camera.annotate_text_size = 16
    camera.start_recording(output, format='mjpeg', resize=(1280,720))
    try:
        address = ('', 8000)
        server = StreamingServer(address, StreamingHandler)
        server.serve_forever()
    finally:
        camera.stop_recording()
Copy this file, from your main Pi 3 on root1/home/pi and root2/home/pi
Modify the Pi zeroes rc.local in order to stream straight from a boot :

Code: Select all

$ nano root1/etc/rc.local

Code: Select all

_IP=$(hostname -I) || true
if [ "$_IP" ]; then
  printf "My IP address is %s\n" "$_IP"
fi
/usr/bin/tvservice -o
/usr/bin/python3 /home/pi/stream.py
exit 0
(don't forget the "tvservice -o" again...)

Repeat for the second Pi Zero :

Code: Select all

$ nano root2/etc/rc.local 
Web Site on Main Pi 3:
Here after, the web site to put on a file named "index.html" on "/var/www/html/":

Code: Select all

<html>
<head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<style>
img {
  width: 50%;
  height: auto;
}
</style>
<title>Dual Pi Camera MJPEG Monitor Streaming</title>
</head>
<body>
<a href="camera1/index.html"><img src="camera1/stream.mjpg" width="1280" height="720" alt="Camera 1" border=0 /></a><a href="camera2/index.html"><img src="camera2/stream.mjpg" width="1280" height="720" alt="Camera 2" border=0 /></a>
</body>
</html>
Obviously, this site must be improved in the future. It's mostly for testing purposes.

Step III: Miscellaneous

III-1 Remote safe shutdown
(working in progress)
It's very important to provide a safe way for shutting down properly both Pi Zero and the main Raspberry Pi. I'm currently testing solutions before publishing one.
My current solution consists of sending a remote "sudo halt" commands to both Pi Zero, before doing this on the main Pi, but I don't have a proper way for doing this now. I'll soon publish when it will be done.

III-2 IR illuminator
(not realized yet)
As said before, you can find on the market allready-made ones, but I choose to make mine.
I plan to use the spare powering micro USB port in order to plug a hand-made IR illuminator, but I didn't received my ordered missing parts yet. I want to put 2 IR 850nm LED in serial with a resistor, it should be enough (I don't want to draw too much power and the "subjects" are pretty close).

III-3 Room's temperature/humidity
(not realized yet)
Quite important for a baby's room. I plan to use a Si7021 with few centimetres of wire to keep it away from the warming Pi 3B(+).


Step IV: Test it out !

IV-1 Linking them together
I chosen a 3 meters USB cable, hoping it will be good enough to feed the required power through a such distance, and fortunately, it worked (I still have to test it with the IR illuminator).
At this time you can plug the power supply and the ethernet cable to check if everything's work, by connecting to your Raspberry Pi's IP address with you favourite browser.
CAUTION: the overall startup time is VERY LONG ! Even if the main page is quickly available, you have to wait few minutes before both streams are operational.
Connect to your main Pi by SSH and you can verify both usbx connexions (192.168.1.1 and 192.168.2.1) are created for each Pi zero.
You can also verify how much CPU/RAM the streaming takes on the main Pi and both Pi Zero. Look at the nginx line (one for each connexion), it must take about 10-20% of CPU for the first connexion and few more % for any new connexion on the main Pi. The Rpiboot utility must take up to 9% of CPU.
On Pi zero, you must only have a "python3" line for the running script, taking up to about 40-45% of the CPU. It increases to 80-90% for multiple connexions (its not intended to be streamed all over the planet in this use case ^^, but it must be improved for sure...)

IV-2 Placing the whole configuration in real conditions

The (near) final installation
Image

Close-ups to one camera and its arm
Image
Image
Image

The master Pi 3 at work
Image

SSH on the Pi 3 and one Pi Zero, showing a top's result
Image
Image

The hosted web interface at work, showing both streams
Image

After clicking on one stream to zoom
Image

And after ? Improvements and wish list
  • Movement detection, with visual warning
  • Using H264 to save network bandwidth (and/or improve quality)
  • Adding sound(could be useful ^^)
  • Adding an online configuration tool
  • Adding the possibility of switching to a wireless connection
  • Improving reliability (read-only filesystem, hot-plug, and so on...)
  • For very very skilled experts: making a more suitable tiny OS image for a fastest start-up time (maybe piCore ?)
Final word
Thanks for having read all this tutorial. As far as I know, this is my first real tutorial, written under particular conditions (very little spare time).
The main difficulty was to write all this after almost everything was done, so I certainly missed some (I hope not so) important steps.
Many many thanks to the community for the resources available all over the web. They allowed me to achieve this project on a very limited time.

References and links :
https://dev.webonomic.nl/how-to-run-or- ... an-sd-card
https://8086.support/content/23/85/en/h ... r-hat.html
https://picamera.readthedocs.io/en/rele ... -streaming
https://github.com/raspberrypi/usbboot
Last edited by laurent on Thu Jan 10, 2019 8:07 am, edited 7 times in total.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Tue Jan 08, 2019 10:58 pm

Ok, I finally used a third party image hosting service to include properly all my pictures on the original post.
Sorry but now, I can't manage to delete following posts I used to share pictures. If a moderator can help me :oops:
Last edited by laurent on Wed Jan 09, 2019 10:58 pm, edited 2 times in total.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Tue Jan 08, 2019 11:01 pm

Post to delete because all images are now on the first post...
Last edited by laurent on Wed Jan 09, 2019 10:47 pm, edited 1 time in total.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Tue Jan 08, 2019 11:18 pm

Post to delete because all images are now on the first post...
Last edited by laurent on Wed Jan 09, 2019 10:47 pm, edited 2 times in total.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Tue Jan 08, 2019 11:29 pm

Post to delete because all images are now on the first post...
Last edited by laurent on Wed Jan 09, 2019 10:47 pm, edited 1 time in total.

User avatar
HermannSW
Posts: 1758
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: [Tutorial] Two camera modules with one Raspberry Pi

Wed Jan 09, 2019 7:59 pm

Nice detailed description.

Our 3 kids are all adult now, but when they were babies I remember they moved around in bed.
You may want to turn the camera/whole case by 90 degrees in order to capture the whole bed area.
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Wed Jan 09, 2019 10:55 pm

HermannSW wrote:
Wed Jan 09, 2019 7:59 pm
Nice detailed description.

Our 3 kids are all adult now, but when they were babies I remember they moved around in bed.
You may want to turn the camera/whole case by 90 degrees in order to capture the whole bed area.
Thanks.
Fortunately, the chosen arm could be oriented as I want. Main drawbacks of this camera V2 are really the field of view (cropped on common video sizes) and the optic.
I didn't talked about previously, but I had to correct both camera focuses (with a special key) to obtain a sharp image.

You are right, though. A better orientation and a third party camera with fish-eye lens to cover the whole bed would be a real improvement for the future.

User avatar
bertlea
Posts: 301
Joined: Wed Dec 07, 2016 6:33 am
Location: Hong Kong

Re: [Tutorial] Two camera modules with one Raspberry Pi

Thu Jan 10, 2019 1:38 am

Nice detailed tutorial with pictures! However, I think your title is misleading... this clearly using three Raspberry Pi not one.

User avatar
HermannSW
Posts: 1758
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: [Tutorial] Two camera modules with one Raspberry Pi

Thu Jan 10, 2019 4:52 am

laurent wrote:
Wed Jan 09, 2019 10:55 pm
Main drawbacks of this camera V2 are really the field of view (cropped on common video sizes) ...
It's not too late, you can get v1 NoIR camera for 6$, with fisheye lense for 9$ on aliexpress.com:
https://www.aliexpress.com/wholesale?Se ... ht+fisheye
Only cropped v1 camera mode is 1920x1080:
https://picamera.readthedocs.io/en/rele ... 3/fov.html
Image
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Thu Jan 10, 2019 8:09 am

bertlea wrote:
Thu Jan 10, 2019 1:38 am
Nice detailed tutorial with pictures! However, I think your title is misleading... this clearly using three Raspberry Pi not one.
Thanks. You're right, I modified the title, not mentioning the use of three Raspberry Pi, because I don't want to reveal the solution in the title :mrgreen:

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] Two camera modules with one Raspberry Pi

Thu Jan 10, 2019 8:17 am

HermannSW wrote:
Thu Jan 10, 2019 4:52 am
laurent wrote:
Wed Jan 09, 2019 10:55 pm
Main drawbacks of this camera V2 are really the field of view (cropped on common video sizes) ...
It's not too late, you can get v1 NoIR camera for 6$, with fisheye lense for 9$ on aliexpress.com:
https://www.aliexpress.com/wholesale?Se ... ht+fisheye
Only cropped v1 camera mode is 1920x1080:
https://picamera.readthedocs.io/en/rele ... 3/fov.html
Image
I saw that. I really want to switch to a V1 camera (for the FOV and the overall light sensitivity of the V1 camera), but one of my main requirement was the ease of assembling those cameras. Sadly, official Pi Zero case are only compatible with the V2 camera.
I'm still very interested of switching to the V1, I just need to find a solution for casing the V1 with Zeroes in a beautiful case (remember it's for a baby's room). And I have so little spare time :/

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7707
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 10:22 am

For 720p there the v2 will happily provide full FOV cropped to 16:9 at 24fps (actually up to 40fps).

Code: Select all

camera.start_recording(output, format='mjpeg', resize=(1280,720))
is probably your issue as it is leaving the camera resolution at the default and then software resizing the output to 1280x720.

Code: Select all

camera.resolution = (1280, 720)
camera.start_recording(output, format='mjpeg')
or

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24, resolution=(1280,720)) as camera:
...
camera.start_recording(output, format='mjpeg')
you should get better results. The default resolution appears to be match the screen resolution.

1080P will be cropped as you can't get the pixels off the sensor fast enough for 30fps. You should be able to set sensor_mode=2 and frame rate=15 to get the full frame off the sensor, and then resize in the ISP. It may require some tweaking of buffer configuration to get it to work though.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 10:50 am

6by9 wrote:
Thu Jan 10, 2019 10:22 am
For 720p there the v2 will happily provide full FOV cropped to 16:9 at 24fps (actually up to 40fps).

Code: Select all

camera.start_recording(output, format='mjpeg', resize=(1280,720))
is probably your issue as it is leaving the camera resolution at the default and then software resizing the output to 1280x720.

Code: Select all

camera.resolution = (1280, 720)
camera.start_recording(output, format='mjpeg')
or

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24, resolution=(1280,720)) as camera:
...
camera.start_recording(output, format='mjpeg')
you should get better results. The default resolution appears to be match the screen resolution.

1080P will be cropped as you can't get the pixels off the sensor fast enough for 30fps. You should be able to set sensor_mode=2 and frame rate=15 to get the full frame off the sensor, and then resize in the ISP. It may require some tweaking of buffer configuration to get it to work though.
It seems that it's already what I do with my code:

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24) as camera:
...

Code: Select all

camera.start_recording(output, format='mjpeg', resize=(1280,720))
I don't really understand why some modes are called "full FOV" since they aren't using the full sensor area (which is impossible with a 16:9 format, since the sensor is 4:3).
The Picamera library indicates that it chose the correct mode and resize, according the required user size, but I preferred to force the mode and resize to be sure I'm using the maximum FOV I can.

If you don't want much details, V1 camera at 640*480 with 4x4 binning mode should give best sensitivity results (full FOV + bigger sensor + 4x4 binning).

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7707
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 11:08 am

laurent wrote:
Thu Jan 10, 2019 10:50 am
It seems that it's already what I do with my code:

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24) as camera:
...

Code: Select all

camera.start_recording(output, format='mjpeg', resize=(1280,720))
You are NOT using

Code: Select all

camera.resolution = (1280, 720)
camera.start_recording(output, format='mjpeg')
or

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24, resolution=(1280,720)) as camera:
...
camera.start_recording(output, format='mjpeg')
which are the two alternatives I'm suggesting.
Having resize=(1280,720) in your start_recording line inserts a software resize between the camera and video_encode components, which is not the same thing.
laurent wrote:I don't really understand why some modes are called "full FOV" since they aren't using the full sensor area (which is impossible with a 16:9 format, since the sensor is 4:3).
It's using the full FOV from the sensor, and then cropping in the ISP. What would prefer it was called that doesn't take a minor thesis to describe?
laurent wrote:The Picamera library indicates that it chose the correct mode and resize, according the required user size, but I preferred to force the mode and resize to be sure I'm using the maximum FOV I can.
And that's why the controls are there.
laurent wrote:If you don't want much details, V1 camera at 640*480 with 4x4 binning mode should give best sensitivity results (full FOV + bigger sensor + 4x4 binning).
The V1 sensor doesn't support 4x4 binning. 640x480 from the sensor is achieved with line skipping (reading only lines 1, 4, 9, 12, 17, 20, 25, etc to retain the Bayer pattern), so has no effect on the sensitivity.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 12:08 pm

6by9 wrote:
Thu Jan 10, 2019 11:08 am
You are NOT using

Code: Select all

camera.resolution = (1280, 720)
camera.start_recording(output, format='mjpeg')
or

Code: Select all

with picamera.PiCamera(sensor_mode=5, framerate=24, resolution=(1280,720)) as camera:
...
camera.start_recording(output, format='mjpeg')
which are the two alternatives I'm suggesting.
Having resize=(1280,720) in your start_recording line inserts a software resize between the camera and video_encode components, which is not the same thing.
You're right, I had read too fast the resize/resolution parameter.
The Picamera documentation says that the GPU is used to downscale from the nearest mode resolution to the required resolution parameter (https://picamera.readthedocs.io/en/rele ... mera-modes). So I too quickly supposed the GPU was also used for the resize parameter.
Anyway, I'll try your parameters as soon as I can, thanks.
6by9 wrote:
Thu Jan 10, 2019 11:08 am
laurent wrote:If you don't want much details, V1 camera at 640*480 with 4x4 binning mode should give best sensitivity results (full FOV + bigger sensor + 4x4 binning).
The V1 sensor doesn't support 4x4 binning. 640x480 from the sensor is achieved with line skipping (reading only lines 1, 4, 9, 12, 17, 20, 25, etc to retain the Bayer pattern), so has no effect on the sensitivity.
The Picamera documentation mentions a 4x4 binning on modes 6 and 7 of the V1 camera (still at https://picamera.readthedocs.io/en/rele ... nsor-modes).
Sensitivity may not be the correct word (writing in English is not that easy for me, sorry), but the goal is to obtain brighter pixels (which I suppose binning helps by merging pixels).

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7707
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 12:34 pm

laurent wrote:
Thu Jan 10, 2019 12:08 pm
6by9 wrote:
Thu Jan 10, 2019 11:08 am
laurent wrote:If you don't want much details, V1 camera at 640*480 with 4x4 binning mode should give best sensitivity results (full FOV + bigger sensor + 4x4 binning).
The V1 sensor doesn't support 4x4 binning. 640x480 from the sensor is achieved with line skipping (reading only lines 1, 4, 9, 12, 17, 20, 25, etc to retain the Bayer pattern), so has no effect on the sensitivity.
The Picamera documentation mentions a 4x4 binning on modes 6 and 7 of the V1 camera (still at https://picamera.readthedocs.io/en/rele ... nsor-modes).
Sensitivity may not be the correct word (writing in English is not that easy for me, sorry), but the goal is to obtain brighter pixels (which I suppose binning helps by merging pixels).
Whilst I will sometimes sanity check or proof read the PiCamera docs, both the library and the docs are all written by a third party and so may contain errors.
Feel free to read the Omnivision (v1 sensor manufacturer) datasheet for the OV5647 - https://cdn.sparkfun.com/datasheets/Dev ... 7_full.pdf. 2x2 binning is referenced, but not 4x4. Modes 6 & 7 for the v1 sensor both use line skipping with no binning. Modes 4 & 5 use 2x2 binning.

Binning will increase the sensitivity and signal/noise ratio, but only if done in the analog domain (v2 sensor supports 4x4 digital binning).
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 1:50 pm

6by9 wrote:
Thu Jan 10, 2019 12:34 pm
Whilst I will sometimes sanity check or proof read the PiCamera docs, both the library and the docs are all written by a third party and so may contain errors.
Feel free to read the Omnivision (v1 sensor manufacturer) datasheet for the OV5647 - https://cdn.sparkfun.com/datasheets/Dev ... 7_full.pdf. 2x2 binning is referenced, but not 4x4. Modes 6 & 7 for the v1 sensor both use line skipping with no binning. Modes 4 & 5 use 2x2 binning.

Binning will increase the sensitivity and signal/noise ratio, but only if done in the analog domain (v2 sensor supports 4x4 digital binning).
Many thanks for those informations ;)
So fortunately for me, I didn't planned to switch to 640x480 just for the mentioned 4x4 binning :lol: (but still plan to switch to a third party V1 w/ fisheye)
Anyway, the V2 sensor gives pretty good results in daylight, I really need to make an IR illuminator now.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Thu Jan 10, 2019 10:21 pm

@6by9
I've just tested out resolution parameter instead of resize and the resources required by this script are almost the same (only one Pi Zero has the modification and the other has the old version):
Image

It means that PiCamera library uses the GPU on both cases ?
Both images are completely dark at the moment of the test (still no IR light), may it has any importance on the CPU usage ?
I let the modification on one Pi Zero to test it a little more.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7707
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Fri Jan 11, 2019 8:36 am

laurent wrote:
Thu Jan 10, 2019 10:21 pm
It means that PiCamera library uses the GPU on both cases ?
Yes, all of the image manipulation is done on the GPU. Particularly on the Pi0 and A/B/A+/B+ that use the old armv6 CPUs there is almost no chance of getting decent performance on image processing.
laurent wrote:Both images are completely dark at the moment of the test (still no IR light), may it has any importance on the CPU usage ?
I hope you bought the NoIR version of the camera module, otherwise they have IR filters in them and your illuminators will do almost nothing.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Fri Jan 11, 2019 8:58 am

6by9 wrote:
Fri Jan 11, 2019 8:36 am
laurent wrote:
Thu Jan 10, 2019 10:21 pm
It means that PiCamera library uses the GPU on both cases ?
Yes, all of the image manipulation is done on the GPU. Particularly on the Pi0 and A/B/A+/B+ that use the old armv6 CPUs there is almost no chance of getting decent performance on image processing.
laurent wrote:Both images are completely dark at the moment of the test (still no IR light), may it has any importance on the CPU usage ?
I hope you bought the NoIR version of the camera module, otherwise they have IR filters in them and your illuminators will do almost nothing.
Yes, cameras are both the NoIR version, I'm just waiting parts from eBay to build little IR illuminators that I plan to plug on the power spare micro USB ports.

User avatar
HermannSW
Posts: 1758
Joined: Fri Jul 22, 2016 9:09 pm
Location: Eberbach, Germany
Contact: Website Twitter YouTube

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Fri Jan 11, 2019 5:46 pm

I understand the idea of IR lighting and capturing video during the night.
While I see no problems with that for viewing eg. house entrance, have you checked whether whole night IR light might have side effects (although not visible) to your babies?
⇨https://stamm-wilbrandt.de/en/Raspberry_camera.html

https://github.com/Hermann-SW/Raspberry_v1_camera_global_external_shutter
https://stamm-wilbrandt.de/github_repo_i420toh264
https://github.com/Hermann-SW/fork-raspiraw
https://twitter.com/HermannSW

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Fri Jan 11, 2019 11:41 pm

HermannSW wrote:
Fri Jan 11, 2019 5:46 pm
I understand the idea of IR lighting and capturing video during the night.
While I see no problems with that for viewing eg. house entrance, have you checked whether whole night IR light might have side effects (although not visible) to your babies?
Very good question. I found some answers and many debates over the Web, letting me think there is no danger in my opinion (I'm open to every opinion - feel free to give yours).
- First, baby monitors on the market all have a huge number of IR LED (more than necessary I think). Although this is not a reason to say it's safe, I can imagine that those product are a minimum tested and used, with no report of any consequence at this day (right, still not a proof. Still no report about long-term consequences ?).
- IR light are long wavelength, transporting less energy (less dangerous) than visible (and worst, UV) light.
- This is also the reason I want to made mines, with a diffuse and very limited intensity of light (no more than necessary). I just want to see at a glance if everything is alright. I want to put 2 IR LED by camera, with something to diffuse the light (no ideas of what yet).
- Last, but not least : when babies are on the bed, they are sleeping the most of the time, keeping their eyes closed and not exposed.

User avatar
rleyden
Posts: 74
Joined: Thu Jun 14, 2012 2:17 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Tue Feb 05, 2019 5:42 am

Very nice tutorial. I've gone through the steps without major problems. (Several steps seemed to require the use of "sudo'.)
I decided that I really wanted three cameras (at least), using each for a different field of view. So, I added a third camera on the master Pi 3B. This seems to run fine with only about 30% usage on each CPU.

Adding the third stream makes all of the streams seriously lag. I can wave my hand in front of a camera and see it delayed in the browser by several seconds. I don't think this will be a problem since I plan to put Pikrellcam on each systems to monitor for motion. But it is curious that this didn’t seem to a problem with just 2 cameras, either (zero + zero) or (3B + zero).

I had not previously used the Pi zero because I don't live near any stores that a will sell you one for $5 (A Pi zero on Amazon costs $26 including shipping). This seemed a poor cost-performance ratio compared with a Pi 3 B (not +) which are under $30. However, using the architecture in your tutorial, one can add, effectively, "smart USB cameras" to a main PC (not necessarily a Pi). Using clone 5MP cameras could cut the cost per "smart camera" under $10. Taking this its logical conclusion, it would be wonderful if the next Pi Zero had a Sunny connector on the board so the sensor could be mounted directly on the board.

laurent
Posts: 323
Joined: Thu Jul 26, 2012 11:24 am

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Tue Feb 05, 2019 9:43 am

rleyden wrote:
Tue Feb 05, 2019 5:42 am
Very nice tutorial. I've gone through the steps without major problems. (Several steps seemed to require the use of "sudo'.)
I decided that I really wanted three cameras (at least), using each for a different field of view. So, I added a third camera on the master Pi 3B. This seems to run fine with only about 30% usage on each CPU.
Many thanks :D
Unfortunately, I don't think to have the time to make again this tutorial from scratch to be sure every steps are OK. Very glad to see you managed to follow it with success though. Thanks for testing a third camera, too ! I planned to test it, but freeing some spare time is still a huge problem for me.
rleyden wrote:
Tue Feb 05, 2019 5:42 am
Adding the third stream makes all of the streams seriously lag. I can wave my hand in front of a camera and see it delayed in the browser by several seconds. I don't think this will be a problem since I plan to put Pikrellcam on each systems to monitor for motion. But it is curious that this didn’t seem to a problem with just 2 cameras, either (zero + zero) or (3B + zero).
MJPEG is very bandwidth-hungry, and with the only USB2 link shared between those cameras AND the ethernet port, it's a critical limitation to take care about.
I didn't tuned bitrate/quality parameters (I wondering if it's even possible with PiCamera), in order to save bandwidth.
You may also play with video definition and framerate.
I also noticed a increasing lag in time with my 2 cameras, giving several seconds of delay after 2 weeks of continuously work. The solution is to restart the whole system after some weeks :(

It's still important to find a better way of streaming (using H264 if it's possible).
Fortunately a such hackable platform like a Raspberry Pi allows to try out many solutions, but lack of time is the critical issue for that :cry:
rleyden wrote:
Tue Feb 05, 2019 5:42 am
I had not previously used the Pi zero because I don't live near any stores that a will sell you one for $5 (A Pi zero on Amazon costs $26 including shipping). This seemed a poor cost-performance ratio compared with a Pi 3 B (not +) which are under $30. However, using the architecture in your tutorial, one can add, effectively, "smart USB cameras" to a main PC (not necessarily a Pi). Using clone 5MP cameras could cut the cost per "smart camera" under $10. Taking this its logical conclusion, it would be wonderful if the next Pi Zero had a Sunny connector on the board so the sensor could be mounted directly on the board.
Sadly, that's true: buying an overpriced Pi zero ruins the main advantage of this tutorial. Maybe a A+ could do the job but the price won't be so interesting. One other huge advantage is the hackability of the platform (that you don't have with a regular webcam), but you have to balance it with the overall price.
Nice idea of the Sunny connector on the PCB (like on iMX Sabre boards) ! Hope the RPF folks will read this :mrgreen:

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 7707
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: [Tutorial] How to plug two camera modules on a Raspberry Pi

Tue Feb 05, 2019 10:28 am

laurent wrote:
Tue Feb 05, 2019 9:43 am
rleyden wrote:
Tue Feb 05, 2019 5:42 am
Adding the third stream makes all of the streams seriously lag. I can wave my hand in front of a camera and see it delayed in the browser by several seconds. I don't think this will be a problem since I plan to put Pikrellcam on each systems to monitor for motion. But it is curious that this didn’t seem to a problem with just 2 cameras, either (zero + zero) or (3B + zero).
MJPEG is very bandwidth-hungry, and with the only USB2 link shared between those cameras AND the ethernet port, it's a critical limitation to take care about.
Unless I've missed something then you're using the Pi camera module, which is not connected over USB on the Pi0 (it's CSI direct to the SoC).
The bandwidth required over USB from the Pi0 to master Pi is significantly lower as it has already been compressed. Exactly how the Pi0s are presented in gadget mode, and how efficient that is in terms of USB, may be the limiting factor.
laurent wrote:I didn't tuned bitrate/quality parameters (I wondering if it's even possible with PiCamera), in order to save bandwidth.
You may also play with video definition and framerate.
https://picamera.readthedocs.io/en/late ... _recording

Code: Select all

All encoded formats accept the following additional options:
    bitrate - The bitrate at which video will be encoded. Defaults to 17000000 (17Mbps) if not specified. The maximum value depends on
    the selected H.264 level and profile. Bitrate 0 indicates the encoder should not use bitrate control (the encoder is limited
    by the quality only).
laurent wrote:
rleyden wrote:
Tue Feb 05, 2019 5:42 am
Taking this its logical conclusion, it would be wonderful if the next Pi Zero had a Sunny connector on the board so the sensor could be mounted directly on the board.
Nice idea of the Sunny connector on the PCB (like on iMX Sabre boards) ! Hope the RPF folks will read this :mrgreen:
Very unlikely to happen. People complain enough that the current connectors are fragile, whilst the Sunny type connectors are even more so, and very prone to popping off at inopportune moments.
You've also then moved all the voltage regulators and oscilator for the camera module onto the Pi, and therefore bumped up the BOM for the Pi.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “General discussion”