M7e Hecto Serial vs USB detection differences

I’ve been working on a sketch using the M7e and an esp32.

I’m using this code:

#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
#include <SPI.h>
#include “SparkFun_UHF_RFID_Reader.h”

// TFT Pins
#define TFT_CS 5
#define TFT_RST 4
#define TFT_DC 2

Adafruit_ST7789 tft = Adafruit_ST7789(TFT_CS, TFT_DC, TFT_RST);
RFID rfidModule;

#define RXD2 16
#define TXD2 17
#define rfidBaud 115200

// Touch Settings
const int touchPins = {13, 12, 14};
float rollingBaselines[3];
const float alpha = 0.05;
const int touchThreshold = 20;

// RFID Tracking
unsigned long lastClearTime = 0;
const int scanInterval = 1000; // 1 second window to collect all tags
bool foundDigits[16];
bool lastFoundDigits[16];

void setup(void) {
Serial.begin(115200);
tft.init(240, 320);
tft.setRotation(1);
tft.fillScreen(ST77XX_BLACK);
tft.setCursor(0, 0);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);

tft.println(“SYSTEM STARTUP…”);

// Calibrate Touch
for (int i = 0; i < 3; i++) {
long sum = 0;
for (int j = 0; j < 20; j++) sum += touchRead(touchPins[i]);
rollingBaselines[i] = sum / 20.0;
}

Serial2.begin(rfidBaud, SERIAL_8N1, RXD2, TXD2);

if (setupRfidModule(rfidBaud)) {
tft.setTextColor(ST77XX_GREEN);
tft.println(“RFID: MULTI-SCAN ACTIVE”);
rfidModule.setRegion(REGION_NORTHAMERICA);
rfidModule.setReadPower(1800); // 12.00 dBm

// Help with collisions by setting Q
// A higher initial Q helps when multiple tags are present
//rfidModule.setInitialQ(4); 

rfidModule.startReading();

} else {
tft.setTextColor(ST77XX_RED);
tft.println(“RFID: FAILED”);
}

delay(1000);
tft.fillScreen(ST77XX_BLACK);
}

void loop() {
// — TOUCH LOGIC —
tft.setCursor(0, 0);
tft.setTextSize(2);
tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);
tft.println(“SENSOR STATUS:”);

for (int i = 0; i < 3; i++) {
int val = touchRead(touchPins[i]);
int diff = (int)rollingBaselines[i] - val;
bool isTouched = (diff > touchThreshold);

if (!isTouched) {
  rollingBaselines[i] = (rollingBaselines[i] * (1.0 - alpha)) + (val * alpha);
}

tft.printf("W%d: B:%.0f V:%d ", i + 1, rollingBaselines[i], val);
if (isTouched) {
  tft.setTextColor(ST77XX_YELLOW, ST77XX_BLACK);
  tft.print("TOUCH!! ");
} else {
  tft.print("        ");
}
tft.println();
tft.setTextColor(ST77XX_CYAN, ST77XX_BLACK);

}

// — RFID SCANNING —
if (rfidModule.check() == true) {
byte responseType = rfidModule.parseResponse();
if (responseType == RESPONSE_IS_TAGFOUND) {
byte tagEPCBytes = rfidModule.getTagEPCBytes();
byte lastByte = rfidModule.msg[31 + tagEPCBytes - 1];
int digit = lastByte & 0x0F;
foundDigits[digit] = true;
}
}

// — REFRESH DISPLAY —
if (millis() - lastClearTime > scanInterval) {
bool changeDetected = false;
for (int d = 0; d < 16; d++) {
if (foundDigits[d] != lastFoundDigits[d]) {
changeDetected = true;
break;
}
}

if (changeDetected) {
  tft.setCursor(0, 120);
  tft.setTextColor(ST77XX_MAGENTA, ST77XX_BLACK);
  tft.setTextSize(2);
  tft.println("TAGS IN FIELD:");
  
  tft.setCursor(0, 150);
  tft.setTextSize(4);
  tft.fillRect(0, 150, 320, 50, ST77XX_BLACK); 
  
  for (int d = 0; d < 16; d++) {
    if (foundDigits[d]) {
      tft.print(d, HEX);
      tft.print(" ");
    }
    lastFoundDigits[d] = foundDigits[d];
    foundDigits[d] = false; 
  }
} else {
  for (int d = 0; d < 16; d++) foundDigits[d] = false;
}
lastClearTime = millis();

}
}

boolean setupRfidModule(long baudRate) {
rfidModule.begin(Serial2, ThingMagic_M7E_HECTO);

delay(100);
while (Serial2.available()) Serial2.read();

rfidModule.getVersion();
if (rfidModule.msg[0] == ERROR_WRONG_OPCODE_RESPONSE) {
rfidModule.stopReading();
delay(1500);
} else {
Serial2.begin(115200);
rfidModule.setBaud(baudRate);
Serial2.begin(baudRate);
delay(250);
}

rfidModule.getVersion();
if (rfidModule.msg[0] != ALL_GOOD) return false;

rfidModule.setTagProtocol();
rfidModule.setAntennaPort();
return true;
}

It works but I find that I need to hold the tags right up onto the built in antenna. By contrast, when I connect using the Universal Reader Assistant, it reads quite fast and at least from several inches to a foot away.

I’m using an external 5v 1A power supply to power the M7e.
Is it not powerful enough? Should I get one that can provide 2A or 3A?
Should I be using the Mercury library to access other control options?

Any help would be appreciated. Thank you in advance.

I have just connected my M6E to an Esp32. I have used the 5V from the ESP32S3 not external power supply. I have taken the standard example1, just added setting Serial2 to connect to the right pins.

I have set the read power to 1800 (as you did), selected NA region and get about 5 cm of distance detection from the tag. Setting to 2700 I get about 10 cm.

I have then started the URA on a WindowsPC. I get about the same distances with the different reading powers with the URA.

On URA I have created and analyzed the log file, they are nearly the same as on the ESP32 (just more repeats of the same setting and getting information)

Be aware the URA starts by default with 2700 and it is very important to select the same region. Each region has different (free) frequencies to read/write the tags.

If you continue to see a difference, turn on logging on the URA and share the outcome so I can have a look what might be different.

Thank you for the reply. I changed up my sketch a bit and it seems to work better now. It’s still not quite as effective as connecting via USB. I read somewhere that it could be my TFT LCD display that I added could be slowing things down a bit. I have no idea if that’s true or not. I plan on removing that part from the sketch and seeing if readability improves. I’ll report back after.