Arduino with C++ and libVLC

Hello,

I have a Duemilanove (ATMEGA 328), a laptop (i7) with windows 7 (64 bits), and I have also some problems :slight_smile:

I have three cameras and I would like to trigger those cameras with the arduino via a C++ program.
The thing is I want to trigger those camera (in burst mode) one after the other, and display a video at the same time for each camera.

I use the library libvlc.

So first of all here is the arduino program uploaded to the board :

const int myPin1 =4;
const int myPin2 = 7;
const int myPin3 = 8;

int com ;


void setup() {
  Serial.begin(9600);           
  pinMode(myPin1, OUTPUT);
  pinMode(myPin2, OUTPUT);
  pinMode(myPin3, OUTPUT);
}
  
void loop() {
 
  if (Serial.available() == 3) {
	com = Serial.read();
     }
 
 
  /*********************/
 switch(com)
{
      case 'T':
        digitalWrite(myPin1,HIGH);
      break;
      case 'R': 
        digitalWrite(myPin1,LOW);
      break;
      case 'U':
        digitalWrite(myPin2,HIGH);
      break;
      case 'M':
        digitalWrite(myPin2,LOW);
      break;
      case 'V':
        digitalWrite(myPin3,HIGH);
      break;
      case 'N':
        digitalWrite(myPin3,LOW);
      break;      
      default:
      break;
}
   
Serial.println();
}

I found some C++ sources, and modified them a bit to fit my needs. Here is the main file :

main.cpp

#include "vlcWindow.h"
#include "SerialCom.h"

int main(int argc, char *argv[])
{
	//create the arduino port (- PORT -)
	char *myPort ="COM3";
	Serial *myArduino = new Serial(myPort);
	if(myArduino->IsConnected()){
		std::cout <<"serial connection to COM3"<<std::endl;
	}else{
		std::cout <<"arduino board not found .."<< std::endl;
	}



	//create the first vlcWindow (- VLC -)
	VlcWindow *vlcWindow1 = new VlcWindow();
	vlcWindow1->playFirst();
	//create second vlcWindow (- VLC -)
	VlcWindow *vlcWindow2 = new VlcWindow();
	vlcWindow2->playFirst();
	//create second vlcWindow (- VLC -)
	VlcWindow *vlcWindow3 = new VlcWindow();
	vlcWindow3->playFirst();

	//ask for delay
	int delay;
	std::cout<<"sleep duration in ms : "<<std::endl;
	std::cin>>delay;

	int serie=0;
	while(1)
	{
		std::cout<<"press Enter"<<std::endl;
		std::getchar();

		myArduino->WriteData("T",1);	//arduino press 1
		vlcWindow1->playComp(delay);	//play video1
		myArduino->WriteData("R",1);	//arduino release 1

		myArduino->WriteData("U",1);	//arduino press 2
		vlcWindow2->playComp(delay);	//play video2 
		myArduino->WriteData("M",1);	//arduino release 2

		myArduino->WriteData("V",1);	//arduino press 3
		vlcWindow3->playComp(delay);	//play video3 
		myArduino->WriteData("N",1);	//arduino release 3

		std::cout<<"serie : "<<serie<<std::endl;
		serie++;
	}

    return 1;
}

The files included for SerialCom.h are the c++ files we can find on the arduino website :
http://arduino.cc/playground/Interfacing/CPPWindows

And the vlcWindow.h is a file found on vlc website, that I modified a bit.
I just load a movie, and set the timeline to first frame, and the function "playComp()" reads the movie.

Ok, so here are what I have :
When I compile for only one camera, and one video, it works perfectly, the arduino receives the message and trigger the cam, synchronised with the video that is played.
When I compile for three cameras, without any video display, (with a Sleep() function instead of playVideo) I have the three cameras triggered one after the other.

BUT : when I compile for the three cameras and the three videos, then, the program will play the first two videos, and while starting the last one, the cameras will finally get triggered, one after the other.. so it is not synchronised at all with the videos..

I also noticed that sometimes it seems that the order of the camera is changed, which is very weird to me. Or it also seems that the arduino consider that the pin are still "HIGH"..

Do you have any suggestion ? What can I do ?

Thanks for your help

-Thomas

Could it be that you're waiting for three characters to become available before the Arduino does anything?

Hmm.. maybe ? I am not an expert (yet :slight_smile: ) in programming neither for Arduino..

I noticed that arduino was not receiving the values when I was sending them too fast one after the other.
So I tried to change the order, rather than having :

pin1 high ;
play video1;
pin1 low;
pin2 high;
play video2;
pin2low;
pin3high;
playvideo3;
pin3low;

I tried :

pin1 high ;
play video1;
pin2 high;
play video2;
pin3 high;
playvideo3;
pin1 low;
wait 1 second;
pin2low;
wait 1 second;
pin3low;

It didn t change the problem

I noticed that arduino was not receiving the values when I was sending them too fast one after the other.

That is very, very hard to believe.

Well, sorry, I meant that I "felt" like arduino was not receiving the value.
Actually you are right, the Rx light blinks at the right time, but the camera does nothing.

i just tried right now, here is what happen :

I press Enter, the Rx light blinks, then at the same time the video1 is displayed, after the video1 display, the Rx blinks again and second video is displayed, once the second video finishes, the Rx blinks a third time and the third video start, with also the first camera starting to burst.
Then once the camera 1 finishes, and the third videos finishes, the second camera start to burst, and then the third camera.
The Rx led blinks three times after (which correspond to messages sent to put all three pins to LOW)

So could it be a problem with the wires , del and reed relay ?

Something else I noticed :

I connect the cameras through a USB cable for each one of them.
When I unplug the usb cable and replug it for the camera 2 and 3, the second and third cameras starts again to trigger. It s like the value of their pins are still HIGH.
That s why I felt like the value were not read

That s why I felt like the value were not read

It's quite likely that they aren't.

  if (Serial.available() == 3) {
	com = Serial.read();
     }

You only do a Serial.read() if there are exactly 3 bytes available. This is why it doesn't do anything until T,R and U have been received, and won't read any more after the M has been read, as Serial.available() is then less than 3.

Thank you dxw00d !

Of course you are right, the problem was there ! I don t know why but I changed that line, thinking that it was about the com port (set to 3).. rather than the flow of data.
So now I changed it to :

if (Serial.available() >0)

It solved my problem, and explained all the problems above.
I tried it and it works perfectly.

Thank you again guys for your quick and valuable help :slight_smile:

Cheers

-Thomas

You're welcome, but AWOL did point it out in reply #1.

Hi,....

I really need ur help,....
i'm working on a project and want to interface my arduino uno with 4 cameras,.....

plz provide me info, about what kind of camera u used, how u interfaced it with ur controller....

plz provide me info, about what kind of camera u used, how u interfaced it with ur controller....

Put the phone away, and use proper English!