Elegoo mega2560 r3 wih M6E nano rfid using hardware serial

I am trying to connect my Arduino/elegoo mega 2560 r3 with the m6e nano rfid using hardware serial I made the changes to the code for the library for reading the tag, I made sure the switch is in the HW - UART, and used the serial2 of the mega and after uploading code it shows this in the serial monitor:

and it is not detecting the tag at all

This is the connection, and I ensured the wiring is also right.

here is the code:

/*
  Reading multiple RFID tags, simultaneously!
  By: Nathan Seidle @ SparkFun Electronics
  Date: October 3rd, 2016
  https://github.com/sparkfun/Simultaneous_RFID_Tag_Reader

  Single shot read - Ask the reader to tell us what tags it currently sees. And it beeps!
*/

// Library for controlling the RFID module
#include "SparkFun_UHF_RFID_Reader.h"

// Create an instance of the RFID module
RFID rfidModule;

// Use Hardware Serial2 for communication with the RFID module
#define rfidSerial Serial2 // Use Serial2 for the Elegoo Mega 2560 R3

// Set the baud rate for the RFID module
#define rfidBaud 115200 // Set baud rate to 115200 for hardware serial

// Specify which module you are using
#define moduleType ThingMagic_M6E_NANO
// #define moduleType ThingMagic_M7E_HECTO

#define BUZZER1 9
//#define BUZZER1 0 //For testing quietly
#define BUZZER2 10

void setup()
{
  Serial.begin(115200);

  pinMode(BUZZER1, OUTPUT);
  pinMode(BUZZER2, OUTPUT);

  digitalWrite(BUZZER2, LOW); //Pull half the buzzer to ground and drive the other half.

  while (!Serial);
  Serial.println();
  Serial.println("Initializing...");

  if (setupRfidModule(rfidBaud) == false)
  {
    Serial.println("Module failed to respond. Please check wiring.");
    while (1); // Freeze!
  }

  rfidModule.setRegion(REGION_NORTHAMERICA); // Set to North America

  rfidModule.setReadPower(500); // 5.00 dBm
}

void loop()
{
  Serial.println(F("Press a key to scan for a tag"));
  while (!Serial.available()); // Wait for user to send a character
  Serial.read(); // Throw away the user's character

  byte myEPC[12]; // Most EPCs are 12 bytes
  byte myEPClength;
  byte responseType = 0;

  while (responseType != RESPONSE_SUCCESS)
  {
    myEPClength = sizeof(myEPC); // Length of EPC is modified each time .readTagEPC is called

    responseType = rfidModule.readTagEPC(myEPC, myEPClength, 500); // Scan for a new tag up to 500ms
    Serial.println(F("Searching for tag"));
  }

  // Beep!
  tone(BUZZER1, 2093, 150); // C
  delay(150);
  tone(BUZZER1, 2349, 150); // D
  delay(150);
  tone(BUZZER1, 2637, 150); // E
  delay(150);

  // Print EPC
  Serial.print(F(" epc["));
  for (byte x = 0; x < myEPClength; x++)
  {
    if (myEPC[x] < 0x10) Serial.print(F("0"));
    Serial.print(myEPC[x], HEX);
    Serial.print(F(" "));
  }
  Serial.println(F("]"));
}

// Gracefully handles a reader that is already configured and already reading continuously
boolean setupRfidModule(long baudRate)
{
  rfidModule.begin(rfidSerial, moduleType); // Tell the library to communicate over serial port

  // Test to see if we are already connected to a module
  rfidSerial.begin(baudRate); // Start serial at desired baud rate
  delay(100); // Wait for port to open

  // Ignore initial messages from the module
  while (rfidSerial.available())
    rfidSerial.read();

  rfidModule.getVersion();

  if (rfidModule.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)
  {
    rfidModule.stopReading(); // Stop continuous reading
    Serial.println(F("Module continuously reading. Asking it to stop..."));
    delay(1500);
  }
  else
  {
    // The module did not respond, assume it's been powered on and is communicating at 115200bps
    rfidSerial.begin(115200); // Start serial at 115200
    rfidModule.setBaud(baudRate); // Set module baud rate

    rfidSerial.begin(baudRate); // Start the serial port at user's chosen baud rate
    delay(250);
  }

  // Test the connection
  rfidModule.getVersion();
  if (rfidModule.msg[0] != ALL_GOOD)
    return false; // Something is not right

  // Set protocol and antenna
  rfidModule.setTagProtocol(); // Set protocol to GEN2
  rfidModule.setAntennaPort(); // Set TX/RX antenna ports to 1

  return true; // We are ready to rock
}

Please kindly let me know what I am doing wrong. Thank you

Looks like you've swapped Tx and Rx.

If you would have used it as a shield, it would connect Tx to Tx and Rx to Rx. So in your setup, Tx2 of the Mega must go to Tx of the shield and Rx2 of the Mega to Rx of the shield.

If you would have used TXO and RXI on the shield, the connections would have been TX2 of the Mega to RXI and RX2 of the Mega to TXO.

Yes you were right its working thank you very much; one more question so if I were to use the TXO and RX1 do they still function just like the other like does it make a serial communication between the RFID and MEGA?

Look at the schematic: https://cdn.sparkfun.com/datasheets/Sensors/ID/Simultaneous_RFID_Tag_Reader.pdf and decide. There is a way to choose between the header pins and the TXO/RXI; but I can not immediately find it back how it is set.

Please note that the Mega is a 5V device and the RXI is more than likely a 3.3V input and can be damaged by the Mega.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.