MFRC522 Printing Names

Hi All -

I am struggling a bit here with why certain serial outputs are printed onto a new line in the serial monitor. I have attached a screenshot of the serial monitors output when I scan a card. I want all of the output to be written on the same line separated by commas, in order to be written to a CSV file by python. I am unsure why there is a new line printed after displaying the UID.

Any advice?

#include <SPI.h>
#include <MFRC522.h>


#define RST_PIN         7          // Configurable, all readers will be using same reset pin
#define SS_1_PIN        53         // Configurable, take a unused digital pin, must be different to other SS 
#define SS_2_PIN        43         // Configurable, take a unused digital pin, must be different to other SS 
#define SS_3_PIN        33         // Configurable, take a unused digital pin, must be different to other SS 


#define NR_OF_READERS   3          // Change depending on number of readers

byte ssPins[] = {SS_1_PIN, SS_2_PIN, SS_3_PIN};

MFRC522 mfrc522[NR_OF_READERS];   // Create MFRC522 instance.

/* Note: Creating a for loop for multiple MFRC522 instances, thus unable to create individual reader names.
         Readers will be named mfrc522[0], mfrc522[1], etc. until NR_OF_READERS condition is met. Sections
         pertaining to each reader zone will be segmented with appropriate comments.
*/

void setup() {

  Serial.begin(9600); // Initialize serial communications with the PC
  while (!Serial);    // Do nothing if no serial port is opened
  SPI.begin();        // Initialize SPI bus

  // Initializes each MFRC522 card
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    mfrc522[reader].PCD_Init(ssPins[reader], RST_PIN);
  }
}


void loop() {

  MFRC522::MIFARE_Key key;
  for (byte i = 0; i < 6; i++) key.keyByte[i] = 0xFF;

  //some variables we need
  byte block;
  byte len;
  MFRC522::StatusCode status;

  //Look for new cards
  for (uint8_t reader = 0; reader < NR_OF_READERS; reader++) {
    if (mfrc522[0].PICC_IsNewCardPresent() && mfrc522[0].PICC_ReadCardSerial()) {
      String Area = "Core";
      //Serial.print("Core,");
      //---Show some details of the PICC (that is: the tag/card)
      Serial.print(Area + ",");
      dump_byte_array(mfrc522[0].uid.uidByte, mfrc522[0].uid.size);
      byte buffer1[18];
      block = 4;
      len = 18;
      //---GET BALL TYPE
      status = mfrc522[0].PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, &key, &(mfrc522[0].uid)); //line 834 of MFRC522.cpp file
      if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Authentication failed: "));
        Serial.print(mfrc522[0].GetStatusCodeName(status));
        return;
      }
      status = mfrc522[0].MIFARE_Read(block, buffer1, &len);
      if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Reading failed: "));
        Serial.print(mfrc522[0].GetStatusCodeName(status));
        return;
      }
      //---PRINT BALL TYPE
      for (uint8_t i = 0; i < 16; i++) {
        if (buffer1[i] != 32) {
          Serial.write(buffer1[i]);
        }
      }
      Serial.print(",");
      //---GET LOT NUMBER
      byte buffer2[18];
      block = 1;
      status = mfrc522[0].PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 1, &key, &(mfrc522[0].uid)); //line 834
      if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Authentication failed: "));
        Serial.print(mfrc522[0].GetStatusCodeName(status));
        return;
      }

      status = mfrc522[0].MIFARE_Read(block, buffer2, &len);
      if (status != MFRC522::STATUS_OK) {
        Serial.print(F("Reading failed: "));
        Serial.print(mfrc522[0].GetStatusCodeName(status));
        return;
      }
      //----PRINT LOT NUMBER
      for (uint8_t i = 0; i < 16; i++) {
        Serial.write(buffer2[i] );
      }
      Serial.println("");
      //-----Halt PICC
      mfrc522[0].PICC_HaltA();
      //-----Stop encryption on PCD
      mfrc522[0].PCD_StopCrypto1();
    }
  }
}



/**
   Helper routine to dump a byte array as hex values to Serial.
*/
void dump_byte_array(byte *buffer, byte bufferSize) {
  for (byte i = 0; i < bufferSize; i++) {
    //Serial.print(buffer[i] < 0x10 ? "0" : " ");
    //Serial.print(buffer[i], HEX);
    String RFID = String(buffer[i], HEX);
    Serial.print(RFID);
  } Serial.print(",");
}

Capture.PNG

Capture.PNG

Is there a line feed character (0x0a) embedded in the data?

Update: Yes, when reading the dump info output, there is a 0A before the input data. I do not understand why it is being input. I am assuming it is in the below pasted code.

  // Input the ball type
  Serial.println(F("Input Lot Number, ending with #"));
  len = Serial.readBytesUntil('#', (char *) buffer, 30) ; // read family name from serial
  for (byte i = len; i < 30; i++) buffer[i] = ' ';     // pad with spaces

  block = 1;
  //Serial.println(F("Authenticating using key A..."));
  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("PCD_Authenticate() failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }
  else Serial.println(F("PCD_Authenticate() success: "));

  // Write block
  status = mfrc522.MIFARE_Write(block, buffer, 16);
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("MIFARE_Write() failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }
  else Serial.println(F("MIFARE_Write() success: "));

  block = 2;
  //Serial.println(F("Authenticating using key A..."));
  status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid));
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("PCD_Authenticate() failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }

  // Write block
  status = mfrc522.MIFARE_Write(block, &buffer[16], 16);
  if (status != MFRC522::STATUS_OK) {
    Serial.print(F("MIFARE_Write() failed: "));
    Serial.println(mfrc522.GetStatusCodeName(status));
    return;
  }
  else Serial.println(F("MIFARE_Write() success: "));