SRTR with arduino Mega

Hi,

I use the SRTR with an Arduino Mega 2560 and I’m just asking why we have to slow communication at 38400bps.

Thanks in advance for your help.

Do you use softserial or one of the serial ports ? I use it on MEGA2560 as well and have no problems with speed on a serial port.

I use softserial ports (D51 and D10) and I read on the guide that we have to slow communication at 38400 bps. It is the fonction setupNano who take care of the communication speed if I remember but when I enter 115200 bps in setupNano the communication does not work

SoftSerial has a undocumented maximum, which is depending on the processor and the program load. I am happy if I can reach a stable 56K. Actually 38400 is normally enough to capture the data you need or you can use one of the UART/serial ports and connect the Nano with loose wires.

Ok, I hope that one day Arduino will give us the answer exactly.

Thanks

paulvha:
SoftSerial has a undocumented maximum, which is depending on the processor and the program load. I am happy if I can reach a stable 56K. Actually 38400 is normally enough to capture the data you need or you can use one of the UART/serial ports and connect the Nano with loose wires.

Iam using mega for SRTR with hardware serial Serial1 Iam getting "Module failed to respond. Please check wiring."

is there any way to fix it??

Hi KHADDIR.

You’d need to modify the example sketches to point to one of the Megas free hardware UARTs to switch ports. If you’re not making those changes, the sketch is looking in the wrong place for the SRTR and throwing an error when it doesn’t respond.

Sadly we don’t support this product on the Mega, but you may find others that are willing to share some code that works on a Mega.

HI

TS-Chris is right in his advice. I have been using the SRTR on a Mega without any problems. If you continue to have issues, please share your sketch and maybe I can help. Make sure however to connect TX from the MEGA to RX on the SRTR and the opposite. Also keep the ENABLE line floating and set the onboard switch to HW.

this is the code iam using

Edited by moderator to add code formatting.

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

  Constantly reads and outputs any tags heard

  If using the 
SIMULTANEOUS
 
RFID
 Tag 
READER
 (SRTR) shield, make sure the serial slide
  switch is in the 'SW-UART' position
*/
//
//#include <SoftwareSerial.h> //Used for transmitting to the device
//
//SoftwareSerial softSerial(2, 3); //RX, TX

#include "SparkFun_UHF_RFID_Reader.h" //Library for controlling the M6E Nano module
RFID nano; //Create instance

void setup()
{
  Serial2.begin(115200);
  while (!Serial2); //Wait for the serial port to come online

  if (setupNano(38400) == false) //Configure nano to run at 38400bps
  {
    Serial2.println(F("Module failed to respond. Please check wiring."));
    while (1); //Freeze!
  }

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

  nano.setReadPower(500); //5.00 dBm. Higher values may caues USB port to brown out
  //Max Read TX Power is 27.00 dBm and may cause temperature-limit throttling

  Serial2.println(F("Press a key to begin scanning for tags."));
  while (!Serial2.available()); //Wait for user to send a character
  Serial2.read(); //Throw away the user's character

  nano.startReading(); //Begin scanning for tags
}

void loop()
{
  if (nano.check() == true) //Check to see if any new data has come in from module
  {
    byte responseType = nano.parseResponse(); //Break response into tag ID, RSSI, frequency, and timestamp

    if (responseType == RESPONSE_IS_KEEPALIVE)
    {
      Serial2.println(F("Scanning"));
    }
    else if (responseType == RESPONSE_IS_TAGFOUND)
    {
      //If we have a full record we can pull out the fun bits
      int rssi = nano.getTagRSSI(); //Get the RSSI for this tag read

      long freq = nano.getTagFreq(); //Get the frequency this tag was detected at

      long timeStamp = nano.getTagTimestamp(); //Get the time this was read, (ms) since last keep-alive message

      byte tagEPCBytes = nano.getTagEPCBytes(); //Get the number of bytes of EPC from response

      Serial2.print(F(" rssi["));
      Serial2.print(rssi);
      Serial2.print(F("]"));

      Serial2.print(F(" freq["));
      Serial2.print(freq);
      Serial2.print(F("]"));

      Serial2.print(F(" time["));
      Serial2.print(timeStamp);
      Serial2.print(F("]"));

      //Print EPC bytes, this is a subsection of bytes from the response/msg array
      Serial2.print(F(" epc["));
      for (byte x = 0 ; x < tagEPCBytes ; x++)
      {
        if (nano.msg[31 + x] < 0x10) Serial2.print(F("0")); //Pretty print
        Serial2.print(nano.msg[31 + x], HEX);
        Serial2.print(F(" "));
      }
      Serial2.print(F("]"));

      Serial2.println();
    }
    else if (responseType == ERROR_CORRUPT_RESPONSE)
    {
      Serial2.println("Bad CRC");
    }
    else
    {
      //Unknown response
      Serial2.print("Unknown error");
    }
  }
}

