Hello,

I am looking for some guidance on the usage of the GPIO pin in the OAK 4 D Pro camera. I am using the Python APIs to set this pin as HIGH but I am not able to see any change in output. I am setting the BoardConfig gpio pin as 7 and I have also tried with 52 as is the one specified for older versions.

Please find the example code that I am modifying to test this functionality.

#!/usr/bin/env python3

import cv2

import depthai as dai

#Create a Board Configuration

board = dai.BoardConfig()

#Set up GPIO (Assume GPIO pin 7)

gpio_pin = 52

gpio_config = dai.BoardConfig.GPIO()

gpio_config.direction = dai.BoardConfig.GPIO.Direction.OUTPUT

gpio_config.level = dai.BoardConfig.GPIO.Level.LOW

#Assign the GPIO configuration to the board

board.gpio = dai.BoardConfig.GPIOMap()

board.gpio[gpio_pin] = gpio_config

#Apply the Board Configuration to the device

# device = dai.Pipeline()

# device.setBoardConfig(board)

# Create pipeline

with dai.Pipeline() as pipeline:

# Define source and output

cam = pipeline.create(dai.node.Camera).build()

videoQueue = cam.requestOutput((640,400)).createOutputQueue()

# Connect to device and start pipeline

pipeline.start()

while pipeline.isRunning():

    #Placeholder for GPIO control

    condition_met = True

    if condition_met:

        #set GPIO pin to high

        gpio_config.level = dai.BoardConfig.GPIO.Level.HIGH

        board.gpio[gpio_pin] = gpio_config

        pipeline.setBoardConfig(board)

        print(f"GPIO {gpio_pin} set to HIGH")

    videoIn = videoQueue.get()

    assert isinstance(videoIn, dai.ImgFrame)

    cv2.imshow("video", videoIn.getCvFrame())

    if cv2.waitKey(1) == ord("q"):

        break
  • jakaskerl replied to this.
  • rsantan
    GPIO 26 & 27 can be toggleable.

    #!/usr/bin/env python3
    import cv2
    import depthai as dai
    
    # Connect to device with pipeline
    with dai.Pipeline() as pipeline:
        # Define a source - color camera
        cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
    
        # Script node
        script = pipeline.create(dai.node.Script)
        script.setScript("""
        import time
            
        import GPIO
        MX_PIN = 26
    
        ret = GPIO.setup(MX_PIN, GPIO.OUT)
        toggleVal = True
    
        while True:
            node.warn('GPIO toggle: ' + str(toggleVal))
            toggleVal = not toggleVal
            ret = GPIO.write(MX_PIN, toggleVal)  # Toggle the GPIO
            time.sleep(5)
        """)
    
        q = cam.requestOutput((640, 400)).createOutputQueue()
        # Connect to device and start pipeline
    
        pipeline.start()
        while pipeline.isRunning():
    
            videoIn = q.get()
            assert isinstance(videoIn, dai.ImgFrame)
            cv2.imshow("video", videoIn.getCvFrame())
    
            if cv2.waitKey(1) == ord("q"):
                break

    rsantan
    GPIO 26 & 27 can be toggleable.

    #!/usr/bin/env python3
    import cv2
    import depthai as dai
    
    # Connect to device with pipeline
    with dai.Pipeline() as pipeline:
        # Define a source - color camera
        cam = pipeline.create(dai.node.Camera).build(dai.CameraBoardSocket.CAM_A)
    
        # Script node
        script = pipeline.create(dai.node.Script)
        script.setScript("""
        import time
            
        import GPIO
        MX_PIN = 26
    
        ret = GPIO.setup(MX_PIN, GPIO.OUT)
        toggleVal = True
    
        while True:
            node.warn('GPIO toggle: ' + str(toggleVal))
            toggleVal = not toggleVal
            ret = GPIO.write(MX_PIN, toggleVal)  # Toggle the GPIO
            time.sleep(5)
        """)
    
        q = cam.requestOutput((640, 400)).createOutputQueue()
        # Connect to device and start pipeline
    
        pipeline.start()
        while pipeline.isRunning():
    
            videoIn = q.get()
            assert isinstance(videoIn, dai.ImgFrame)
            cv2.imshow("video", videoIn.getCvFrame())
    
            if cv2.waitKey(1) == ord("q"):
                break

    Perfect, thank you!