Pages: [1]   Go Down
Author Topic: Sparkfun RFID Starter Kit Problems  (Read 1622 times)
0 Members and 1 Guest are viewing this topic.
London
Offline Offline
Newbie
*
Karma: 0
Posts: 2
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi guys,
I brought the Sparkfun RFID starter kit to play around with,
I managed to get my arduino to read the full ID into a string variable, however when i try and use that string to decided what to display on an LCD things go pear shaped.

Code:
#include <SoftwareSerial.h>
#include <LiquidCrystal.h>
LiquidCrystal lcd(12, 11, 5, 4, 3, 2);

const int SerInToArdu=7; //Defines pin data passes
    //to Arduino over from RFID reader
const int SerOutFrmArdu=3; //Not used, but
    //"fills" a parameter in the set up of
    //mySerialPort
String FullCode;

SoftwareSerial mySerialPort(SerInToArdu,SerOutFrmArdu);
//  Creates serial port for RFID reader to be attached to.
//  Using pins 0 and 1 is problematic, as they are also
//     connecting the development PC to the Arduino for
//     programming, and for the output sent to the serial
//     monitor.

void setup()
{
Serial.begin(9600);//For access to serial monitor channel
Serial.println("Please Scan Card");
lcd.begin(16, 2);
lcd.print("Please Scan Card");
mySerialPort.begin(9600);
delay(1000);
lcd.clear();
};

void loop()
{
int incomingByte=0;//create and initialize a local variable

//The "then" part of the following will only execute
//  after the RFID reader has sent something to the Arduino
if (mySerialPort.available() > 0) {

             // read the incoming byte from the serial buffer
incomingByte = mySerialPort.read();
// show what was received
//Serial.print(incomingByte, DEC);
                //Serial.print(' ');
                FullCode = FullCode + " " + incomingByte;
                if (incomingByte==3){
                  Serial.println();
                  Serial.print("The Full Code is - ");
                  Serial.print(FullCode);
                  Serial.println();
                  if (FullCode == " 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3")
                    {
                      lcd.print("Your Card Is");
                      lcd.setCursor(1,2);
                      lcd.print("67 51");
                      FullCode = "";
                    }
                 
                  if(FullCode != " 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3"); //" 2 53 49 48 48 55 66 69 65 52 50 56 50 13 10 3");
                    {
                      lcd.print("Your Card Is");
                      lcd.setCursor(1,2);
                      lcd.print("56 50");
                      FullCode = "";
                    }

                  delay(4000);
                  lcd.clear();
                  FullCode = "";
                }
         }
}

So instead of displaying that the card is "67 51" or "56 50" (last two numbers as the rest is checksum etc)
the display shows the correct text for card 56 50, but for 67 51 it shows
Quote
Your card is
56 50Your Card
Can anyone help?
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm not sure, could it be that you dont call setCursor(1,1) before you print "Your Card is"? Do the second time it just adds "Your Card is" to the end.
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
                  if (FullCode == " 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3")
                    {
                    }
                 
                  if(FullCode != " 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3"); //" 2 53 49 48 48 55 66 69 65 52 50 56 50 13 10 3");
                    {
                    }
If the full code is that ridiculous string, do something.
If the full code is not that ridiculous string, do something else.

Apparently, you've never encountered the else statement.
Logged

Belgium
Offline Offline
Jr. Member
**
Karma: 1
Posts: 63
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You check twice for "" 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3" which does not make sense.

if that card is detected, you twice print to the display.
The second time you print to the display, it continues where the cursor is.
It does exactly what it is supposed to do.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
You check twice for "" 2 53 48 48 48 56 70 65 52 66 56 67 51 13 10 3" which does not make sense.
I thought that, too, at first. But, one uses == and the other uses !=. Still useless, but not the same.
Logged

Offline Offline
Full Member
***
Karma: 0
Posts: 174
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Other idea, but I'm really not good in it: you declare the string as string, but can you use "string1=string2"? Wouldnt you have to use strcmp(string1,string2)?

Oh and that string also contains spaces (" "), which probably can't be contained by int (incomingByte). So whenever your incomingbyte should become a space, it doesnt. Or am I wrong?
« Last Edit: October 16, 2012, 07:59:55 am by GoingForGold » Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 601
Posts: 48543
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
you declare the string as string, but can you use "string1=string2"?
Where is string declared as a string?

FullCode is declared as a String, which is completely different beast. == works with Strings. strcmp() works with strings.
Logged

Pages: [1]   Go Up
Jump to: