How to combine RFID and LCD

Hi there,

I'm using a Sparkfun RFID Evaluation Shield 13,56 MHz and a 2x16 LCD display. My question: I want to display the tag-id on the LCD-screen. Here's my code:

/*
RFID Eval 13.56MHz Shield example sketch v10

Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW

works with 13.56MHz MiFare 1k tags

Based on hardware v13:
D7 -> RFID RX
D8 -> RFID TX
D9 -> XBee TX
D10 -> XBee RX

Note: RFID Reset attached to D13 (aka status LED)

Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 9, 5, 1, 3, 0);
SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];

//INIT
void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Herzlich Wilkommen");
  Serial.begin(9600);
  Serial.println("Start");
  // set the data rate for the SoftwareSerial ports
  xbee.begin(9600);
  rfid.begin(19200);
  delay(10);
  halt();
 
}

//MAIN
void loop()
{
  read_serial();
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
}

void print_serial()
{
  if(flag == 1){
    //print to serial port
    lcd.setCursor(0, 1);
    lcd.print(Str1[8], HEX);
    lcd.print(Str1[7], HEX);
    lcd.print(Str1[6], HEX);
    lcd.print(Str1[5], HEX);
    //print to XBee module
    xbee.print(Str1[8], HEX);
    xbee.print(Str1[7], HEX);
    xbee.print(Str1[6], HEX);
    xbee.print(Str1[5], HEX);
    xbee.println();
    delay(100);
    //check_for_notag();
  }
}

void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}

At first it displays "Herzlich Willkommen" as it shuld. But when I read a tag it only displays unreadable shit instead of the Tag-ID.

What could be the problem here?

Thanks in advance

arduino2013

Are you sure? int not byte (or unsigned char) ?

int Str1[11];

At first I used the demo code by Sparkfun that printed the ID to the Serial Monitor. Now I only implemented the display and replaced Serial.print by lcd.print. In the original version it worked. How to fix that?

  if(flag = 1){

Why are you setting flag to 1 in an if statement?

How to fix that?

You want to fix the original version so it just prints shit? Why?

You appear to be using pin 0 for the LCD and Serial, too.

I'm not using XBee. And in addition I got it working now by disabling Serial Monitor. It now displays "Willkommen!" in the first line and the Tag-ID in the second line. But it fills the second line with ""-signs after the Tag-ID. And when I read another Tag it displays shit again.

Here's the code I'm using now:

/*
RFID Eval 13.56MHz Shield example sketch v10

Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW

works with 13.56MHz MiFare 1k tags

Based on hardware v13:
D7 -> RFID RX
D8 -> RFID TX
D9 -> XBee TX
D10 -> XBee RX

Note: RFID Reset attached to D13 (aka status LED)

Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(6, 9, 5, 1, 3, 0);
SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];

//INIT
void setup()
{
  lcd.begin(16, 2);
  lcd.setCursor(0, 0);
  lcd.print("Herzlich Wilkommen");
 // Serial.begin(9600);
 // Serial.println("Start");
  // set the data rate for the SoftwareSerial ports
  xbee.begin(9600);
  rfid.begin(19200);
  delay(10);
  halt();
 
}

//MAIN
void loop()
{
  read_serial();
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
}

void print_serial()
{
  if(flag == 1){
    //print to serial port
    lcd.setCursor(0, 1);
    lcd.print(Str1[8], HEX);
    lcd.print(Str1[7], HEX);
    lcd.print(Str1[6], HEX);
    lcd.print(Str1[5], HEX);
    //print to XBee module
    xbee.print(Str1[8], HEX);
    xbee.print(Str1[7], HEX);
    xbee.print(Str1[6], HEX);
    xbee.print(Str1[5], HEX);
    xbee.println();
    delay(100);
    //check_for_notag();
  }
}

void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}

And here's the original code by Sparkfun:

/*
RFID Eval 13.56MHz Shield example sketch v10

Aaron Weiss, aaron at sparkfun dot com
OSHW license: http://freedomdefined.org/OSHW

works with 13.56MHz MiFare 1k tags

Based on hardware v13:
D7 -> RFID RX
D8 -> RFID TX
D9 -> XBee TX
D10 -> XBee RX

Note: RFID Reset attached to D13 (aka status LED)

Note: be sure include the SoftwareSerial lib, http://arduiniana.org/libraries/newsoftserial/

Usage: Sketch prints 'Start' and waits for a tag. When a tag is in range, the shield reads the tag,
blinks the 'Found' LED and prints the serial number of the tag to the serial port
and the XBee port.
06/04/2013 - Modified for compatibility with Arudino 1.0. Seb Madgwick.

*/
#include <SoftwareSerial.h>

SoftwareSerial rfid(7, 8);
SoftwareSerial xbee(10, 9);

//Prototypes
void check_for_notag(void);
void halt(void);
void parse(void);
void print_serial(void);
void read_serial(void);
void seek(void);
void set_flag(void);

//Global var
int flag = 0;
int Str1[11];

//INIT
void setup()
{
  Serial.begin(9600);
  Serial.println("Start");

  // set the data rate for the SoftwareSerial ports
  xbee.begin(9600);
  rfid.begin(19200);
  delay(10);
  halt();
}

//MAIN
void loop()
{
  read_serial();
}

void check_for_notag()
{
  seek();
  delay(10);
  parse();
  set_flag();

  if(flag = 1){
    seek();
    delay(10);
    parse();
  }
}

void halt()
{
 //Halt tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)147);
  rfid.write((uint8_t)148);
}

void parse()
{
  while(rfid.available()){
    if(rfid.read() == 255){
      for(int i=1;i<11;i++){
        Str1[i]= rfid.read();
      }
    }
  }
}

void print_serial()
{
  if(flag == 1){
    //print to serial port
    Serial.print(Str1[8], HEX);
    Serial.print(Str1[7], HEX);
    Serial.print(Str1[6], HEX);
    Serial.print(Str1[5], HEX);
    Serial.println();
    //print to XBee module
    xbee.print(Str1[8], HEX);
    xbee.print(Str1[7], HEX);
    xbee.print(Str1[6], HEX);
    xbee.print(Str1[5], HEX);
    xbee.println();
    delay(100);
    //check_for_notag();
  }
}

void read_serial()
{
  seek();
  delay(10);
  parse();
  set_flag();
  print_serial();
  delay(100);
}

void seek()
{
  //search for RFID tag
  rfid.write((uint8_t)255);
  rfid.write((uint8_t)0);
  rfid.write((uint8_t)1);
  rfid.write((uint8_t)130);
  rfid.write((uint8_t)131);
  delay(10);
}

void set_flag()
{
  if(Str1[2] == 6){
    flag++;
  }
  if(Str1[2] == 2){
    flag = 0;
  }
}

So the only thin I modified is that I disabled Serial Monitor and changed the Serial.print to lcd.print

What can I do that the display doesn't display that shit when I read more than one tag an how can I get rid of the ""-signs?