Page 1 of 1

how to capture an image when an external trigger arised

Posted: Sat May 11, 2019 5:21 am
by Thiyagarajan
Hi there,
As i'm newbie to openmv, I wanna know how to capture an image when an external trigger is given via gpio pin. I wanna capture an image when a buzor is pressed and find the qrcodes in that image and share those data via uart to a pc. I'm using openmv m7. Thanks in advance.

CODE:

Code: Select all

import sensor, image, time
from pyb import *


sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)
clock = time.clock()
i=0
def callback():
    i=1
ext = ExtInt(Pin('P7'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback)

if(i==1):
   print('trigerred')
   img=sensor.snapshot()
else:
   print('no signal')
this code doesn't works actually.

Re: how to capture an image when an external trigger arised

Posted: Sat May 11, 2019 9:07 am
by iabdalkader

Code: Select all

import sensor, image, time
from pyb import Pin, ExtInt

sensor.reset()                   
sensor.set_pixformat(sensor.RGB565) 
sensor.set_framesize(sensor.QVGA)   
sensor.skip_frames(time = 2000)    
              
cap = 0

def callback (line):
    cap = 1
    
ext = ExtInt(Pin('P7'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback)

while(True):
    if (cap == 1):
        img = image.snapshot()
        cap = 0

Re: how to capture an image when an external trigger arised

Posted: Tue May 14, 2019 1:02 am
by Thiyagarajan
Hi,
Thanks for your reply, Actually this is what the code which is in the example. I already tried this code, what happens when i run this code is exactly after 2000 frames the camera stops capturing. But the external interrupt on pin 7 doesn't capture any image. I want to capture when the 5V supply interrupts the pin p7 when pressing the buzor. I hope will get a perfect solution. Thanks in advance.

Re: how to capture an image when an external trigger arised

Posted: Tue May 14, 2019 5:11 am
by iabdalkader
I need to see your schematics and a picture of the setup.

Re: how to capture an image when an external trigger arised

Posted: Thu May 16, 2019 2:49 am
by Thiyagarajan
Actually I gave +5V to pin Vin, -5V to gnd and then i gave +5V interrupt to pin p7.

Re: how to capture an image when an external trigger arised

Posted: Thu May 16, 2019 11:54 am
by kwagyeman
Um, can you also share the code or other details? I don't have an idea what's wrong still. You are putting 10V across the device power supply which is out of spec.

Re: how to capture an image when an external trigger arised

Posted: Thu May 16, 2019 2:08 pm
by iabdalkader
So is this issue fixed or not ?

Re: how to capture an image when an external trigger arised

Posted: Thu May 23, 2019 2:23 am
by Thiyagarajan
kwagyeman wrote:
Thu May 16, 2019 11:54 am
Um, can you also share the code or other details? I don't have an idea what's wrong still. You are putting 10V across the device power supply which is out of spec.
Actually, I have shared the code already i think. Is there anything wrong with my power supply.? lemme have a suggestion for external interrupt supply. I have tried connecting -5V to gnd and +5V interrupt to pin p7 also.

Re: how to capture an image when an external trigger arised

Posted: Thu May 23, 2019 2:24 am
by Thiyagarajan
iabdalkader wrote:
Thu May 16, 2019 2:08 pm
So is this issue fixed or not ?
Not, yet fixed abdal.

Re: how to capture an image when an external trigger arised

Posted: Thu May 23, 2019 2:32 am
by kwagyeman
Hi, +5v to the pin and -5v to gnd is 10V across the camera's I/O pin. That will destroy the camera. Can you post a schematic of what you are doing?

Re: how to capture an image when an external trigger arised

Posted: Tue Jun 04, 2019 7:06 pm
by openmvdev
I am having the same issue. Connected via USB to windows 10.

Locks up after about 2 seconds

my code

Code: Select all

import sensor, image, time
from pyb import Pin, ExtInt

sensor.reset()
sensor.set_pixformat(sensor.RGB565)
sensor.set_framesize(sensor.QVGA)
sensor.skip_frames(time = 2000)

cap = 0
def callback (line):
    cap = 1

ext = ExtInt(Pin('P5'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback)
ext.enable()
#uart = pyb.UART(3, 115200, timeout_char = 1000)

while(True):
    if (cap == 1):
        #img = sensor.snapshot()
        #img = img.compressed(quality=35)
        #uart.write(img)
        print("cap_found")
        cap = 0

Re: how to capture an image when an external trigger arised

Posted: Tue Jun 04, 2019 7:55 pm
by kwagyeman
Can you repost your code with code tags? Also, I notice you are not using global in your callback method. Python methods do not have scope of variables like C unless you say a variable is global before hand.

Code: Select all

def callback (line):
    cap = 1
Is not valid python code. You have to do:

Code: Select all

def callback (line):
    global cap
    cap = 1

Re: how to capture an image when an external trigger arised

Posted: Tue Jun 04, 2019 11:08 pm
by openmvdev
Thank you for the suggestion. Unfortunately it still did not work. No at big issue at this time, I decided to trigger via a serial port command.