Trigger an Arduino from a video card

Hello guys,

I have been working for a while to trigger an Arduino stopwatch from a video card with RS4222 port.
To do so, I have developed a tool (a plug) in order to get an easy access to the RS422 port of my video card (see picture).
Afterward, I have been working on sending an easy message from my video card through the RS422 port (see oscilloscope picture).

Then, I have been developing my Arduino StopWatch with 7 leds. It works in a binary code. I am going to 99 (1100100) and then starting from 0 again.

I am now trying to drive the bytes from the video card (RS422 port) to the Arduino I/O in order to trigger my stopwatch.
I've got a GND and a T+ (or T-) with 3V3 signal from the video card (RS422).
It seems to suit well the Arduino digital I/O.

The goal is to plug the T+ to the pin 2 (or 3) of the Arduino Uno, and then to plug the GND to the GND of the Arduino. Then, once the message from the video card is sent, the stopwatch could be triggered using the following code :

const byte numPins = 8; // how many leds
int state;        // used for HIGH or LOW
 // pins to connect leds
byte pins[] = {5, 6, 7, 8, 9, 10, 11, 12};
const byte interruptPin = 3; // pin which would trigger the Arduino StopWatch from the RS422 of the video card
unsigned long t0Micro = 0; // Time recording
unsigned long CurrentMicro = 0; //Time recording
const long interval = 1000; // Time step for the increment of the leds in microsecond
unsigned long error = 3 ;
//int saveTime [60];
int l =0;
int k = 0;
int data =0;
int What =0; 
int trigger =0;


void setup()
{
  Serial.begin(38400); // RS422 video card
  /* we setup all led pins as OUTPUT */
  for(int i = 0; i < numPins; i++) {
    pinMode(pins[i], OUTPUT);
     digitalWrite(pins[i], LOW);
  }
  pinMode(13,OUTPUT); // Just to check if the code will run through
  digitalWrite(13, LOW);
  pinMode(interruptPin,INPUT_PULLUP);  
  attachInterrupt(digitalPinToInterrupt(interruptPin), blink, LOW);  
}



void loop()
{
if(trigger=1)
	{
	digitalWrite(13, HIGH);
	t0Micro = micros();
	for (k = 1; k<600; k++) // 600 times 0.1 second = 1 minute running
		{
		for(int i = 0; i < numPins; i++) // All the led r turned off
			{
            		digitalWrite(pins[i], LOW);
			}
        	for (l = 1; l<101 ; l++) 
            		{     
            		CurrentMicro = micros();
            		//if (l==1 && k==0){Serial.println(CurrentMicro - t0Micro);}
            		error = CurrentMicro-t0Micro - (k-1)*100*interval-l*interval; 
            		if (CurrentMicro-t0Micro >= (k-1)*100*interval+l*interval) // if the duration between two numbers is more than 1 millisecond
                		{
                		if (l==100 && k%10==0){Serial.println(error);}//saveTime[k/10] = error; // print the error between the starting time and now
                		//Serial.print(l);
				String binNumber = String(l, BIN); // convert the number is binary
    
				/* get the length of the string */
				int binLength = binNumber.length(); 
				for(int i = 0, x = 1; i < binLength; i++, x+=2) // turn the led ON and OFF according to the binary of the current number
                        		{ 
                        		if(binNumber[i] == '0') state = LOW;
                        		if(binNumber[i] == '1') state = HIGH;
                        		digitalWrite(pins[i] + binLength - x, state);
                        		}
				}
            			else { l--;}              
			}

    		}
  
	}
 trigger=0; 
}

void blink()
{
  trigger=1;
}

However, as soon as I teletransmit the code, the Arduino stopwatch start.
I have no idea where it would come from.
Thank you in advance for any help/feedback.

David

At the beginning of your loop, you are doing an assignment

  if (trigger = 1)

which assigns the value 1 to trigger and then compares that to true/false which is always true so the code is executed. You need to use the comparison operator '=='

  if (trigger == 1)

Also, trigger needs to be declared volatile since it is used within an interrupt.

volatile int trigger = 0;

As a style note, never use lower case L as a variable, it looks just like the number 1 in the editor. Use more meaningful names.

Also, you shouldn't be doing your timing by for(), just check micros() and see how much time has elapsed. The arduino is plenty fast enough to keep within a millisecond. Note that micros() will only return values to a resolution of 4us.

It is also super slow to turn a number into a binary string to then compare it and set the LEDs. Just loop over the number and use the bitRead() function or, if you are comfortable with it, the shift '>>' and compare '&' operators.

Thanks a lot for your remarks.
I am going to try that on monday and let you know the results.