It doesn't, but the sketch that prints the received data in post #20 does...
Your received data and card number is matching but mine is not matching.
My received data is coming correctly but card number is false.
Received data: 02 36 35 33 38 36 44 34 31 31 33 // for card number
giving false
Card number:349602646
This values are not correct and it has to be 12 character but it gives 9.
What is the full string you receive?
Can you post your full sketch and the full output from the Serial Monitor.
#include <Arduino.h>
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3);
byte b;
byte buffer[30];
uint8_t idx;
boolean started = false;
byte XOR;
byte inverted;
uint32_t value;
void setup()
{
Serial.begin (9600);
RFID.begin (9600);
}
void loop()
{
while (RFID.available())
{
b = RFID.read();
if (b == 0x02) // Start byte
{
idx = 0;
started = true;
}
if (started) // Ignore anything received until we get a start byte.
{
buffer[idx++] = b;
if (b == 0x03) // End byte
{
started = false;
// Display the received data.
Serial.print("Received data: ");
for (int x = 0; x < idx; x++)
{
if (buffer[x] < 0x10)
{
Serial.print("0"); // Pad with leading 0
}
Serial.print (buffer[x], HEX);
Serial.print (" ");
}
Serial.println("");
// Check we received the message ok. XOR checksum on bytes 01-26 should match byte 27.
XOR = buffer[1];
for (int x = 2; x <= 26; x++)
{
XOR ^= buffer[x];
}
Serial.print("Calculated checksum: ");
Serial.print(XOR, HEX);
if (XOR == buffer[27])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Check the inverted XOR checksum
inverted = ~XOR;
Serial.print("Inverted checksum: ");
Serial.print(inverted, HEX);
if (inverted == buffer[28])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Extract the card number from bytes 01 (LSB) - 10 (MSB).
value = 0;
Serial.print("This is my buffer[x] from 1 to 10: ");
for (int x = 10; x >= 1; x--)
{
Serial.print(buffer[x], HEX);
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.println("");
Serial.print("Card number: ");
Serial.println(value);
// Extract the country number from bytes 11 (LSB) - 14 (MSB).
value = 0;
for (int x = 14; x >= 11; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Country number: ");
Serial.println(value);
// Extract the Data Block from byte 15.
Serial.print("Data block: ");
Serial.println(buffer[15] - '0');
// Extract the Animal Flag from byte 16.
Serial.print("Animal flag: ");
Serial.println(buffer[16] - '0');
Serial.println("\r");
}
}
}
}
Received data: 02 36 35 33 38 36 44 34 31 31 33 37 45 33 30 31 31 30 30 30 30 30 30 30 30 30 30 0C F3 03
Calculated checksum: C (Correct)
Inverted checksum: F3 (Correct)
This is my buffer[x] from 1 to 10: 33313134443638333536
Card number: 349602646
Country number: 999
Data block: 1
Animal flag: 1
The reason you are not getting the correct card number (which I believe is 210 803 000 150, is the variable value is only 32 bits long, and is therefore overflowing.
In my case the card numbers were a lot smaller so didn't have this problem.
If you define as follows it should work
uint64_t value;
Note that Serial.print can't handle numbers this big so you will need another way to display it.
You could try something as suggested in this post:
Yes, it works. Thank you for your help.
I have the same WL-134 RFID reader board as yourself but it is a newer revision as it includes a 3.3v TTL (for Raspberry Pi) as well as the existing 5v TTL.
When hooked up to only a battery I can see the blue LED flash when it reads a tag. However when I hook up the TXD the blue LED no longer flashes and I also don't see anything on Serial.
Would you tell me if the blue LED still flashes when TXD is wired up?
The simplest hookup is just to a 6v lantern battery and uses the 3.3v TX to the Raspberry Pi.
I also have tried using the 5v TX with a Logic Level Converter to step it down to 3.3v needed by the Pi using a Sparkfun LLC.
...[more to follow]
A picture of the RFID Reader with the additional pins and datasheet.
To make a follow up on this thread, I brought a USB to TTL converter and plugged the RFID module into that. When plugged into my desktop/workstation everything works fine, however when I plug into the Raspberry Pi the RFID module stops working.
I realise this is an Arduino forum and not a Pi forum, but the discussion here helped me to narrow the problem down so maybe this is useful for others that come across this problem.
You need to have a common GND between the RFID reader and the Arduino/Pi.
@maru33 Did you try with a common ground?
With common ground the same problem exists, I have a thread going on the Pi forum here which has some links to others with the same problem. Basically the system has to be ground to earth to work due to the AC noise filtering through from the Pi power supply, as too if that noise could be taken out is well beyond my ability and requires a oscilloscope and indepth knowledge of electrical engineering and RF.
Hi!
@red_car , can you help with my coding?
I copied your code and hooked up my arduino and rfid reader and reads small chips and both of my cats. Now i want a action/ command to happen when a certain "chip/ cat" activates the rfid.
Here's the code
<
#include <SoftwareSerial.h>
SoftwareSerial RFID(7, 8);
byte b;
byte buffer[30];
uint8_t idx;
boolean started = false;
byte XOR;
byte inverted;
uint32_t value;
void setup()
{
Serial.begin (9600);
RFID.begin (9600);
}
void loop()
{
String content = "";
while (RFID.available())
{
b = RFID.read();
if (b == 0x02) // Start byte
{
idx = 0;
started = true;
}
if (started) // Ignore anything received until we get a start byte.
{
buffer[idx++] = b;
if (b == 0x03) // End byte
{
started = false;
// Display the received data.
Serial.print("Received data: ");
for (int x = 0; x < idx; x++)
{
if (buffer[x] < 0x10)
{
Serial.print("0"); // Pad with leading 0
}
Serial.print (buffer[x], HEX);
Serial.print (" ");
}
Serial.println("");
// Check we received the message ok. XOR checksum on bytes 01-26 should match byte 27.
XOR = buffer[1];
for (int x = 2; x <= 26; x++)
{
XOR ^= buffer[x];
}
Serial.print("Calculated checksum: ");
Serial.print(XOR, HEX);
if (XOR == buffer[27])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Check the inverted XOR checksum
inverted = ~XOR;
Serial.print("Inverted checksum: ");
Serial.print(inverted, HEX);
if (inverted == buffer[28])
Serial.println(" (Correct)");
else
Serial.println(" (Error)");
// Extract the card number from bytes 01 (LSB) - 10 (MSB).
value = 0;
for (int x = 10; x >= 1; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Card number: ");
Serial.println(value);
// Extract the country number from bytes 11 (LSB) - 14 (MSB).
value = 0;
for (int x = 14; x >= 11; x--)
{
if(buffer[x] <= '9')
value = (value<<4) + buffer[x] - '0';
else
value = (value<<4) + buffer[x] - '7';
}
Serial.print("Country number: ");
Serial.println(value);
// Extract the Data Block from byte 15.
Serial.print("Data block: ");
Serial.println(buffer[15] - '0');
// Extract the Animal Flag from byte 16.
Serial.print("Animal flag: ");
Serial.println(buffer[16] - '0');
Serial.println("\r");
}
}
}
}
This is what i get :
Received data: 02 37 30 36 36 35 34 46 30 32 33 34 38 33 30 30 31 30 30 30 30 30 30 30 30 30 30 7F 80 03
Calculated checksum: 7F (Correct)
Inverted checksum: 80 (Correct)
Card number: 256206343
Country number: 900
Data block: 0
Animal flag: 1
How can i code it so just my cat can activate it?
Thanks!
After this code...
Just add...
if(value == 256206343)
{
Serial.println("My cat");
// Do other stuff
}
@red_car Thanks, Works like a charm!
@red_car sorry to bother you, but if i want my RFID to take a brake for 10 minutes, so it dosent read the cat 10 times when in the reach of the antenna.
Can you help me with that one ass well? ![]()
See Using millis() for timing. A beginners guide ,
I think you can write something like this :
you should define startMillis and period. period is //the value is a number of milliseconds.
currentMillis = millis(); //get the current "time" (actually the number of milliseconds since the
program started)
if (currentMillis - startMillis >= period) //test whether the period has elapsed
{
startMillis = currentMillis;
while (RFID.available())
{
}
}
It depends exactly what you are trying to do.
Do you want to completely stop reading RFID tags for 10 minutes?
Or do you just want to ignore the one cat that it already detected?
@red_car If theres no issues with completly stop it for 10min, i would like to do that.
As it is now, it read the chip, and while it command the LED and servo, and still hold the chip nearby, it reads the chip again multiplie times and keep that in its mind. So when the "cycle" is done, it repeat it selv multiple times.
My plan for the prosject is to make a feeder who feed the cat a small amount of food when the cat/ chip activates it, but have to wait 10min/30min until next time.