//Gracefully handles a READER that is already configured and already reading continuously
//Because Stream does not have a .begin() we have to do this outside the library
boolean setupNano(long baudRate)
{
  nano.begin(Serial3); //Tell the library to communicate over software serial port
  
  //Test to see if we are already connected to a module
  //This would be the case if the Arduino has been reprogrammed and the module has stayed powered
  Serial3.begin(baudRate); //For this test, assume module is already at our desired baud rate
  while(!Serial3); //Wait for port to open

  //About 200ms from power on the module will send its firmware version at 115200. We need to ignore this.
  while(Serial3.available()) Serial3.read();
  
  nano.getVersion();

  if (nano.msg[0] == ERROR_WRONG_OPCODE_RESPONSE)
  {
    //This happens if the baud rate is correct but the module is doing a ccontinuous read
    nano.stopReading();

    Serial2.println(F("Module continuously reading. Asking it to stop..."));

    delay(1500);
  }
  else
  {
    //The module did not respond so assume it's just been powered on and communicating at 115200bps
    Serial3.begin(115200); //Start software serial at 115200

    nano.setBaud(baudRate); //Tell the module to go to the chosen baud rate. Ignore the response msg

    Serial3.begin(baudRate); //Start the software serial port, this time at user's chosen baud rate
  }

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

  //The M6E has these settings no matter what
  nano.setTagProtocol(); //Set protocol to GEN2

  nano.setAntennaPort(); //Set TX/RX antenna ports to 1

  return (true); //We are ready to rock
}

Also i have changed in library from stream to HardwareSerial

bool RFID::begin(Stream &serialPort) this way to setup uart communication bool RFID::begin(HardwareSerial &serialPort)

how did you made the HW connection between the Mega and the SRTR? which wires are connected and what setting is the switch.

1 SRTR switch is pushed to hw side.

2 srtr rx to mega tx(14)

3 srtr tx to mega rx(15)

GND to GND ? VCC to 5V ?? enable not connected ?

is there any enable pin on the srtr board??? If yes please let me know.

Do I need to enable any pin to use hardware serial

Leave the enable pin floating… it is described on https://learn.sparkfun.com/tutorials/si … e-overview. I’ll try your code over the weekend.

Yes, there is an enable pin on the board, it’s labeled EN on the edge of the board to the right of the FTDI serial header.

The enable pin isn’t connected to the Arduino and isn’t needed for serial communication. According to the [datasheet, the enable pin is only used to disable the module by pulling enable low and by default enable is disconnected enabling the module.

This section from the data sheet explains how EN works.

The ENABLE line (referred to as the SHUTDOWN line in the M6e) must be pulled HIGH or left unconnected for the module to be operational. To shut down the module, the line is set LOW or pulled to Ground. Switching from high to low to high is equivalent to performing a power cycle of the module. All internal components of the module are powered down when ENABLE is set LOW.The Enable line must be connected to a GPO line of the control processor. This will allow the processor to reset the module into a default state should it become unable to communicate with the processor for any reason. Pulling the Enable line low for 50 milliseconds will reset the module.

You might also want to have a look at the [schematic and the [Eagle files as those will help you determine what pins are present and where they are on the board.](https://cdn.sparkfun.com/datasheets/Sensors/ID/Simultaneous_RFID_Tag_Reader.zip)](https://cdn.sparkfun.com/datasheets/Sensors/ID/Simultaneous_RFID_Tag_Reader.pdf)](https://cdn.sparkfun.com/assets/4/e/5/5/0/SEN-14066_datasheet.pdf)

I have tested your sketch and it works well. The only change is that I did not use Serial2 for monitor but the normal Serial.

Hardware connection (made with loose wires)

Nano — MEGA2560

GND ----- GND

VCC ------ +5V

RXD ------ TXD (14)

TXD ------ RXD (15)

Nano switch to HW

There is no enable pin for hardware serial on this board. The serial selection switch sets which pins are used for serial communication. This is explained in more detail in the [Hardware Overview section of the Hookup Guide.](https://learn.sparkfun.com/tutorials/simultaneous-rfid-tag-reader-hookup-guide/hardware-overview)