0

I am trying to get the UID of RFID from Arduino to netbeans. I was able to display it to a textfield, but once another rfid was scanned, it is displayed together with the UID from the prev scan. How do I stop Arduino to send data so the only thing displayed in the textfield was the first UID scanned.

Here is Arduino code:

#include <SPI.h>
#include <MFRC522.h>
#define RST_PIN 9 // Configurable, see typical pin layout above
#define SS_PIN 10 // Configurable, see typical pin layout above
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
void setup() {
 Serial.begin(9600); // Initialize serial communications with the PC
 while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
 SPI.begin(); // Init SPI bus
 mfrc522.PCD_Init(); // Init MFRC522
 //mfrc522.PCD_DumpVersionToSerial(); // Show details of PCD - MFRC522 Card Reader details
 //Serial.println(F("Scan PICC to see UID, SAK, type, and data blocks..."));
}
void loop() {
 // Look for new cards
 String code = "";
 if ( ! mfrc522.PICC_IsNewCardPresent()) {
 return;
 }
 // Select one of the cards
 if ( ! mfrc522.PICC_ReadCardSerial()) {
 return;
 }
 for (byte i = 0; i < mfrc522.uid.size; i++) {
 code += String(mfrc522.uid.uidByte[i] < 0x10 ? " 0" :" ");
 code += String(mfrc522.uid.uidByte[i], HEX);
 }
 code.toUpperCase();
 Serial.println(code);
 mfrc522.PICC_HaltA();
}
asked Feb 21, 2017 at 19:54
3
  • Only the first card scanned or the current card being scanned? Commented Feb 21, 2017 at 20:04
  • the first scanned Commented Feb 22, 2017 at 0:11
  • 3
    I'm voting to close this question as off-topic because the problem is with the PC code, no the Arduino Commented Jan 21, 2018 at 8:26

1 Answer 1

1

Unless there is a fault in the library you are using there is nothing wrong with the Arduino code, this can be seen from the serial output.

The fault is with the receiving java code, pump test data into that to see what is wrong.

answered Feb 22, 2017 at 13:12

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.