Pages: 1 [2] 3 4 ... 7   Go Down
Author Topic: RFID Video Daemon  (Read 4993 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10449
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

the "play" button in processing will compile AND run your code, so no need to export while tesing.
java file has to be manually compiled (pain for noob!)
jar file are easier: java -jar filename.jar :-)
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

At the moment I am coming up with a null pointer error referring to the video, do I have to declare the full directory name of the video or do I copy the video into the sketch folder?

I cannot test until the errors have stopped appearing.

Where exactly will the video play in processing? I can see the details on the bottom but dont understand how a video will be played.

Once again I will post my code

Thank you.

Quote
import processing.serial.*;
import processing.video.*;

Serial myPort;  // The serial port
Movie myMovie;

void movieEvent(Movie m) {
  m.read();
}

void setup() {
  // List all the available serial ports
  println(Serial.list());
  // I know that the first port in the serial list on my mac
  // is always my  Keyspan adaptor, so I open Serial.list()[0].
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[1], 9600);
  //Video Code:
  size(200, 200);
  myMovie = new Movie(this, "video.mpg");
  myMovie.play();
}

void draw() {
  while (myPort.available() > 0) {
    //Video Code:
    image(myMovie, 0, 0);
  }
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The previous code is running in the background of an rfid reader.

The code for the arduino rfid is on the arduino playground and has not been edited.

I want these prrograms to run together and play a video when a tag is over the rfid reader.

Do I need to associate them better and is this feasible?

Thank you
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10449
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,

At the moment I am coming up with a null pointer error referring to the video, do I have to declare the full directory name of the video or do I copy the video into the sketch folder?
yes, the video has to be put in the project folder located in processing's sketchbook folder. Or you can use absolute path
I cannot test until the errors have stopped appearing.

Where exactly will the video play in processing? I can see the details on the bottom but dont understand how a video will be played.
Movie class probably has a setSize() method, in witch you set the video's window dimension.

your code is not right:
in draw  you have to look if you have received a full command.
for example in case the command is long 4 char:
while (myPort.available() > 4) {

read the code:
String command = myPort.read()+myPort.read()+myPort.read()+myPort.read(); //read 4 char. it isn't and addiction but a string of 4 char

then load the video (in this case same name than the command) and play it
myMovie = new Movie(this, command+".mpg");
myMovie.play();

end the if
}

and now paint the frame if we already loaded a video:
if (myMovie != null){
   image(myMovie, 0, 0);
}
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you for all your replys.

The arduino code is printing a 10 digit number over the serial like this: 3600A9C9F8

I have renamed my video to 3600A9C9F8.mpg and placed it in the Processing/sketch_apr05a/ folder.

So my serial needs to read the 10 digits like this:
String command = myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read()
+myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read();

The edited code now looks like this:

Quote
import processing.serial.*;
import processing.video.*;

Serial myPort;  // The serial port
Movie myMovie;

void movieEvent(Movie m) {
  m.read();
}

void setup() {
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[1], 9600);
}

void draw() {
  while (myPort.available() > 10) {
    //Video Code:
    String command = myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read()
    +myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read();
  size(200, 200);
  myMovie = new Movie(this, command+".mpg");
  myMovie.play();
  }
 
  if (myMovie != null){
      image(myMovie, 0, 0);
  }
 
}
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am recieving an error that you cannot convert an int to a string.

Is there a toString() method to convert the data types?

I am sure that the arduino is printing the right data across the serial, i believe my daemon file is the problem.

Thanks again
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I think this should be the right code for what I need to do:

Quote
void draw() {
  while (myPort.available() > 0) {
    //Video Code:
    String command = myPort.read();
  size(200, 200);
  myMovie = new Movie(this, command+".mpg");
  myMovie.play();
  }
 
  if (myMovie != null){
      image(myMovie, 0, 0);
  }
 
}


As long as the port isn't 0 i know that i have recieved a tag code, then the whole code is stored in the command variable which is used as the video filename.

The only time the port isnt available is when the RFID is turned off (not in use).

I am still getting the String to Int error, but I want to make sure my method is right too.

Thanks.
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10449
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

no, your code  is wrong because with myPort.read() you read only a int.
the error on conversion is because Serial.read return a int (representing a byte), while we need a char, so just use instead a readChar(), and a for just to do nice code:

the wrong code:
Code:
while (myPort.available() > 10) {
    //Video Code:
    String command = myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read()
    +myPort.read()+myPort.read()+myPort.read()+myPort.read()+myPort.read();
  size(200, 200);
  myMovie = new Movie(this, command+".mpg");
  myMovie.play();
  }
shoud be
Code:
while (myPort.available() >= 10) {
  //Video Code:
  String command = "";
  for (int i=0;i<10;i++){
     command += myPort.readChar();
  }
  size(200, 200);
  myMovie = new Movie(this, command+".mpg");
  myMovie.play();
}
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you so much, I feel as though it is in the final development stages now.

