RFID HEX to DEC

Hi,

I have a device:

GROOVE RFID -> http://www.seeedstudio.com/wiki/Grove_-_125KHz_RFID_Reader

I'm reading: "STX0F000C9C0E91ETX" --> STX 0F000C9C0E 91 ETX

The RFID card indicates: "000353396" (printed)

How is this relationship between DEC and HEX numbers?

Your code?

How to use this forum

sorry...

#include <SoftwareSerial.h>
 
SoftwareSerial rfid(2, 3);
unsigned char buffer[64]; // buffer array for data recieve over serial port
int count=0;     // counter for buffer array 
void setup()
{
  rfid.begin(9600);               // the rfid baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.
 
}
 
void loop()
{
  if (rfid.available())              // if date is comming from softwareserial port ==> data is comming from rfid shield
  {
    while(rfid.available())          // reading data into char array 
    {
      buffer[count++]=rfid.read();     // writing data into array
      if(count == 64)break;
  }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero
 
 
  }
  if (Serial.available())            // if data is available on hardwareserial port ==> data is comming from PC or notebook
    rfid.write(Serial.read());       // write it to the rfid shield
}
void clearBufferArray()              // function to clear buffer array
{
  for (int i=0; i<count;i++)
    { buffer[i]=NULL;}                  // clear all index of array with command NULL
}

related:
https://forum.sparkfun.com/viewtopic.php?f=14&t=25360

if(count == 64)break;

Their example shows 12 bytes. I'm not sure where 64 comes from.

I have an RFID reader here, not sure if it helps or not:

Your basic problem is here:

 if (rfid.available())              // if date is comming from softwareserial port ==> data is comming from rfid shield
  {
    while(rfid.available())          // reading data into char array 
    {
      buffer[count++]=rfid.read();     // writing data into array
      if(count == 64)break;
  }
    Serial.write(buffer,count);            // if no data transmission ends, write buffer to hardware serial port
    clearBufferArray();              // call clearBufferArray function to clear the storaged data from the array
    count = 0;                       // set counter of while loop to zero
 
 
  }

You won't necessarily get all the bytes quickly, so you will leave the loop prematurely. Read this:

My example above of RFID reader shows a better way of reading the data.

I do not see the reason of my problem be there.

The buffer is just to avoid losing data .. but any example in arduino reads the same value ... Like: "SeeedRFIDlib":

0F000C9C0E91
Decoding 0x0F00: 3840
Decoding 0x0C9C0E
Decoding 0x91: 145
Decoding 0x0F: 15
Decoding 0x00: 0
Decoding 0x0C: 12
Decoding 0x9C: 156
Decoding 0x0E: 14
readId()
0F000C9C0E91

I do not see the reason of my problem be there.

Well it is your problem.
The buffer only fills up at the data rate of the input but you empty it very quickly. So you start reading before all the data is in and finish reading too soon.

Grumpy_Mike:

I do not see the reason of my problem be there.

Well it is your problem.
The buffer only fills up at the data rate of the input but you empty it very quickly. So you start reading before all the data is in and finish reading too soon.

Do you have any example?

My example above of RFID reader shows a better way of reading the data.

I get your example and change for my example...:

#include <SoftwareSerial.h>
 
SoftwareSerial rfid(2, 3);

const unsigned int MAX_INPUT = 128;

int count=0;     // counter for buffer array 
void setup()
{
  rfid.begin(9600);               // the rfid baud rate   
  Serial.begin(9600);             // the Serial port of Arduino baud rate.
 
}

void process_data (char * data)
  {
  // for now just display it
  Serial.println("FOUND");
  Serial.println (data);
  }  // end of process_data
  
void loop()
{
static char input_line [MAX_INPUT];
static unsigned int input_pos = 0;

  if (rfid.available () > 0) 
    {
    char inByte = rfid.read ();
     
    Serial.print(inByte);
    
    switch (inByte)
      {
      case '\n':   // end of text
        input_line [input_pos] = 0;  // terminating null byte
        // terminator reached! process input_line here ...
        process_data (input_line);     
        // reset buffer for next time
        input_pos = 0;  
        break;
        
      case '\r':   // discard carriage return
        break;
  
      default:
        // keep adding if not full ... allow for terminating null byte
        if (input_pos < (MAX_INPUT - 1))
          input_line [input_pos++] = inByte;
        break;
      }
  }
}

obtain:
STX0F000C9C0E91ETX

the same :slight_smile:

Other example without buffer:

#include <SoftwareSerial.h>

SoftwareSerial rfid(2, 3);

char val = 0; // variable to store the data from the serial port

void setup() {
Serial.begin(9600); // connect to the serial port
rfid.begin(9600); // the rfid baud rate
}

void loop () {
// read the serial port
if(rfid.available() > 0) {
val = rfid.read();
Serial.write(val);
}
}

0F000C9C0E91
Decoding 0x0F00: 3840
Decoding 0x0C9C0E

You don't see that the value was split? You need new glasses.

PaulS:

0F000C9C0E91
Decoding 0x0F00: 3840
Decoding 0x0C9C0E

You don't see that the value was split? You need new glasses.

sorry ... you do not understand.

i have a plastic card (RFID) ... where has written: "0 0 0 3 5 3 3 9 6" ....

and i obtain : "000C9C0E" »» convert in decimal: " 0 0 0 8 2 6 3 8 2" ...

NOT THE SAME...

http://www.cplusplus.com/reference/cstdlib/itoa/

my conversion is wrong?

If you are not willing to accept help when offered then why on earth bother to ask the question?

Grumpy_Mike:
If you are not willing to accept help when offered then why on earth bother to ask the question?

why say that?...

I'm just trying to understand where is my problem...

Maybe I have not understood well what they said

Maybe I have not understood well what they said

You haven't. You've been told that your code for reading the RFID tag is not robust. You insist that the problem must come after that. You are not accepting the fact that you need to fix all upstream errors before trying to deal with downstream errors.

Make the code that reads the tags correct FIRST!

summary..

When I read my RFID card on my arduino it outputs value (10 characters if we excluding STX, BCC and ETX).

My card has a decimal number printed on it (9 characters >> 000353396 >> see image).

My question is, how can I calculate the decimal value printed on card from the hexadecimal reading from arduino?