Arduino with processing to load images.

Hi,

I recently got processing to load multiple images from the sketch folder, but instead of just clicking run to load the images I am looking for a way to use RFID with arduino to communicate with processing to load the images. Is there any ways of doing this?

Any tips would be great.

Thanks

Is there any ways of doing this?

Of course. The Arduino can write to the serial port. Processing can read from the serial port.

Perfect. Make the Arduino send something at the appropriate time. Make Processing read the serial port, and change the image when it is told to.

Plenty of examples delivered with Processing.

Thanks.

I have just found this code. Is this what I would be looking for ? And what code would I use for the Arduino?

import processing.serial.*;

Serial portOne;    // the first serial port
Serial portTwo;    // the second serial port

boolean showImage;  // whether or not to show the image
// the list of names
String[] tags = {
  "04157EC3CB67","04157EC1E846","04157EC22588","04157EC2A409","04157EC5DA70","04157EC60CA5",
  "04157EC1BB15","04157EC3B915","04157EC31FB3","04157EC5C369","04157EC5F55F","04157EAAE623"};

// the list of people
String[] people = {
  "Christer", "Marianne", "Martin","Bo", "Gunnar","Knut","Fan_fan","Kyrre","Silje",
  "Natasha","Gudmund","Alice"};
PImage thisImage;

void setup() {
  size(640, 480);
  showImage = false;
  // list the serial ports
  println(Serial.list());
  // open the serial ports:
  portOne = new Serial(this, Serial.list()[0], 9600);
  portTwo = new Serial(this, Serial.list()[2], 9600);
  // set both ports to buffer information until you get 0x03:
  portOne.bufferUntil(0x03);
  portTwo.bufferUntil(0x03);
}

void draw() {
  background(0);
  // if there's an image to show, show it:
  if (showImage) {
  image(thisImage, 0, 0);
  }
}

void serialEvent(Serial thisPort) {
  // read the incoming serial data:
  String inString = thisPort.readStringUntil(0x03);

  // if the string is not empty, do stuff with it:
  if (inString != null) {
    // if the string came from serial port one:
    if (thisPort == portOne) {
      print ("Data from port one: ");
    }
    // if the string came from serial port two:
    if (thisPort == portTwo) {
      print ("Data from port two: ");
    }
    // print the string:
    println(inString);

    // the tag ID is only bytes 1 through 13. Get it:
    String payload = inString.substring(1, 13);
    // match the tag against the list of tags:
    matchTag(payload);
  }
}

/*
  This method matches the RFID tag number to a tag in the tagList.  
  Then it takes the corresponding name from the people list, and 
  gets the image from the data directory.
*/
void matchTag(String thisTag) {
  // iterate over the list of all known tags:
  for (int whichTag = 0; whichTag < tags.length; whichTag++) {
    // if the tag you got matches this tag in the list:
    if (thisTag.equals(tags[whichTag])) {
      // get the name from the people list
      // that corresponds to this tag's position
      String thisName = people[whichTag];
      // print it:
      println("Here's " + thisName);
      // get the image and display it:
      getImage(thisName);
    }
  }
}


// Get random image from the folder filelist array
void getImage(String personName) {
  String filenames[];

  try{
    // open the directory:
    File directory = new File(sketchPath("data"));
    // list the files in the directory:
    filenames = directory.list();

    for(int thisFile = 0; thisFile<filenames.length; thisFile++){
      // if the file is a .jpg:
      if (filenames[thisFile].endsWith(".jpg")) {
        // get the filename without the .jpg extension:
        String thisName = filenames[thisFile].substring(0, filenames[thisFile].length() -4);
        //if the filename matches the name of the person:
        if( thisName.equals(personName)) {
          // load the image from the file:
          thisImage = loadImage("data/"+filenames[thisFile]);
          // show it:
          showImage = true;
        }
      }
    }
  }
  catch(Exception f){
    //  if there was a problem reading the directory:
    println("Image import error - missing thisFile or folder");
  }
}

That Processing code expects you to send a tag's string. So, that is what your Arduino should send.

Looks like you want to do mainly what I did in this project:-
http://www.thebox.myzen.co.uk/Hardware/Crazy_People.html