I am recieving a null pointer exception, the video is in the same folder as the sketch_apr05a.pde file. Is this where it should be?

I am proud to of got this far with your help and am not willing to give up now.

Thank you
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If the number being sent from the arduino and recieved by the daemon is 3600A9C9F8, isn't that hexadecimal not int?

I cannot print the string to check if it is the right filename because serial.print won't let me print a string.

File types always get confusing.

Thank you
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

It is also a .wmv file not .mpg sorry.

Does it make any difference? I am happy to convert!

Thanks again.
Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The size of the window that the video is in is also small although I have changed   size(200, 200); to   size(400, 400);

Thank you again
Logged

0
Offline Offline
Shannon Member
****
Karma: 130
Posts: 10449
:(){:|:&};:
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I am recieving a null pointer exception, the video is in the same folder as the sketch_apr05a.pde file. Is this where it should be?
please, test with absolute path, then you can fight with relative path, but before you have to know everything is working

Quote
If the number being sent from the arduino and recieved by the daemon is 3600A9C9F8, isn't that hexadecimal not int?

I cannot print the string to check if it is the right filename because serial.print won't let me print a string.
in processing you don't write to serial or you are talking with arduino  smiley-grin
you have to do:
println(command);
and it will be printed in the black screen under the code

Quote
It is also a .wmv file not .mpg sorry.
"The video library allows Processing to display QuickTime video files"
you have to convert it to .mov
Logged

sei nuovo? non sai da dove partire? leggi qui: http://playground.arduino.cc/Italiano/Newbie

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Thank you that makes sense now.

I cannot use the full path for some reason, when i put "C:\Documents\Sketch\" +command+ ".mov"; it comments and tells me that it is an incorrect string, however, I printed out the command variable and it came back as: ø???ø? which is nothing like the output from the arduino. (3600A9C9F8)

The code inside the arduino is the example code from: http://www.arduino.cc/playground/Learning/PRFID

This is the variable 'code' that is used by the arduino:
char code[10];     //character array of 10
val = Serial.read();   //reads value from tag
code[bytesread] = val;  //stores each value in the array
Serial.println(code);   //prints the array

This is what the daemon needs to work with. Im not sure where the data is being read wrong. Maybe characters to string doesnt work?

The error message is a null pointer exception, however if the data can be read correctly I dont think it will have this problem any longer.

Could this be a possibility?

char command[10];
  for (int i=0;i<10;i++){
     command[ i ] += myPort.readChar();
  }
« Last Edit: April 06, 2011, 10:10:43 pm by 4kingrich » Logged

Offline Offline
Jr. Member
**
Karma: 0
Posts: 62
2b/!2b
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I need help finding the error please.

Arduino Code
Quote
int  val = 0;
char code[10];
int bytesread = 0;

void setup() {

Serial.begin(2400); // RFID reader SOUT pin connected to Serial RX pin at 2400bps
pinMode(2,OUTPUT);   // Set digital pin 2 as OUTPUT to connect it to the RFID /ENABLE pin
digitalWrite(2, LOW);                  // Activate the RFID reader
}  


 void loop() {

  if(Serial.available() > 0) {          // if data available from reader
    if((val = Serial.read()) == 10) {   // check for header
      bytesread = 0;
      while(bytesread<10) {              // read 10 digit code
        if( Serial.available() > 0) {
          val = Serial.read();
          if((val == 10)||(val == 13)) { // if header or stop bytes before the 10 digit reading
            break;                       // stop reading
          }
          code[bytesread] = val;         // add the digit          
          bytesread++;                   // ready to read next digit  
        }
      }
      if(bytesread == 10) {              // if 10 digit read is complete
        Serial.print("TAG code is: ");   // possibly a good TAG
        Serial.println(code);            // print the TAG code
      }
      bytesread = 0;
      digitalWrite(2, HIGH);                  // deactivate the RFID reader for a moment so it will not flood
           delay(1500);                       // wait for a bit
           digitalWrite(2, LOW);                  // Activate the RFID reader
    }
  }
}

Daemon Code
Quote
import processing.serial.*;
import processing.video.*;

Serial myPort;  // The serial port
Movie myMovie;

void movieEvent(Movie m) {
  m.read();
}

void setup() {
  // Open whatever port is the one you're using.
  myPort = new Serial(this, Serial.list()[1], 9600);
 
}
void draw() {
while (myPort.available() >= 10) {
  //Video Code:
  String command = "";
  for (int i=0;i<10;i++){
     command += myPort.readChar();
  }
  println(command);
  size(400, 400);
  myMovie = new Movie(this,  command+".mov");
  myMovie.play();
}
 
  if (myMovie != null){
      image(myMovie, 0, 0);
  }
 
}

Error Message: The file "ø???ø????.mov" is missing or inaccessible, make sure the URL is valid or that the file has been added to your sketch and is readable.

Help is highly appreciated.
« Last Edit: April 06, 2011, 10:26:02 pm by 4kingrich » Logged

Pages: 1 [2] 3 4 ... 7   Go Up
Jump to: