Go Down

Topic: RFID Serial Problem (Read 320 times) previous topic - next topic

JacobNes

Hey, I have made a simple program for reading bytes from my RFID Module.
However I have a problem with the Serial Monitor. I get values from the RFID Reader but it seems to occupy the serial traffic.
When i try to write something to the serial monitor it does not appear, tho when scanning tags i get prints.

The RFID Module i am using is: RDM630
And I am using Ardunio Uno

My program is:
Quote

char tegn;

void setup()
{

Serial.begin(9600);

}

void loop()
{
  if (Serial.available() > 0)
                            {
                           tegn = Serial.read();

                           Serial.print(tegn);
                             }

}

If anyone could help me or explain this i would greatly appreciate it.
Jacob

PaulS

Is your RFID connected to pins 0 and 1, which are the hardware serial port pins, that the Serial instance uses to talk to the PC?

You seem to be trying to read from the RFID and print to the PC using the same serial port. As you've discovered, that doesn't work.

SoftwareSerial will allow you to read from the RFID on other pins, leaving the hardware serial port free for debugging.

JacobNes

Hey, thanks so much for the help. I have updated my program to use this library, but I have still have some difficutlies with the printing.
Whenever i print it comes out like this:
Code: [Select]
5000893AF31
05000893AF
3105000893
AF31050008
93AF310500
0893AF3105
000893AF310
5000893AF31
05000893AF

As you can see the code is cut off, the code its supposed to print is: 5000893AF310
My updated code is:
Code: [Select]
#include <SoftwareSerial.h>
#define rxPin 2
#define txPin 3


SoftwareSerial mySerial =  SoftwareSerial(rxPin, txPin);
String kort = "";
char tegn;
int teller2 = 0;

void setup()
{

mySerial.begin(9600);
Serial.begin(9600);



}

void loop()
{
if (teller2 >= 12)
{
  Serial.println(kort);
  teller2=0;
  kort="";
}
if (mySerial.available() > 0 && teller2<12)
                            {
                           tegn = mySerial.read();
                           kort=kort+tegn;
                           teller2++;
                           

                             }


}

How can I make it print like it should?
I know that the RFID reads a start bit and a stop bit which it seems to print as a space.
Any help on this would be appreciated.
Jacob

PaulS

You know how many bytes there are supposed to be in a valid tag. Why are you using dynamic memory allocation in the form of a String? Stop that.

Use a static array of the proper size, and an index to define where the store the next byte.

You need to actually pay attention to the values received. There is a byte that indicates the start of a tag, and one that indicates the end of a tag. They are the characters that print funny.

When the proper byte indicating the start of the tag arrives, set the index to 0 and put a NULL in the 0th position of the array.

Then, each time another character arrives, see if it is the end marker. If not, add it to the array at the index position, increment the index, and store another NULL at the index position. If it is, set a flag that indicates that the array contains a full tag.

Only print the full tag when that flag is set.

Go Up