Communication with processing

Hi,
I have an Arduino Duemilanove connected to an ID12 RFID reader and an servo motor. I need to get the arduino to turn the servo when it gets a signal from processing. Then it needs to wait until it reads one of the tags before returning the servo to the original position and send a signal back to processing.

I managed to modify sample code to rotate the servo when the tags are read, so the hardware is fine. I also managed to send info to processing. However, I have not been able to get my arduino to see that I send something from processing. (using the serial write command) The RX light flashes when I try to send something from processing to arduino. Does anyone got any clue what I’m doing wrong?

This is the code I have right now, pretty messy since I have been trying to figure it out on my own by shifting things around:

#include <SoftwareServo.h>

SoftwareServo servo1;


boolean reserved = false;
int up = 60;
int down = 1;
byte token[6] = {
  0x01, 0x04, 0xFA, 0x8B, 0x53, 0x27          };
byte tag1[6] = {
  0x42, 0x00, 0x44, 0x82, 0xC5, 0x41          };
byte tag2[6] = {
  0x42, 0x00, 0x44, 0x6F, 0x94, 0xFD          };

void setup() {
  Serial.begin(9600);                                 // connect to the serial port
  servo1.setMaximumPulse(2200);
  servo1.attach(2);
  servo1.write(down);
}

void loop () {
  byte i = 0;
  byte val = 0;
  byte recieved = 0;
  byte code[6];
  int tokenCheck = 0;
  int tag1Check = 0;
  int tag2Check = 0;
  byte checksum = 0;
  byte bytesread = 0;
  byte tempbyte = 0;


  // Look for the owner
  //  while (reserved){
  if(Serial.available() > 0) {
    if((val = Serial.read()) == 2) {                  // check for header 
      bytesread = 0; 
      while (bytesread < 12) {                        // read 10 digit code + 2 digit checksum
        if( Serial.available() > 0) { 
          val = Serial.read();
          if((val == 0x0D)||(val == 0x0A)||(val == 0x03)||(val == 0x02)) { // if header or stop bytes before the 10 digit reading 
            break;                                    // stop reading
          }

          // Do Ascii/Hex conversion:
          if ((val >= '0') && (val <= '9')) {
            val = val - '0';
          } 
          else if ((val >= 'A') && (val <= 'F')) {
            val = 10 + val - 'A';
          }

          // Every two hex-digits, add byte to code:
          if (bytesread & 1 == 1) {
            // make some space for this hex-digit by
            // shifting the previous hex-digit with 4 bits to the left:
            code[bytesread >> 1] = (val | (tempbyte << 4));

            if (bytesread >> 1 != 5) {                // If we're at the checksum byte,
              checksum ^= code[bytesread >> 1];       // Calculate the checksum... (XOR)
            };
          } 
          else {
            tempbyte = val;                           // Store the first hex digit first...
          };

          bytesread++;                                // ready to read next digit
        } 
        //        } 

        // Output to Serial:

        if (bytesread == 12) {                          // if 12 digit read is complete

          // Compare with tags
          for (i=0; i<6; i++) {
            if (code[i] == token[i]) tokenCheck ++;
            if (code[i] == tag1[i]) tag1Check ++;
            if (code[i] == tag2[i]) tag2Check ++;
          }
          if (tokenCheck == 6) servo1.write(60);
          if (tag1Check == 6) {
            servo1.write(down);
            Serial.print(1, BYTE);
          }
          if (tag2Check == 6) {
            servo1.write(up);
            Serial.print(0, BYTE);
          }
        }
      }
      // Turn up the ledge when reserved

      recieved = Serial.read();
      if (recieved == 'H'){
        servo1.write(up);
        reserved = true;
      }

    }
  }

  SoftwareServo::refresh();
}

You can have the PC attached to the hardware serial port, or the RFID reader, but not both.

Processing expects to be able to talk to the hardware serial port, but you have the RFID reader connected there.

You could use a software serial port (NewSoftSerial) for the RFID reader.