priya123
Junior Member level 1
Hi
This is my code..
I am not able to read the RFID tag. I am not very sure of the address, length,checksum and reset reader as I already said.
#include <Wire.h>
#include <EEPROM.h>
#define MAX_NO_CARDS 3
byte tag[4];
void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0x6c); // address of RFID reader
Wire.send(0x01); // length
Wire.send(0x80); // checksum
Wire.send(0x81); // reset reader
Wire.endTransmission();
}
void loop() {
if (Serial.available() > 0) {
Serial.read();
seekNewTag();
printTags();
}
else seekNewTag();
delay(200);
}
//Write Tag
void writeTag(int startingAddress, byte byte0, byte byte1, byte byte2, byte byte3){
EEPROM.write( startingAddress*5, byte(1));
EEPROM.write(startingAddress*5+1, byte0);
EEPROM.write(startingAddress*5+2, byte1);
EEPROM.write(startingAddress*5+3, byte2);
EEPROM.write(startingAddress*5+4, byte3);
}
//Find Empty Tag
int findEmptyTag(){
for (int startingAddress = 0; startingAddress< MAX_NO_CARDS; startingAddress++){
byte value = EEPROM.read(startingAddress*5);
if (value == byte(0)) {
return(startingAddress);
}
}
return(200);
}
//PrintTag
void printTags(){
for (int thisTag = 0; thisTag< MAX_NO_CARDS; thisTag++){
printOneTag(thisTag);
}
}
void printOneTag(int address) {
Serial.print(address);
Serial.print(":");
for (int offset = 1; offset < 5; offset++) {
int thisByte = int(EEPROM.read(address*5+offset));
if (thisByte < 0x10) {
Serial.print("0");
}
Serial.print(thisByte,HEX);
}
Serial.println();
}
//Look Up Tag
int lookupTag(byte byte0, byte byte1, byte byte2, byte byte3){
for (int thisCard = 0; thisCard< MAX_NO_CARDS; thisCard++){
byte value = EEPROM.read(thisCard*5);
if (value != byte(0)){
if(byte0 == EEPROM.read(thisCard*5+1) && byte1 == EEPROM.read(thisCard*5+2)
&& byte2 == EEPROM.read(thisCard*5+3) && byte3 == EEPROM.read(thisCard*5+4)) {
return(thisCard);
}
}
}
return(200);
}
//Seek New Tag
void seekNewTag() {
Serial.println("Waiting for card");
if (Serial. available()) {
return;
}
int tagToCheck = lookupTag(tag[0], tag[1], tag[2], tag[3]);
if (tagToCheck != 200){
Serial.println("That tag is already stored");
printOneTag(tagToCheck);
}
else {
int emptyTagLocation = findEmptyTag();
if (emptyTagLocation != 200){
writeTag(emptyTagLocation, tag[0], tag[1], tag[2], tag[3]);
Serial.println("That tag is new");
printOneTag(emptyTagLocation);
}
}
}
I am gettin an output as follows:
Waiting for tag
That tag is already stored
0:00000000
This is my code..
I am not able to read the RFID tag. I am not very sure of the address, length,checksum and reset reader as I already said.
#include <Wire.h>
#include <EEPROM.h>
#define MAX_NO_CARDS 3
byte tag[4];
void setup()
{
Wire.begin();
Serial.begin(9600);
Wire.beginTransmission(0x6c); // address of RFID reader
Wire.send(0x01); // length
Wire.send(0x80); // checksum
Wire.send(0x81); // reset reader
Wire.endTransmission();
}
void loop() {
if (Serial.available() > 0) {
Serial.read();
seekNewTag();
printTags();
}
else seekNewTag();
delay(200);
}
//Write Tag
void writeTag(int startingAddress, byte byte0, byte byte1, byte byte2, byte byte3){
EEPROM.write( startingAddress*5, byte(1));
EEPROM.write(startingAddress*5+1, byte0);
EEPROM.write(startingAddress*5+2, byte1);
EEPROM.write(startingAddress*5+3, byte2);
EEPROM.write(startingAddress*5+4, byte3);
}
//Find Empty Tag
int findEmptyTag(){
for (int startingAddress = 0; startingAddress< MAX_NO_CARDS; startingAddress++){
byte value = EEPROM.read(startingAddress*5);
if (value == byte(0)) {
return(startingAddress);
}
}
return(200);
}
//PrintTag
void printTags(){
for (int thisTag = 0; thisTag< MAX_NO_CARDS; thisTag++){
printOneTag(thisTag);
}
}
void printOneTag(int address) {
Serial.print(address);
Serial.print(":");
for (int offset = 1; offset < 5; offset++) {
int thisByte = int(EEPROM.read(address*5+offset));
if (thisByte < 0x10) {
Serial.print("0");
}
Serial.print(thisByte,HEX);
}
Serial.println();
}
//Look Up Tag
int lookupTag(byte byte0, byte byte1, byte byte2, byte byte3){
for (int thisCard = 0; thisCard< MAX_NO_CARDS; thisCard++){
byte value = EEPROM.read(thisCard*5);
if (value != byte(0)){
if(byte0 == EEPROM.read(thisCard*5+1) && byte1 == EEPROM.read(thisCard*5+2)
&& byte2 == EEPROM.read(thisCard*5+3) && byte3 == EEPROM.read(thisCard*5+4)) {
return(thisCard);
}
}
}
return(200);
}
//Seek New Tag
void seekNewTag() {
Serial.println("Waiting for card");
if (Serial. available()) {
return;
}
int tagToCheck = lookupTag(tag[0], tag[1], tag[2], tag[3]);
if (tagToCheck != 200){
Serial.println("That tag is already stored");
printOneTag(tagToCheck);
}
else {
int emptyTagLocation = findEmptyTag();
if (emptyTagLocation != 200){
writeTag(emptyTagLocation, tag[0], tag[1], tag[2], tag[3]);
Serial.println("That tag is new");
printOneTag(emptyTagLocation);
}
}
}
I am gettin an output as follows:
Waiting for tag
That tag is already stored
0:00000000