Arduino simultaneously running with processing

Hi I'm pretty new to this all but I am currently working on a project that is controlling a RGB LED with a RFID but at the same time I am telling processing to display a picture.

Basically I'm telling the arduino, if one card is scanned make the RGB LED light up a certain colour and in processing i'm telling the RFID to display a picture when the same card is scanned, so both event happen simultaneously.

My problem is arduino is over-riding the processing 'display picture' and the only thing that is working is the LED. Do I have to program code into the arduino code to say when the LED is a colour to also play processing. Im confused as if I upload simple RFID code to arduino the processing part works fine but since I have incorporated the RGB function suddenly the processing code is being ignored.

If anyone needs I can post the code on here, just let me know.

Any help very very much appreciated!

Yes, you need to post your code. What you are saying is "my code on the Arduino isn't making my Processing application work right. Why not?".

Well, we have no idea what code is on your Arduino (or in your Processing sketch), so we can't help you.

I'm also puzzled by this statement:

in processing i'm telling the RFID to display a picture

My RFID reader can't display a picture. Can you post a link to your RFID reader that can display a picture?

Hi Thanks for getting back to me so fast. Firstly you'll probably have to excuse the way i describe all this stuff as i've not been doing it long.

My RFID reader is reading different cards which in turn flash up images in processing, I don't think I made that clear so sorry.

Here's my arduino code controlling the RGB LED with the RFID...

char val = 0; // Value of read from Serial int i=0; int redPin = 11; int greenPin = 9; int bluePin = 10;

//Serial myPort; char tagID[13]; //the string for the tag ID

void setup() {

Serial.begin(9600); // connect to the serial port

pinMode(redPin, OUTPUT); // sets the redPin to be an output pinMode(greenPin, OUTPUT); // sets the greenPin to be an output pinMode(bluePin, OUTPUT); // sets the bluePin to be an output


void loop () {

while (Serial.available() > 0) { // tagID =;

char tagID1[13] = "1F001A7072"; char tagID2[13] = "1F001A8A83"; char tagID3[13] = "1F001ACC0F"; char tagID4[13] = "1F001A9C40"; char tagID5[13] = "1F001A830D";

char IDstring[13]; //create a string of 13 characters

//if data is available on the serial buffer if (Serial.available() > 0 ) { if ( (val = == 02 ) { // look for Start Of Text marker (i.e ASCII "02") Serial.print("[SOT] ");

// read until you get End Of Text for ( i = 0; (val = != 03 ; i++) { Serial.print(val, DEC); // Display val in Hexadecimal Serial.print(" "); IDstring = val; * }* * IDstring[10] = 0x00;* * Serial.println("[EOT]");* * Serial.println();* * Serial.print(" IDString = ");* *} *

  • if(IDstring[7]==tagID1[7] && IDstring[8]== tagID1[8] && IDstring[9]==tagID1[9]) // if it's this specific rfid card*
  • { Serial.print("hello");*
  • color(0, 0, 255);*
  • delay(1000);} //turn rgb to blue*

  • else if(IDstring[7]==tagID2[7] && IDstring[8]== tagID2[8] && IDstring[9]==tagID2[9]) // if it's this specific rfid card*

  • { Serial.print("hello");*

  • color(255, 0, 0);*

  • delay(1000);} //turn rgb to red*

  • else if(IDstring[7]==tagID3[7] && IDstring[8]== tagID3[8] && IDstring[9]==tagID3[9]) // if it's this specific rfid card*

  • { Serial.print("hello");*

  • color(255,180,0);*

  • delay(1000);} //turn rgb to yellow*

  • else if(IDstring[7]==tagID4[7] && IDstring[8]== tagID4[8] && IDstring[9]==tagID4[9]) // if it's this specific rfid card*

  • { Serial.print("hello");*

  • color(0,255, 0);*

  • delay(1000);} //turn rgb to green*

  • else if(IDstring[7]==tagID5[7] && IDstring[8]== tagID5[8] && IDstring[9]==tagID5[9]) // if it's this specific rfid card*

  • { Serial.print("hello");*

  • color(128,0,255);*

  • delay(1000);} //turn rgb to purple*

  • }* }//end of loop } void color (unsigned char red, unsigned char green, unsigned char blue) // the color generating function *{ *

  • analogWrite(redPin, 255-red); *

  • analogWrite(bluePin, 255-blue);*

  • analogWrite(greenPin, 255-green);* }

