Pages: [1]   Go Down
Author Topic: RFID code  (Read 787 times)
0 Members and 1 Guest are viewing this topic.
0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I still fairly new to electronics and the Arduino. I just got a Parallax RFID reader module and tags kit from Radio shack, and I can't get the code to verify. I get a error for the "digitalWrite(2, LOW);" from the code below. please help I want to play with my new toys.

Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


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;
           delay(500);                       // wait for a second
    }
  }
}

// extra stuff
// digitalWrite(2, HIGH);             // deactivate RFID reader
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 731
skcor oniudrA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


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
}

void activateReader() {
 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;
           delay(500);                       // wait for a second
    }
  }
}
Logged

0
Offline Offline
God Member
*****
Karma: 0
Posts: 731
skcor oniudrA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry, that was wrong - give this a whizz

Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


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;
           delay(500);                       // wait for a second
    }
  }
}
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

OK, stupid question. on the RFID reader the pins are VCC, ENABLE, SOUT, GND


so, from the this page :
http://www.arduino.cc/playground/Learning/PRFID

it says the hook up:
Arduino RX to RFID TX
Arduino GND to RFID GND
Arduino Digital pin 2 to RFID enable
Arduino +5V to RFID Vcc pin

I take it the SOUT is the RFID TX pin ??
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I don't know what is going on. The code verifies and uploads to the board just fine. I put the tag in front of the reader and nothing happens.

here is the code i'm using:
Code:
// RFID reader for Arduino
// Wiring version by BARRAGAN <http://people.interaction-ivrea.it/h.barragan>
// Modified for Arudino by djmatic


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;
      delay(500);                       // wait for a second
    }
  }
}

Logged

Copenhagen / Denmark
Offline Offline
Edison Member
*
Karma: 6
Posts: 2360
Do it !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe i'm wrong but i think that if you are using the RX and TX (Arduino pins 0 and 1) then you can not use serial communication with the computer over the "usb" connection.

Do you know for sure that someone else have had the code you use working ?

The RX and TX pins are shared with the USB to serial interface so you are basically trying to do serial communications with two dirrerent devices at the same time over the same line, which i think is not possible.

If someone knows better let me know  :-X
Logged

0
Offline Offline
Newbie
*
Karma: 0
Posts: 9
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

The code from post #4 was right. user error, i wired it up wrong. it's hard being me :-/


thanx for the help anyways
Logged

Pages: [1]   Go Up
Jump to: