Hi @kwagyeman !
Thank you for those suggestions! Frustratingly, I discovered that the problem was some wonky connections between the terminals and the wires. This code works properly with regards to the pin 7 trigger to start and stop recording and with pin 0 sending out a TTL for each frame grab:
import pyb
import sensor
import image
import time
import mjpeg
import machine
import os
from pyb import Pin, ExtInt
sensor.reset() # Reset and initialize the sensor.
sensor.set_pixformat(sensor.GRAYSCALE) # Set pixel format to RGB565 (or GRAYSCALE)
sensor.set_framesize(sensor.QVGA) # Set frame size to QVGA (320x240)
sensor.set_windowing((121,101,100,80)) # Set windowing
sensor.skip_frames(time=2000) # Wait for settings take effect.
# Use triggered mode for frame capture to ensure all pixels are recorded simultaneously
sensor.ioctl(sensor.IOCTL_SET_TRIGGERED_MODE, True)
led = machine.LED("LED_RED")
# Prepare the voltage output
pin0 = Pin('P0', Pin.OUT_PP)
pin0.low()
# Set external trigger
trigger = 0
def triggerline (line):
global trigger
trigger = 1
ext = ExtInt(Pin('P7'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, triggerline)
ext.enable()
# Set trigger pin
#pin7 = Pin('P7', Pin.IN, Pin.PULL_DOWN)
#print(pin7)
#print(pin7.value())
# led.on()
m = mjpeg.Mjpeg("openMVvideoFakeSubject.mjpeg") # <----UPDATE THIS FILE NAME!!!! -----
print(trigger)
clock = time.clock() # Create a clock object to track the FPS.
while(True):
#print(pin7.value())
#print(trigger)
#time.sleep(1)
if (trigger == 1):
sensor.skip_frames(time=1000) # Wait for the trigger to reset
trigger = 0
while(trigger == 0):
clock.tick()
led.on()
pin0.high()
m.write(sensor.snapshot())
# time.sleep(1) # Included to slow pulses/flashes to make them visible
pin0.low()
led.off()
time.sleep(0.003) # Included to give pin 0 voltage time to reset to 0
# time.sleep(1) # Included to slow pulses/flashes to make them visible
print(clock.fps())
break
m.close()
# led.off()
raise (Exception("Please reset the camera to see the new file."))
I had to include a brief delay after resenting the pin 0 voltage to 0 in order to give time for the voltage to change and be detected by Matlab.
Thank you again for all your help!
~Nick