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