Arduino Mega in combination with Grove RFID reader

Goodday.



I experience issues in the connectivity between the Arduino Mega and the Grove RFID 125khz reader.



When I use the following connection and code everything works fine and I can read the RFID tags</s>RFID Reader--------Arduino (Mega) Tx-------------------Rx Rx-------------------Tx GND-----------------GND VCC------------------5v<e>
[code]void setup()
{ Serial.begin(9600);}

void loop()
{
if(Serial.available())
{
while(Serial.available())
Serial.write(Serial.read());
}
}[/code]

However when I use the following code;
[code]// RFID_UART.ino

#include <SoftwareSerial.h>
#include <SeeedRFID.h>

#define RFID_RX_PIN 10
#define RFID_TX_PIN 11

#define TEST

SeeedRFID RFID(RFID_RX_PIN, RFID_TX_PIN);
RFIDdata tag;

void setup() {
Serial.begin(57600);
Serial.println(“Hello, double bk!”);
}

void loop()
{
if(RFID.isAvailable())
{
tag = RFID.data();
Serial.print("RFID card number: ");
Serial.println(RFID.cardNumber());
#ifdef TEST
Serial.print("RFID raw data: ");
for(int i=0; i<tag.dataLen; i++)
{
Serial.print(tag.raw[i], HEX);
Serial.print(’\t’);
}
#endif
}
}[/code]
I am not receiving any data from the tags. I see the green led on the Grove RFID reader blink but nothing seems to be sent to the arduino.

In this case I have connected the Grove RFID RX pin to Arduino digital pin 10 and the RFID TX pin to the arduino digital pin 11



To be sure I switched pin 10 and 11 around (and tried many other setups) but nothing seems to work.

Can somebody advice what i am doing wrong.

Hi, i tested it successfully.

  1. hardware connection




  2. software
    [code]/*
    link between the computer and the SoftSerial Shield
    at 9600 bps 8-N-1
    Computer is connected to Hardware UART
    SoftSerial Shield is connected to the Software UART:D2&D3
    */

#include <SoftwareSerial.h>

SoftwareSerial SoftSerial(10, 11);
unsigned char buffer[64]; // buffer array for data receive over serial port
int count = 0; // counter for buffer array

void setup()
{
SoftSerial.begin(9600); // the SoftSerial baud rate
Serial.begin(9600); // the Serial port of Arduino baud rate.
}

void loop()
{
// if date is coming from software serial port ==> data is coming from SoftSerial shield
if (SoftSerial.available())
{
while(SoftSerial.available()) // reading data into char array
{
buffer[count++] = SoftSerial.read(); // writing data into array
if(count == 64)break;
}
Serial.write(buffer, count); // if no data transmission ends, write buffer to hardware serial port
clearBufferArray(); // call clearBufferArray function to clear the stored data from the array
count = 0; // set counter of while loop to zero
}
if (Serial.available()) // if data is available on hardware serial port ==> data is coming from PC or notebook
SoftSerial.write(Serial.read()); // write it to the SoftSerial shield
}
void clearBufferArray() // function to clear buffer array
{
// clear all index of array with command NULL
for (int i=0; i<count; i++)
{
buffer[i]=NULL;
}
}[/code]


3. output

[img]https://github.com/SeeedDocument/forum_doc/raw/master/image/rfid.png[/img]

Bill

Thanks for your response, however based on your pictures your setup looks slightly different as I am currently using an arduino Mega and in your picture a Grove mega shield is being used.

This triggered me with a different thought that maybe not all pins on the mega can be used for software serial communication.

So I did some digging and found out the following.
</s>Not all pins on the Mega and Mega 2560 support change interrupts, so only the following can be used for RX: 10, 11, 12, 13, 14, 15, 50, 51, 52, 53, A8 (62), A9 (63), A10 (64), A11 (65), A12 (66), A13 (67), A14 (68), A15 (69).<e>
https://www.arduino.cc/en/Reference/SoftwareSerial



I now changed the program to use pin 52/53 en finally I get readings. So I can move on with testing the setup, thanks :smiley: