yesterday my new arduino mega arrived. I am new working with the arduino so maybe anybody can help me.
I tried to connect the RDM630 RFID Module bought at watterott.com . The specification can also be found there.
I tried to connect the module as explained in "How to connect Arduino and RFID" at instuctables.com . However this example uses not an adruino mega.
I connected the TX (PIN1) of the module with PIN2 of the PWM connectors. Is that correct?
Compiling and uploading the sourcecode from the instrucatble example worked fine, however I don`t get any reaction when putting a RFID Tag on the antenna of the module.
I intended to use the software serial connection because I did not find a code for the TX/RX connection.
Can anybody tell me if the wireing is ok and if the code is also ok or do I have to make any changes? Maybe there are some special things that I have to do first working with the arduino mega?
The TX pin should be connected to one of the RX pins on the Mega. There are 4 of them on the Mega. Then, use the appropriate Serial instance (Serial, Serial1, etc.) to read the data.
Of course, power and ground need to be connected, too.
Can anybody tell me if the wireing is ok and if the code is also ok or do I have to make any changes?
while(RFID.available()>0){
c=RFID.read();
msg.append(c); //Serial.println(msg); //Uncomment to view your tag ID
}
if(msg.contains(ADD_TAG_CODE)) add();
if(msg.contains(DEL_TAG_CODE)) del();
if(msg.length()>10) verifica();
msg="";
}
void add(){
Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13){
while(RFID.available()>0){
c=RFID.read();
msg.append(c);
}
}
if(ID.contains(msg)) {
Serial.println("\nAccess already granted for this card.");
msg="";
}
else{ //Serial.print("Card: ");
Serial.println(msg);
ID.append(msg);
ID.append(","); //Serial.print("ID: "); //Serial.println(ID);
msg="";
Serial.println("Access granted for this card.");
}
}
void del(){
msg="";
Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<13){
while(RFID.available()>0){
c=RFID.read();
msg.append(c);
}
}
if(ID.contains(msg)){
Serial.println(msg);
Serial.println("TAG found. Access for this card denied."); //ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg.append(ID.substring(0,pos));
msg.append(ID.substring(pos+15,ID.length()));
ID="";
ID.append(msg); //Serial.print("ID: "); //Serial.println(ID);
} else Serial.println("\nTAG not found or already denied");
msg="";
}
I have tried using this rfid module with the Arduino MEGA and I am experiencing the same thing. I can verify that the module is working as I can see the LED blink when a tag is scanned. I think the issue is with the NewSoftSerial library used with this code which doesn't seem to work with the MEGA...or so I've inferred from a thread elsewhere.
I made the code work with the Mega board. I just replaced the softSerial and use instead the Serial1 from the Arduino Mega board. I have also to use a small delay of 5 ms, otherwise the sketch didn't run successful!
Best regards
Sebastian
#define ADD_TAG_CODE "0100028AD5" //change this ID with your own card TAG #define DEL_TAG_CODE "3D00A84FF7"
String msg;
String ID ; //string to store allowed cards
while(Serial1.available()>0){
delay(5); //================================================ without this delay it dosn't work!===============
c=Serial1.read();
msg += c; //Serial.println(msg); //Uncomment to view your tag ID //Serial.println(msg.length());
}
msg=msg.substring(1,13);
if(msg.indexOf(ADD_TAG_CODE)>=0) add();
else if(msg.indexOf(DEL_TAG_CODE)>=0) del();
else if(msg.length()>10) verifica();
msg="";
}
void add(){ Serial.print("What TAG do you wanna grant access?: ");
msg="";
while(msg.length()<13){
while(Serial1.available()>0){
c=Serial1.read();
msg += c;
}
}
if(ID.indexOf(msg)>=0) { Serial.println("\nAccess already granted for this card.");
msg="";
}
else{ Serial.print("Card: "); Serial.println(msg);
ID += msg;
ID += ","; //Serial.print("ID: ");
// Serial.println(ID);
msg=""; Serial.println("Access granted for this card.");
}
}
void del(){
msg=""; Serial.print("What TAG do you wanna deny access?: ");
while(msg.length()<13){
while(Serial1.available()>0){
c=Serial1.read();
msg += c;
}
}
msg=msg.substring(1,13);
if(ID.indexOf(msg)>=0){ Serial.println(msg); Serial.println("TAG found. Access for this card denied."); //ID.replace(card,"");
int pos=ID.indexOf(msg);
msg="";
msg += ID.substring(0,pos);
msg += ID.substring(pos+15,ID.length());
ID="";
ID += msg; //Serial.print("ID: "); //Serial.println(ID);
}
else Serial.println("\nTAG not found or already denied");
msg="";
}
That's because NewSoftSerial is not supported on the Mega, unless you have downloaded the patched version, which only works on certain pins - none of which include ANY of the hardware serial pins.
With 4 hardware serial ports, WHY do you INSIST on trying to use a slow software solution for something that is done very well in hardware?
With 4 hardware serial ports, WHY do you INSIST on trying to use a slow software solution for something that is done very well in hardware?
Hi Paul,
I just wont to try the code on the Mega without changing it. But I think you don't see the problem. The problem was that the RFID Reader send the data to slow. Not only for the hardware serial on the Mega, also for the softSerial on the Duemilanove.