Monday, June 26, 2017

multiple raspberry pi cameras using ivport

if you want to use the pi camera module multiplexer (ivport)


everything is fine
but if you want to use multiple multiplexers then its not clear from ivmech datasheet 
how to do it
so my solution is to use one of the ivport module output ports for example cam4 and connect it with another ivport module input
thus allowing to connect more then one ivport multiplexer to the raspberry pi
the code is simple and so is the connection 
but if you need further help just send a msg and ill try to upload some code and schematics


raspberry pi - you will also need to provide power for both of the boards
and solder bridge the right pads ie. a, b, c, d, on both side of the bord

code example - for two ivports boards but might work for more

import time
import picamera
import RPi.GPIO as gp

gp.setwarnings(False)
gp.setmode(gp.BOARD)

#####################################
#                                eXX               pXX                pXX                   #
#       camera          enable-1        enable-2        selection   #
#       cam-1                  0                  1                      0                    #
#       cam-2                  0                  1                      1                    #
#       cam-3                  1                  0                      0                    #
#       cam-4                  1                  0                      1                    #
#       no-cam                1                  1                      X                    #
#       error                     0                  0                     X                    #
#                                                                                                         #
#####################################

#       set GPIO

e21 = 7        #7
p21 = 26    #26
p22 = 33    #33

#1st board
gp.setup(e21, gp.OUT)
gp.setup(p21, gp.OUT)
gp.setup(p22, gp.OUT)

e31 = 37    #37
p31 = 38    #38
p32 = 40    #40

#2nd board
gp.setup(e31, gp.OUT)
gp.setup(p31, gp.OUT)
gp.setup(p32, gp.OUT)

e41 = 35    #35
p41 = 32    #32
p42 = 36    #36

#3rd board
gp.setup(e41, gp.OUT)
gp.setup(p41, gp.OUT)
gp.setup(p42, gp.OUT)

#       init the boards

#1st board - extender board , only 1 working port (port 1)
gp.output(e21, False)
gp.output(p21, False)
gp.output(p22, True)

#2nd board - 3 cameras and pass through to 4th board
gp.output(e31, False)
gp.output(p31, False)
gp.output(p32, True)

#3rd board - 2 cameras , 2 free ports
gp.output(e41, False)
gp.output(p41, False)
gp.output(p42, True)

frames = 1    #number of pictures (frames) for each camera

focus = 0    #time for adjusting the focus of the camera lens

cam = 1        #camera numer 1-6

def cam_change():
    global cam
    gp.setmode(gp.BOARD)
    if cam == 1:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, True)
        gp.output(p22, False)

#       2nd ivport board through port 4 (1,2,3 are used for cameras)
        gp.output(e31, False)
        gp.output(p31, False)
        gp.output(p32, True)
        print("now camera 1")
        time.sleep(focus)

    elif cam == 2:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, True)
        gp.output(p22, False)

#       2nd ivport board passing through port 4 (1,2,3 are used for cameras)
        gp.output(e31, True)
        gp.output(p31, False)
        gp.output(p32, True)
        print("now camera 2")
        time.sleep(focus)

    elif cam == 3:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, True)
        gp.output(p22, False)

#       2nd ivport board passing through port 4 (1,2,3 are used for cameras)
        gp.output(e31, False)
        gp.output(p31, True)
        gp.output(p32, False)
        print("now camera 3")
        time.sleep(focus)

    elif cam == 4:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, True)
        gp.output(p22, False)

#       2nd ivport board passing through port 4 (1,2,3 are used for cameras)
        gp.output(e31, True)
        gp.output(p31, True)
        gp.output(p32, False)

#       3rd ivport board (last one) port 1,3 are used for cameras
        gp.output(e41, False)
        gp.output(p41, True)
        gp.output(p42, False)
        print("now camera 4")
        time.sleep(focus)

    elif cam == 5:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, True)
        gp.output(p22, False)

#       2nd ivport board passing through port 4 (1,2,3 are used for cameras)
        gp.output(e31, True)
        gp.output(p31, True)
        gp.output(p32, False)

#       3rd ivport board (last one) port 1,3 are used for cameras
        gp.output(e41, True)
        gp.output(p41, True)
        gp.output(p42, False)
        print("now camera 5")
        time.sleep(focus)

    elif cam == 6:
#       1st ivport board through port 3 (camera port 4)
        gp.output(e21, True)
        gp.output(p21, False)
        gp.output(p22, True)
        print("now camera 6")
        time.sleep(focus)

    cam += 1
    if cam > 6:
        print("reset count to camera 1")
        cam = 1

No comments:

Post a Comment