I am just a programming novelist who needs help updating code.
The following script used to work with my RDM6300 RFID reader but no longer does since I updated to Arduino's newest IDE:
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>
#define RxPin 8 //Pin to read data
#define TxPin 9 //Pin to write data
//----
// Tags are stored in program flash memory
// 32k minus sketch size determines the amount of tags that can be stored
// Tags include the two CRC bytes (14 bytes total)
prog_char tag_0[] PROGMEM = "000000000000"; //add your tags here
prog_char tag_1[] PROGMEM = "000000000000";
prog_char tag_2[] PROGMEM = "000000000000";
prog_char tag_3[] PROGMEM = "000000000000";
prog_char tag_4[] PROGMEM = "000000000000";
prog_char tag_5[] PROGMEM = "000000000000";
prog_char tag_6[] PROGMEM = "000000000000";
PROGMEM const char *tag_table[] = {
tag_0,
tag_1,
tag_2,
tag_3,
tag_4,
tag_5,
tag_6 };
//----
SoftwareSerial rfidReader(RxPin, TxPin);
String tagString;
char tagNumber[14];
boolean receivedTag;
void setup() {
Serial.begin(9600);
while (!Serial) ;
rfidReader.begin(9600); // the RDM6300 runs at 9600bps
Serial.println("RFID Reader...ready!");
}
void loop() {
receivedTag=false;
while (rfidReader.available()){
Serial.println("rfid available");
int BytesRead = rfidReader.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag
receivedTag=true;
}
if (receivedTag){
tagString=tagNumber;
Serial.println();
Serial.print("Tag Number: ");
Serial.println(tagString);
if (checkTag(tagString)){
Serial.print("Tag Authorized...");
}
else{
Serial.print("Unauthorized Tag: ");
Serial.println(tagString);
delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
rfidReader.flush();
}
memset(tagNumber,0,sizeof(tagNumber)); //erase tagNumber
}
}
// ----
// checkTag function (give it the tag string complete with SOT and EOT)
// compares with tags in tag_table
// and returns true if the tag is in the list
boolean checkTag(String tag){
char testTag[14];
for (int i = 0; i < sizeof(tag_table)/2; i++) {
strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
if(tag.substring(1,13)==testTag){//substring function removes SOT and EOT
return true;
break;
}
}
return false;
}
//----
Any help debugging would be greatly appreciated.
Moderator: added [code]...[/code] tags
what is the latest version?
try this
#include <SoftwareSerial.h>
#include <avr/pgmspace.h>
#define RxPin 8 //Pin to read data
#define TxPin 9 //Pin to write data
//----
// Tags are stored in program flash memory
// 32k minus sketch size determines the amount of tags that can be stored
// Tags include the two CRC bytes (14 bytes total)
const char tag_0[] PROGMEM = "000000000000"; //add your tags here
const char tag_1[] PROGMEM = "000000000000";
const char tag_2[] PROGMEM = "000000000000";
const char tag_3[] PROGMEM = "000000000000";
const char tag_4[] PROGMEM = "000000000000";
const char tag_5[] PROGMEM = "000000000000";
const char tag_6[] PROGMEM = "000000000000";
const char* const tag_table[] PROGMEM = {
tag_0,
tag_1,
tag_2,
tag_3,
tag_4,
tag_5,
tag_6
};
//----
SoftwareSerial rfidReader(RxPin, TxPin);
String tagString;
char tagNumber[14];
boolean receivedTag;
void setup()
{
Serial.begin(9600);
while (!Serial) ;
rfidReader.begin(9600); // the RDM6300 runs at 9600bps
Serial.println("RFID Reader...ready!");
}
void loop()
{
receivedTag = false;
while (rfidReader.available())
{
Serial.println("rfid available");
int BytesRead = rfidReader.readBytesUntil(3, tagNumber, 15);//EOT (3) is the last character in tag
receivedTag = true;
}
if (receivedTag)
{
tagString = tagNumber;
Serial.println();
Serial.print("Tag Number: ");
Serial.println(tagString);
if (checkTag(tagString))
{
Serial.print("Tag Authorized...");
}
else
{
Serial.print("Unauthorized Tag: ");
Serial.println(tagString);
delay(1500); // a delay of 1500ms and a flush() seems to stop tag repeats
rfidReader.flush();
}
memset(tagNumber, 0, sizeof(tagNumber)); //erase tagNumber
}
}
// ----
// checkTag function (give it the tag string complete with SOT and EOT)
// compares with tags in tag_table
// and returns true if the tag is in the list
boolean checkTag(String tag)
{
char testTag[14];
for (int i = 0; i < sizeof(tag_table) / 2; i++)
{
strcpy_P(testTag, (char*)pgm_read_word(&(tag_table[i])));
if (tag.substring(1, 13) == testTag) //substring function removes SOT and EOT
{
return true;
}
}
return false;
}
//----
Thank you all for you help. Changing to const char solved my initial problem with Arduino IDE 1.6.1, but now I'm receiving the following error message:
Error compiling.
In function loop': undefined reference to delay'
In function SoftwareSerial::setTX(unsigned char)': undefined reference to digitalWrite'
undefined reference to pinMode' undefined reference to digital_pin_to_bit_mask_PGM'
undefined reference to digital_pin_to_port_PGM' undefined reference to port_to_output_PGM'
undefined reference to pinMode' undefined reference to digitalWrite'
In function main': undefined reference to init'
In function Stream::timedRead()': undefined reference to millis'
Think you need to reinstall your software as that are the core arduino commands.
wow, that worked. I can't thank you enough!