Monday, June 26, 2017

multiple raspberry pi cameras using ivport

I wanted to use more than one Raspberry Pi camera, so I used an IVPort multiplexer. Then I needed more than four cameras, so I chained several IVPort boards together.

The idea is to use one camera port on the first IVPort as the input to another IVPort. One board selects the next board, and that board selects the final camera. Only one camera is connected to the Raspberry Pi camera interface at a time.

Both boards need power, and the correct A, B, C and D solder bridges have to be set on each side of the boards according to the IVPort version.

My test setup used three boards and six cameras. The Python program below assigns separate enable and selection GPIO pins to every board, then selects the complete path to each camera.

IVPort repository:

https://github.com/ivmech/ivport

Photos, wiring and original Python example below.

Python example

import time

import RPi.GPIO as gpio


gpio.setwarnings(False)
gpio.setmode(gpio.BOARD)

# Enable and selection pins for the three IVPort boards.
boards = [
    (7, 26, 33),
    (37, 38, 40),
    (35, 32, 36),
]

for enable, select_a, select_b in boards:
    gpio.setup(enable, gpio.OUT)
    gpio.setup(select_a, gpio.OUT)
    gpio.setup(select_b, gpio.OUT)


def select(board_number, enable, select_a, select_b):
    pins = boards[board_number]
    gpio.output(pins[0], enable)
    gpio.output(pins[1], select_a)
    gpio.output(pins[2], select_b)


def select_camera(camera):
    # The states below match my three board, six camera wiring.
    if camera == 1:
        select(0, True, True, False)
        select(1, False, False, True)
    elif camera == 2:
        select(0, True, True, False)
        select(1, True, False, True)
    elif camera == 3:
        select(0, True, True, False)
        select(1, False, True, False)
    elif camera == 4:
        select(0, True, True, False)
        select(1, True, True, False)
        select(2, False, True, False)
    elif camera == 5:
        select(0, True, True, False)
        select(1, True, True, False)
        select(2, True, True, False)
    elif camera == 6:
        select(0, True, False, True)
    else:
        raise ValueError("camera must be between 1 and 6")

    print("now camera", camera)
    time.sleep(0.2)


for camera_number in range(1, 7):
    select_camera(camera_number)
    # Open the camera and capture here before selecting the next path.

Photos and videos

multiple raspberry pi cameras with ivport, photograph 1

No comments:

Post a Comment