Hey there guys,
I have been messing around with Arduino for a little bit and have a project with five RDM6300 readers. Wanted to have five of them each read a chip and "unlock" if in the right order. I got them working last week where most of them would give my Arduino UNO a data signal. Now, this week I ordered a Mega board and tried it again and nothing is happening. I switched back to the old board and nothing happened. I was following some code I found online that I had working for the UNO board that was meant for the MEGA board. I just don't understand what is going on.
--Details--
So in my code I check for Serial.available(). If it is it pushes the data through the TX port, or in my case pin three on the UNO. I have the RDM6300 hooked up correctly to the UNO, like seen on online photos and videos. I have 125khz chips, like needed for the RDM6300 board. I have looked through a lot of the normal question and answer forums for this problem and am coming up empty. If I remove the "> 0" it just outputs -1, -1, -1, -1, -1...
Anyone able to shine some light on this problem I am having? I was going to connect four of these boards into the MEGA and call it good, but I just can't get them to work anymore.
Thank you in advanced~
This is what I am working on for my main code for my project
#include <SoftwareSerial.h>
#define NREADER 2
#define NSAVER 5
#define NTAGS 5
#define TAGLEN 14
//Lights and such for the code
int data1 = 0;
int ok = -1;
//int yes = 13;
//int no = 12;
//int win = 0;
//int tControl = 0;
//int t1 = 8;
//int t2 = 9;
//int t3 = 10;
//int t4 = 11;
int chip[NTAGS] = {
0,
0,
0,
0,
0,
};
//// use first sketch in http://wp.me/p3LK05-3Gk to get your tag numbers
////int tag1[14] = {2,52,48,48,48,56,54,66,49,52,70,51,56,3};
//int tag1[14] = {2,51,56,48,48,56,65,52,53,51,57,67,69,3};
//int tag2[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};
//int tag3[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};
//int tag4[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};
//int tag5[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};
int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // used for read comparisons
int tags[NTAGS][TAGLEN] = {
{2,48,53,48,48,48,52,68,65,48,48,68,66,3}, //Bottle 1
{2,48,53,48,48,48,54,51,51,55,55,52,55,3}, //Bottle 2
{2,48,53,48,48,48,52,67,48,67,54,48,55,3}, //Bottle 3
{2,48,53,48,48,48,54,51,51,53,66,54,66,3}, //Bottle 4
{2,48,53,48,48,48,52,65,54,68,53,55,50,3}, //Bottle 5 / backup
};
SoftwareSerial readers[NREADER] = {
SoftwareSerial(2, 3),
SoftwareSerial(4, 5),
};
void setup()
{
//readers.begin(9600);
Serial.begin(9600); // start serial to PC
}
boolean comparetag(int aa[14], int bb[14])
{
boolean ff = false;
int fg = 0;
for (int cc = 0 ; cc < 14 ; cc++)
{
if (aa[cc] == bb[cc])
{
fg++;
}
}
if (fg == 14)
{
ff = true;
}
return ff;
}
//void readTags()
//{
// ok = -1;
//
// if (RFID.available() > 0)
// {
// // read tag numbers
// delay(100); // needed to allow time for the data to come in from the serial buffer.
//
// for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
// {
// data1 = RFID.read();
// newtag[z] = data1;
// }
// RFID.flush(); // stops multiple reads
//
// // do the tags match up?
// //checkmytags(); CUT OUT RIGHT NOW.
// }
//
// // now do something based on tag type
// if (ok > 0) // if we had a match
// {
// Serial.println("Accept");
// for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
// {
// Serial.print(newtag[z]);
// Serial.print(", ");
// }
// digitalWrite(yes, HIGH);
// delay(1000);
// digitalWrite(yes, LOW);
// ok = -1;
// }
// else if (ok == 0) // if we didn't have a match
// {
// Serial.println("Rejected");
// for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
// {
// Serial.print(newtag[z]);
// Serial.print(", ");
// }
// ok = -1;
// Serial.println();
// Serial.println();
// digitalWrite(no, HIGH);
// delay(1000);
// digitalWrite(no, LOW);
// }
//}
///////////////////////////////////////////////////////////////////////////////////
void readTagsNew(int reader_index)
{
Serial.begin(9600);
ok = -1;
Serial.println("Start");
SoftwareSerial RFID = readers[reader_index];
RFID.begin(9600); // Start serial to RFID reader
delay(200); // needed to allow time for the data to come in from the serial buffer.
Serial.println(RFID);
//if (RFID.available() > 0)
if (RFID > 0)
{
Serial.println("RFID Read");
delay(100);
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data1 = RFID.read();
newtag[z] = data1;
}
RFID.flush(); // stops multiple reads
if (memcmp(newtag, tags[reader_index], sizeof(tags[reader_index])) == 0)
{
chip[reader_index] = 1;
}
else
{
Serial.println("No compare");
}
Serial.println("Chip");
Serial.println(chip[reader_index]);
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
Serial.print(newtag[z]);
Serial.print(",");
}
Serial.println("");
RFID.end();
}
}
void loop()
{
// for (int r = 0; r < NREADER; r++)
// {
// readTagsNew(r);
// }
Serial.println("Read 0");
delay(1000);
readTagsNew(0);
//delay(2000);
// Serial.println("Read 1");
// delay(1000);
// readTagsNew(1);
// delay(2000);
if (chip[0] == 1)
{
Serial.println("Accept chip1");
if (chip[1] == 1)
{
Serial.println("Accept chip2");
if (chip[2] == 1)
{
Serial.println("Accept chip3");
if (chip[3] == 1)
{
Serial.println("Accept chip4");
if (chip[5] == 1)
{
Serial.println("Accept chip5");
Serial.println("Accepted all");
}
}
}
}
}
}
What I have running on the board currently to test if anything is working.
#include <SoftwareSerial.h>
SoftwareSerial RFID(2, 3); // RX and TX
//SoftwareSerial RFID(0, 1); // RX and TX
int data1 = 0;
int ok = -1;
int yes = 13;
int no = 12;
// use first sketch in http://wp.me/p3LK05-3Gk to get your tag numbers
int tag1[14] = {2,52,48,48,48,56,54,66,49,52,70,51,56,3};
int tag2[14] = {2,52,48,48,48,56,54,67,54,54,66,54,66,3};
int tag3[14] = {2,51,56,48,48,56,65,52,53,51,57,67,69,3};
int newtag[14] = { 0,0,0,0,0,0,0,0,0,0,0,0,0,0}; // used for read comparisons
void setup()
{
RFID.begin(9600); // start serial to RFID reader
Serial.begin(9600); // start serial to PC
pinMode(yes, OUTPUT); // for status LEDs
pinMode(no, OUTPUT);
}
boolean comparetag(int aa[14], int bb[14])
{
boolean ff = false;
int fg = 0;
for (int cc = 0 ; cc < 14 ; cc++)
{
if (aa[cc] == bb[cc])
{
fg++;
}
}
if (fg == 14)
{
ff = true;
}
return ff;
}
void checkmytags() // compares each tag against the tag just read
{
ok = 0; // this variable helps decision-making,
// if it is 1 we have a match, zero is a read but no match,
// -1 is no read attempt made
if (comparetag(newtag, tag1) == true)
{
ok++;
}
if (comparetag(newtag, tag2) == true)
{
ok++;
}
if (comparetag(newtag, tag3) == true)
{
ok++;
}
}
void readTags()
{
ok = -1;
if (RFID.available() > 0)
{
// read tag numbers
delay(100); // needed to allow time for the data to come in from the serial buffer.
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
data1 = RFID.read();
newtag[z] = data1;
}
RFID.flush(); // stops multiple reads
// do the tags match up?
checkmytags();
}
// now do something based on tag type
if (ok > 0) // if we had a match
{
Serial.println("Accepted");
digitalWrite(yes, HIGH);
delay(1000);
digitalWrite(yes, LOW);
ok = -1;
}
else if (ok == 0) // if we didn't have a match
{
Serial.println("Rejected");
for (int z = 0 ; z < 14 ; z++) // read the rest of the tag
{
Serial.print(newtag[z]);
Serial.print(", ");
}
Serial.println();
Serial.println();
digitalWrite(no, HIGH);
delay(1000);
digitalWrite(no, LOW);
ok = -1;
}
}
void loop()
{
readTags();
}