Synchronising 2 cameras

We have a high speed camera recording at 500fps and a slower camera recording at 30fps. The high speed camera only records for certain periods during a 3 min trial whereas the 30fps camera records for the whole 3 minutes. To know when the high speed camera is recording in reference to the 30fps camera we wanted the 30fps camera to send a signal to an LED, visible by the high speed camera. The signal would represent the frame number from the 30fps camera as 2 bytes - for example for frame number 22, the LED would light up as 1011000000000000 in the allocated 16 time bins. This way whenever the high speed camera starts recording we would always know what 30fps camera frame we're at. I've written the code below where counter_i is the frame number. The code works for slower timescales (e.g. if the light is on for 0.5s), however that would be too slow if we're sending frame capture signals at 30Hz. I've tried it with 2ms but it seems like it's not performing the computations fast enough as when we stop sending the '4' (frame capture signal for the 30fps camera), the LED still keeps going on and off for a few seconds. If anyone can shed some light on what might be a better way of solving this problem it would be greatly appreciated. Also, I am a complete newbie in Arduino and C++ so this could just be complete nonsense.

char trig = 0;

int LED1_PIN = 9;
int LED3_PIN = 1;
int counter_i = 10;

void setup() {
  // put your setup code here, to run once:

void loop() {
  // put your main code here, to run repeatedly:

  if (Serial.available() > 0){
    trig =;
    if (trig == '4'){
      int remainder = counter_i;     
      for (int i = 0; i<=15; i++){    
        int bit_i = remainder % 2;
        remainder = remainder / 2;
          if (bit_i == 1){
          digitalWriteFast(LED_BUILTIN, HIGH);   // turn the LED on (HIGH is the voltage level)
          digitalWrite(LED_BUILTIN, LOW);
          delayMicroseconds(2000);                      // wait for a second

It sounds like you're sending multiple '4's, rather than anything to do with computation times.

Looks pretty complete to me

Oops, it is a complete sketch. Except for documentation or comments. One of them is clearly wrong:

          delayMicroseconds(2000);                      // wait for a second

Yes I am. Every frame capture signal for the 30Hz camera should send a '4' which should also trigger the display of the frame number on the LED.

So, every 33ms you send a '4' (which itself takes > 1ms), and then spend at least 32 ms blinking a LED?

At the moment yes.

You should draw a timing diagram.

You have 33.33 milliseconds (one frame) to send 32 milliseconds worth of data?

You can reduce the frame counter to 14 bits and still get a unique frame number every frame for over 4.5 minutes.

1 Like

My approach would be to put a time stamp display in the field of view of both cameras.

A direct drive 7 segment display could easily be updated every millisecond.

Yes, that's what I was thinking of as well.

This could also work in our setup but we are slightly restricted on the field of view of the high speed camera - that's why only using a single LED which won't take up as much space is beneficial. I might still order such a display and trial it. Thanks.

I think I would use a small display - to show the frame number , much easier .

... but it can't be multiplexed in any way, it's why "direct drive" was mentioned in reply #11

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.