Go Down

Topic: UART communication between arduino uno, and olimex mod-rfid125 (Read 275 times) previous topic - next topic

I got a rfid reader and a arduino uno r3  talking over a uart connection.
The messeage from the rfid reader i not clean. I want the message to look like this,  0A007AA1AC 

The first time I swipe the rfid chip I get this

-0A007AA1AC

but after that, if I swipe again, the response is not clean, and I can't extract the rfid code. this is 4 swipe with the rfid chip
-0A007AA1AC>-0A00-0A007AA1AC>>00A0-0A007AA1AC>>00A0-0A007AA1AC

if I break the lines up, it look something like this.
-0A007AA1AC>
-0A00-0A007AA1AC
>>00A0-0A007AA1AC
>>00A0-0A007AA1AC

what is wrong with the communication, and how do I get a clean response.
Code: [Select]

int readline(int readch, char *buffer, int len)
{
  static int pos = 0;
  int rpos;

  if (readch > 0) {
    switch (readch) {
      case '\n': // Ignore new-lines
        break;
      case '\r': // Return on CR
        rpos = pos;
        pos = 0;  // Reset position index ready for next time
        return rpos;
      default:
        if (pos < len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  // No end of line has been found, so return -1.
  return -1;
}

void setup()
{
  Serial.begin(9600);
}

void loop()
{
  static char buffer[12];
  if (readline(Serial.read(), buffer, 12) > 0) {
    Serial.print(buffer);
  }

}

This is the rfid reader:
https://www.olimex.com/Products/Modules/RFID/MOD-RFID125-BOX/

Hackscribble

Hi kjaergaard

Try checking if Serial.available() is true (i.e. there is at least one character to be read) before calling Serial.read().

Regards

Ray
Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

Thanks Hackscribble, but it did not do any diffrence, :~
if I put some *dummytext* in the end of the loop, it outputs it like this
Quote
-0A007AA1AC*dummytext*
>-0A00*dummytext*
-0A007AA1AC*dummytext*
>>dmmy*dummytext*
-0A007AA1AC*dummytext*
>>dmmy*dummytext*
-0A007AA1AC*dummytext*
>>dmmy*dummytext*
-0A007AA1AC*dummytext*


I did put in the line break, for easier reading.
maybe it is old code not being erased, or maybe it is going to fast, so it can't write it fast enough. ??

I only what it to output the string 0A007AA1AC

Hackscribble

Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

of course  :)

Code: [Select]

int readline(int readch, char *buffer, int len)
{
  static int pos = 0;
  int rpos;

  if (readch > 0) {
    switch (readch) {
      case '\n': // Ignore new-lines
        break;
      case '\r': // Return on CR
        rpos = pos;
        pos = 0;  // Reset position index ready for next time
        return rpos;
      default:
        if (pos < len-1) {
          buffer[pos++] = readch;
          buffer[pos] = 0;
        }
    }
  }
  // No end of line has been found, so return -1.
  return -1;
}

void setup()
{
  Serial.begin(9600);
 
}

void loop()
{
  static char buffer[12];

 
while (Serial.available()){
 
  if (readline(Serial.read(), buffer, 12) > 0) {
   
     Serial.print(buffer);
    Serial.print("*dummytext*");
   
  }
}

}

Hackscribble

Looks like you are using the Uno serial port to talk to the RFID reader and to the serial monitor for debugging? 

If so, you will get interference between them.  From the user manual for the reader it has a command line interface on its serial port, and I guess it will echo back characters typed into it.  So when you display the text received from the reader, that gets sent back to it, and it sends it to the Uno again.

Maybe you should install the SoftwareSerial library and use that for talking to the reader.
Hackscribble.  Writing about making things.
arduino@hackscribble.com | www.hackscribble.com

hey Hackscribble it's working, I remove the wire, that transmit back to the rfid reader, and now my arduino debug  window only output -0A007AA1AC> over and over again :)

BIG THANKS :-)

Go Up