External triggering using Teensy 3.2

External triggering of two OpenMV H7 with Global Shutters

Requesting guidance on how to efficiently trigger two OpenMV H7 (Global Shutter) from my Teensy 3.2.

Equipment:
Teensy 3.2 (Master)
Two OpenMV H7 with Global Shutters (Slaves)

I used " interface.register_callback(color_detection) " in " Remote Control_To_Arduino - As The Remote Device ",
to sucessfully send Centroid Coordinates to my Tennsy 3.2.

I then modified the sketch to have the Teensy trigger (a number of samples times) one of the OpenMV (eventually two cameras will be triggered in syn).

Below is the python sketch, followed my Teensy sketch.

import image, network, math, rpc, sensor, struct, tf
import time, pyb
import uasyncio
from pyb import Pin
from pyb import LED
ir_led = LED(4) # IR LED
ir_led.off()
ir_led.on()
pin7 = Pin(‘P7’, Pin.IN, Pin.PULL_DOWN) #keep it low, triggering makes it HIGH
sensor.reset()
sensor.set_pixformat(sensor.GRAYSCALE)
sensor.set_framesize(sensor.VGA)
sensor.skip_frames(time = 2000)
sensor.set_auto_gain(False) # must be turned off for color tracking
sensor.set_windowing((640, 640)) # 640x480 center pixels of VGA
clock = time.clock() # Create a clock object to track the FPS.

sensor.ioctl(sensor.IOCTL_SET_TRIGGERED_MODE, False)

interface = rpc.rpc_spi_slave(cs_pin=“P3”, clk_polarity=1, clk_phase=0)

thresholds =
out_blob = None

Snapshot

def snapshot(data):
print(“snapshot”)
interface.schedule_callback(snapshot_task)
return bytes()

def snapshot_task():
print(“snapshot waiting for pin7 high”)

while pin7.value() == 0:
    # Active loop (no sleep) to keep it precise and avoid preemption
    pass

print("snapshot now")

blobs = sensor.snapshot().find_blobs([thresholds],
    pixels_threshold=500,
    area_threshold=500,
    merge=True, 
    margin=20)
if not blobs:
    print("No detection")
    return # No detections.

for b in blobs:
    out_blob = max(blobs, key = lambda b: b.density())

print(out_blob)

SPI Communication handlers

def set_threshold(data):
print(“set_threshold”)
thresholds = struct.unpack(“<bbbbbb”, data)
return bytes()

def get_coordinate(data):
print(“get_coordinate”)
if out_blob is None:
print(" === No coordinate available ===“)
return bytes()
return struct.pack(”<HH", out_blob.cx(), out_blob.cy())

Installing the SPI communication handler

interface.register_callback(snapshot)
interface.register_callback(set_threshold)
interface.register_callback(get_coordinate)

interface.loop()

**** OUTPUT OF ABOVE SKETCH: ****
snapshot
snapshot waiting for pin7 high
snapshot now
No detection
get_coordinate
=== No coordinate available ===

****** TEENSY 3.2 SKETCH (color_detection() only)*******

void color_detection() {
Serial.println(" color_detection ");
int8_t color_thresholds[6] = {30, 112, 30, 112, 30, 112};
struct { uint16_t cx, cy;} color_detection_result;

interface.call(F(“set_threshold”), color_thresholds, sizeof(color_thresholds));

digitalWrite(triggerPin, LOW);
interface.call(F(“snapshot”), NULL, 0);

// Trigger the snapshot by setting pin high
digitalWrite(triggerPin, HIGH);
delayMicroseconds( MicroSecperCount); // a delay

if (interface.call_no_args(F(“get_coordinate”), &color_detection_result, sizeof(color_detection_result))) {
xL_array[myindex] = color_detection_result.cx; // Left camera
yL_array[myindex] = color_detection_result.cy;
Serial.print(color_detection_result.cx);
Serial.print(" ");
Serial.println(color_detection_result.cy);

}
}

Thank you for your time and effort
Alex

Hi Alex, we don’t verify giant code dumbs. Please ask a specific question for a specific answer.

If you want to sync two cameras you should use a gpio pin to signal each camera to take a picture.

Dear Kwagyeman,
Thank you again for responding. I completely understand.
I found the solution to my problem:

ext = ExtInt(Pin('P7'), ExtInt.IRQ_RISING, Pin.PULL_DOWN, callback)

Everything works perfectly.

Now, I accidentally connected my OpenMV cameras to a 10+ volt power supply and the camera does not mount.

Is there a way I can change the voltage regulator or what ever was damaged?

I swiped the Global sensor and that works well.

Thank you.

Sincerely,

Alex

Yeah… That’s way above the absolute max of 6V.

Um, you can try to re-work the board. But, it’s basically dead if you do that. The voltage regulator will have definitely died.

Try supplying 3.3V directly to the 3.3V pin. The board may yet still be alive.

Kwagyeman, thank you for replying

I’ll desolder the BEA9W voltage regulator and apply a 3.3 volts across .

If I may take this opportunity to ask a few questions:

Where can I find the name or specks of the IR LED mounted on the OpenMC H7 ? I wish to purchase several to creat an array of IR LEDS.

I have noticed that running the python sketch “ ir_beacon_grayscale_tracking.py” in the Examples → OpenMV → ir_beacon_grayscale_tracking.py,
provides fast and smooth centroid coordinate detection compared to the Examples in Remote_Control’s “popular_features_control_as_the_remote_device”.

Does one need to use: int8_t color_thresholds[6] = {100, 255, 100, 255, 100, 255}; // generic_red_thresholds
struct { uint16_t cx, cy; } color_detection_result;?

Is there a way to just send the centroid coordinates to the Arduino sketch without relying on int8_t color_thresholds[6] ?

I find it difficult adjusting the int8_t color_thresholds[6] = {100, 255, 100, 255, 100, 255} for best results.

Again, thank you for your time.

Alex

Hi, you need to enter into streaming mode to have fast and smooth tracking. RPC is request and then response so it’s always going to be slow. See the JPEG streaming mode example for how to setup a stream such that the camera can just send commands without blocking.

Also, you have to use a UART for this as SPI/I2C cannot issue more than 1 packet at the time.

As for the IR LEDs on the camera. Isn’t the part on the schematic?