how to capture an image when an external trigger arised

Discussion related to "under the hood" OpenMV topics.
Thiyagarajan
Posts: 5
Joined: Sat May 11, 2019 3:02 am

how to capture an image when an external trigger arised

Postby Thiyagarajan » Sat May 11, 2019 5:21 am

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.
Last edited by Thiyagarajan on Tue May 14, 2019 1:07 am, edited 1 time in total.
User avatar
iabdalkader
Posts: 834
Joined: Sun May 24, 2015 3:53 pm

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

Postby iabdalkader » Sat May 11, 2019 9:07 am

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
Thiyagarajan
Posts: 5
Joined: Sat May 11, 2019 3:02 am

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

Postby Thiyagarajan » Tue May 14, 2019 1:02 am

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.
User avatar
iabdalkader
Posts: 834
Joined: Sun May 24, 2015 3:53 pm

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

Postby iabdalkader » Tue May 14, 2019 5:11 am

I need to see your schematics and a picture of the setup.
Thiyagarajan
Posts: 5
Joined: Sat May 11, 2019 3:02 am

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

Postby Thiyagarajan » Thu May 16, 2019 2:49 am

Actually I gave +5V to pin Vin, -5V to gnd and then i gave +5V interrupt to pin p7.
User avatar
kwagyeman
Posts: 3045
Joined: Sun May 24, 2015 2:10 pm

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

Postby kwagyeman » 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.
Nyamekye,
User avatar
iabdalkader
Posts: 834
Joined: Sun May 24, 2015 3:53 pm

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

Postby iabdalkader » Thu May 16, 2019 2:08 pm

So is this issue fixed or not ?
Thiyagarajan
Posts: 5
Joined: Sat May 11, 2019 3:02 am

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

Postby Thiyagarajan » Thu May 23, 2019 2:23 am

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.
Thiyagarajan
Posts: 5
Joined: Sat May 11, 2019 3:02 am

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

Postby Thiyagarajan » Thu May 23, 2019 2:24 am

iabdalkader wrote:
Thu May 16, 2019 2:08 pm
So is this issue fixed or not ?
Not, yet fixed abdal.
User avatar
kwagyeman
Posts: 3045
Joined: Sun May 24, 2015 2:10 pm

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

Postby kwagyeman » Thu May 23, 2019 2:32 am

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?
Nyamekye,
openmvdev
Posts: 4
Joined: Tue Jun 04, 2019 7:05 pm

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

Postby openmvdev » Tue Jun 04, 2019 7:06 pm

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
Last edited by openmvdev on Tue Jun 04, 2019 11:05 pm, edited 1 time in total.
User avatar
kwagyeman
Posts: 3045
Joined: Sun May 24, 2015 2:10 pm

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

Postby kwagyeman » Tue Jun 04, 2019 7:55 pm

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
Nyamekye,
openmvdev
Posts: 4
Joined: Tue Jun 04, 2019 7:05 pm

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

Postby openmvdev » Tue Jun 04, 2019 11:08 pm

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.

Return to “Technical Discussion”

Who is online

Users browsing this forum: Bing [Bot] and 8 guests