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();
}
-
Only the first card scanned or the current card being scanned?SoreDakeNoKoto– SoreDakeNoKoto2017年02月21日 20:04:12 +00:00Commented Feb 21, 2017 at 20:04
-
the first scannedXue– Xue2017年02月22日 00:11:37 +00:00Commented Feb 22, 2017 at 0:11
-
3I'm voting to close this question as off-topic because the problem is with the PC code, no the ArduinoChris Stratton– Chris Stratton2018年01月21日 08:26:17 +00:00Commented Jan 21, 2018 at 8:26
1 Answer 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.