Arduino with processing to load images.


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.


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.


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 = {

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

void setup() {
  size(640, 480);
  showImage = false;
  // list the serial ports
  // 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:

void draw() {
  // 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:

    // 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:

  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:

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

    // 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:-