Chat freely about anything...

User avatar
By julezrules
#92917 Hey guys/girls,

I ran into a problem while programming a POS system for a club of a friend.

I built 3 RFID scanners with an Wemos D1 Mini each with a RC522 reader module. They read the NUID of a card, convert it to a string and send it over Serial. These 3 scanners are connected to an old Windows XP computer. drivers are installed and I can successfully monitor the serial data thats being sent. BUT, only after a reset.
If I connect 1 scanner and then run my (AutoIt) Script that fetches the data, it gives me a connection error. (cant connect to device on port COM(X). When I press the reset button on the wemos d1 mini, then it works. I don't know what to do this is annoying :(

Here's the code of the scanner device, it's the same on all 3 wemos d1 minis except the Serial.println("B") from the setup loop which prints A on the first scanner, B on the second and so on, to identify the scanners inside of my script. D1 is just an LED to identify the device is running.

Code: Select all#include <SPI.h>
#include <MFRC522.h>

#define SS_PIN D8
#define RST_PIN D3
 
MFRC522 rfid(SS_PIN, RST_PIN);

MFRC522::MIFARE_Key key;

void setup() {
  pinMode(D1, OUTPUT);
  digitalWrite(D1, LOW);
  Serial.begin(9600);
  SPI.begin();
  rfid.PCD_Init();
  rfid.PCD_SetAntennaGain(rfid.RxGain_max);
  Serial.println("B");
  digitalWrite(D1, HIGH);
}
 
void loop() {
  if ( ! rfid.PICC_IsNewCardPresent())
    return;

  if ( ! rfid.PICC_ReadCardSerial())
    return;

  char str[32] = "";
  array_to_string(rfid.uid.uidByte, 4, str);
  Serial.println(str);
 
  rfid.PICC_HaltA();
  rfid.PCD_StopCrypto1();
}

void array_to_string(byte array[], unsigned int len, char buffer[])
{
  for (unsigned int i = 0; i < len; i++)
  {
    byte nib1 = (array[i] >> 4) & 0x0F;
    byte nib2 = (array[i] >> 0) & 0x0F;
    buffer[i*2+0] = nib1  < 0xA ? '0' + nib1  : 'A' + nib1  - 0xA;
    buffer[i*2+1] = nib2  < 0xA ? '0' + nib2  : 'A' + nib2  - 0xA;
  }
  buffer[len*2] = '\0';
}