---------------------------------------------------------------------------- Here's my processing sketch, that is displaying as image when the same RFID is scanned... import processing.serial.*; PImage visionblue; PImage visiongreen; PImage visionpurple; PImage visionyellow; PImage visionred; Serial myPort; String tagID = ""; //the string for the tag ID String txt =""; void setup() {

  • size (600,600); //create a display window*

  • println (Serial.list()); //prints list of serial onto console*

  • //write here the name of your serial port*

  • String portname = "COM3"; //MacOS X uses a different format such as "/dev/cu.USA28X21P1.1"*

  • //create new instance of a serial port with specified parameters.*

  • myPort = new Serial (this, portname, 9600);*

  • //create font for writing text*

  • PFont myFont = createFont (PFont.list () [10], 36);*

  • textFont (myFont);* }//end setup void draw(){

  • //clear Screen*

  • background(0);*

  • //delay screen refresh 2 second*

  • delay(2000);*

  • // read bytes from serial and print it out as a string of text*

  • while (myPort.available() > 0) {*

  • tagID = myPort.readString(); *

  • String tagID1 = "1F001A7072";*

  • String tagID2 = "1F001A8A83";*

  • String tagID3 = "1F001ACC0F";*

  • String tagID4 = "1F001A9C40";*

  • String tagID5 = "1F001A830D";*

  • if (tagID.equals(tagID1) == true) {*

  • background(2);*

  • visionblue = loadImage("20.jpg");*

  • image(visionblue, 0, 0); *

  • }*

  • //text("Vision Blue", 200, 100);//draw text on a specific position in display window*

  • //end while* else if (tagID.equals(tagID2) == true) {

  • background(2);*

  • visiongreen = loadImage("21.jpg");*

  • image(visiongreen, 0, 0); *

  • } *

  • //text("Vision Green", 200, 100);//draw text on a specific position in display window*

  • //end while* else if (tagID.equals(tagID3) == true) {

  • background(2);*

  • visionpurple = loadImage("22.jpg");*

  • image(visionpurple, 0, 0);*

  • }*

  • //text("Vision Purple", 200, 100);//draw text on a specific position in display window*

  • //end while* else if (tagID.equals(tagID4) == true) {

  • background(2);*

  • visionyellow = loadImage("23.jpg");*

  • image(visionyellow, 0, 0);*

  • }*

  • //text("Vision Yellow", 200, 100);//draw text on a specific position in display window*

  • //end while*

else if (tagID.equals(tagID5) == true) { * background(2);*

  • visionred = loadImage("24.jpg");*
  • image(visionred, 0, 0);*
  • }*
  • //text("Vision Red", 200, 100);//draw text on a specific position in display window*
  • //end while* } } ------------------------------------------------------------------------ Also I know the code may be messy in places but independently of each other the 2 things work but I want it to do the led and flash up the pic at the same time from just 1 swipe of a card. Thanks again, really really appreciate the help.

The RFID reader is attached to what? The Arduino, I presume.

So, the Arduino is reading an RFID tag, and writing some stuff to the serial port.

If the 1F001ACC0F tag is read, the Arduino will write to the serial port: "[SOT] 1F001ACC0F [EOT]

IDString = hello"

The processing application is reading this data from the serial port. It reads strings that are terminated by carriage returns or end of data, so the first one it sees is "[SOT] 1F001ACC0F [EOT]". That does not match any expected value, so nothing happens.

Then, it sees "", which also doesn't match anything.

Finally, it sees "IDString = hello", which also doesn't match anything.

Somewhere in the Arduino sketch, you need to actually write the string that the Processing sketch is expecting to read, or in the Processing sketch, you need to expect what the Arduino actually wrote.

Also, look at where you are declaring variables in both sketches. The String tadIDx statements and the char tafIDx statements occur inside a while loop inside a function called in an infinite loop.

The values never change, so the statements should be moved outside of the draw and loop functions.


A lot of what you want is in this project:-

it is forum my favorite site to me.