How to read the RFID tag number into a single line
i tried
int i;
void setup()
{
Serial.begin(9600); // start serial to PC
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available())
{
while(Serial1.available()){
i = Serial1.read();}
Serial.println(i);
}
}
These are the codes i tried and their respective outputs.
int i;
void setup()
{
Serial.begin(9600); // start serial to PC
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available())
{
while(Serial1.available())
{
i = Serial1.read();
}
Serial.print(i);
Serial.println("");
}
}
Issue with this output is that this number 0105521670 is not the number printed in the tag. I have to convert the numbers into hex 3 by 3 and convert it to decimal to take the correct tag number.
Secondly after the first reading it takes 3 or four reading to display the number again.
So what is the solutions for these issues for not giving the correct tag number and printing and converting it correctly
Like I said, you didn't do what I told you for the first one. You just put the two print statements next to each other.
However your overall problem is that you are processing the data way faster than it is comming in. So you get one character in the serial buffer, enter the while Avaliable loop, read one character then the buffer is empty so you fall out of the initial if and the loop function gets called again.
Soloution - how many bytes are you expecting? The first if should only be true if you have that number or greater bytes in the buffer.
Same results for this code also, Separation using println("") doesn't work.
int i;
void setup()
{
Serial.begin(9600); // start serial to PC
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available())
{
while(Serial1.available())
{
i = Serial1.read();
Serial.print(i);
}
Serial.println("");
}
}
Output:
0
104
248
112
And readings from Wiegand library gives correct outputs.
Same results for this code also, Separation using println("") doesn't work.
That is because you have not addressed what I said in the last post about you processing data too fast. A simple but not recommended solution is to put in a delay so that there is time for the next byte to arrive:-
int i;
void setup()
{
Serial.begin(9600); // start serial to PC
Serial1.begin(9600);
}
void loop()
{
if (Serial1.available())
{
while(Serial1.available())
{
i = Serial1.read();
Serial.print(i);
delay(3);
}
Serial.println("");
}
}
Now main issue is what is the relationship between these Hex value and the decimal.
This is correct:-
Wiegand HEX = 68F870, DECIMAL = 6879344
Grumpy_Mike:
This is correct:-
Wiegand HEX = 68F870, DECIMAL = 6879344
So what is incorrect?
Normal Hex to decimal conversion doesn't give the 6879344 decimal output. If these numbers are considered only as Dwords, conversion matches. So how do i read or set these Hex values as Dwords and convert to Dword decimal.
I require this conversion because tag numbers appear in Arduino is as decimal (tag output 0104248112 = hex 68F870).
Basically you do not convert a number from decimal to hex.
Numbers are stored in the computer as variables in binary. There is only the concept of conversion when you print out or otherwise display this binary bit pattern.
So you can not CONVERT a number into decimal or into hex, you can only display it as such.
Normal Hex to decimal conversion doesn't give the 6879344 decimal output.
What do you consider "normal", please post the code where you are failing to display the number correctly.
Edit, missed that last post before I wrote this, it was on a page boundary and I didn't spot it.
Can u explain how to put it into variables as v1=0x0.
That is just an illustration, simply use the variables you have received.
And the rest of code how does it work.
It simply ORs together ( the | symbol ) each of the four bytes you receive. Each byte is shifted into the right place in the 32 bit filed by using the << ( shift left ) operator.