Comments (22)
Hi Saiyojeff,
You can use this code to get the ID.
It worked for me :
unsigned int hex_num;
hex_num = mfrc522.uid.uidByte[0] << 24;
hex_num += mfrc522.uid.uidByte[1] << 16;
hex_num += mfrc522.uid.uidByte[2] << 8;
hex_num += mfrc522.uid.uidByte[3];
int NFC_id= (int)hex_num
from rfid.
Hi saiyojeff,
If I understand what you are attempting to do :
You a trying to get a string from the UID of the tag to concatenate it in a GET query.
I did the same with this code and it worked for me. I get this result :
PICC_Select - FIN
Card UID: B0 B8 6A 69
PICC type: MIFARE 1KB
==> Hex Int : -1330091415
Can you give me your code, so I'll try it on my board
from rfid.
In order to get the HEX string you can use this code :
String UID_HEX="";
Serial.print("Printing HEX UID : ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
String partial_id_HEX = String(mfrc522.uid.uidByte[i], HEX);
UID_HEX=StringAdd(UID_HEX, partial_id_HEX);
}
Serial.print("Full ID Hex : ");
Serial.println(UID_HEX);
String StringAdd(String string1, String string2)
{
int len1 = string1.length();
int len2 = string2.length();
char char1[len1];
char char2[len2];
char ret[len1 + len2];
string1.toCharArray(char1, len1 + 1);
string2.toCharArray(char2, len2 + 1);
for(int i = 0; i <= len1 + 1 ; i++){
ret[i] = char1[i];
}
for(int i = 0; i <= len2 + 1; i++){
ret[i + len1] = char2[i];
}
String retval = ret;
return retval;
}
from rfid.
It's not clear to me, you may want to store PICC's UID to some byte array
byte readCard[] ; // This is our byte array to store UID mind that there are 4 and 7 bytes long UID
Serial.println("Scanned PICC's UID:");
for (int i = 0; i < mfrc522.uid.size; i++) {
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
This will output UID to serial monitor and stores it to readCard and you can do whatever you want with this UID.
Getting UID from scanned PICC can be like this:
///////////////////////////////////////// Get PICC's UID ///////////////////////////////////
int getID() {
// Getting ready for Reading PICCs
if ( ! mfrc522.PICC_IsNewCardPresent()) { //If a new PICC placed to RFID reader continue
return 0;
}
if ( ! mfrc522.PICC_ReadCardSerial()) { //Since a PICC placed get Serial and continue
return 0;
}
// There are Mifare PICCs which have 4 byte or 7 byte UID care if you use 7 byte PICC
Serial.println("Scanned PICC's UID:");
for (int i = 0; i < mfrc522.uid.size; i++) { //
readCard[i] = mfrc522.uid.uidByte[i];
Serial.print(readCard[i], HEX);
}
Serial.println("");
mfrc522.PICC_HaltA(); // Stop reading
return 1;
}
You can combine these "if" statements, You may not want to HALT PICC, you can return a boolean instead integer. Modify for your needs.
from rfid.
Ah thanks for the reply. In the simplest words, I would like to store the group of arrays into a single variable. That's it. I just want to utilize the ID into some sort of codes (in case, you don't know about the client.print of the ethernet library, which I intend to use, but anyways, just by helping me about the code for getting to know the unique id from a SINGLE variable and NOT in a way of ARRAYS, :) thanks alot, I'm stuck, please. :) (uppercase is for emphasis, I'm not shouting, fyi :)) Yeah, that one you've provided is the default code in the example of the library, I've just modified it to a definite line of codes instead of a for loop since I'm certain that the IDs I'm using have 8 unique ID nos.
from rfid.
Or is that readCard[] can be used already as a variable? correct me If I'm wrong. I'm not sure If I mnisunderstood your code and explanation. Thank you very much. :)
from rfid.
You have 4 byte UID and you can store it to
byte readCard[4]; // variable to store UIDs
Its a variable data, 4 byte long and it will contain latest scanned PICC's
UID.
12 Ara 2014 18:43 tarihinde "saiyojeff" [email protected] yazdı:
Or is that readCard[] can be used already as a variable? correct me If I'm
wrong. I'm not sure If I mnisunderstood your code and explanation. Thank
you very much. :)—
Reply to this email directly or view it on GitHub
#63 (comment).
from rfid.
Hi gaelperon,
It outputs something but is wrong, :( The unique ID is 44991C33 but when I use your code, it outputs only 7219. I'm using Arduino 1.0.4 I'm not using the latest versions since it seems to be not working for the RC522
from rfid.
I've tried producing outputs from both the NFC_id and hex_num variables (just to check whether there are changes when passing the values, that's why i used both :))
from rfid.
It was a snippet not a complete code, actually I still don't understand
what you are trying to do. If you just want to print a PICC's UID to serial
monitor there are examples out there.
from rfid.
Hi omersiar,
The code you presented is a for loop which outputs the unique ID numbers byte by byte.
For example, the unique ID is 33445A67
In 4 repetitions of the loop, the following is in output,
33
44
5A
67
which makes up into 33445A67 (that is outputted in the serial monitor)
I want these bytes to become into a single variable, with an attempt from gaelperon which you can see above, but it outputs something which is not the unique code.
(The reason why I want to save this into a single variable is that I am outputting it in an ethernet shield( I am not successful in using the default function which is mfrc522.uid.uidByte[i]. I don't want to dig deep further since my question is only saving all the 4 bytes into a single variable, my other concerns are not in the scope of the RC522 that may confuse others. :( )
from rfid.
I don't know any other way around. Data is ready to manipulate, If you want
to send a variable data i'm sure there are ways to do it, people already
doing it, google search will help you I guess.
from rfid.
The code you provided gives me 16161616 which is the same as mine. Thanks for the kind help. I've been searching google in parallel with this question(that's why I also asked in the library itself since I cannot see it in the google results) but I've not arrived with the answer. :( I also thought that the data is really ready to be manipulated since it was given as a function and is outputted in serial monitor successfully but passing it into another variable seems to be not working. :(
from rfid.
@gaelperon Is it possible to output using your code in HEX? Does 7129 pertain to my card which has 44991C33 as it's unique id no. (code based on the example given in the library) Please reply. Thanks a lot.
from rfid.
Try this complete DumpInfo code :
/*
* MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
* The library file MFRC522.h has a wealth of useful info. Please read it.
* The functions are documented in MFRC522.cpp.
*
* Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
* Created by Miguel Balboa (circuitito.com), Jan, 2012.
* Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
* Released into the public domain.
*
* Sample program showing how to read data from a PICC using a MFRC522 reader on the Arduino SPI interface.
*----------------------------------------------------------------------------- empty_skull
* Aggiunti pin per arduino Mega
* add pin configuration for arduino mega
* http://mac86project.altervista.org/
----------------------------------------------------------------------------- Nicola Coppola
* Pin layout should be as follows:
* Signal Pin Pin Pin
* Arduino Uno Arduino Mega MFRC522 board
* ------------------------------------------------------------
* Reset 9 5 RST
* SPI SS 10 53 SDA
* SPI MOSI 11 51 MOSI
* SPI MISO 12 50 MISO
* SPI SCK 13 52 SCK
*
* The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Serial.print("UID size : ");
Serial.println(mfrc522.uid.size);
Serial.print("Printing HEX UID : ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println("");
unsigned long UID_unsigned;
UID_unsigned = mfrc522.uid.uidByte[0] << 24;
UID_unsigned += mfrc522.uid.uidByte[1] << 16;
UID_unsigned += mfrc522.uid.uidByte[2] << 8;
UID_unsigned += mfrc522.uid.uidByte[3];
Serial.println();
Serial.println("UID Unsigned int");
Serial.println(UID_unsigned);
String UID_string = (String)UID_unsigned;
long UID_LONG=(long)UID_unsigned;
Serial.println("UID Long :");
Serial.println(UID_LONG);
Serial.println("UID String :");
Serial.println(UID_string);
}
from rfid.
Yeah yeah you're completely right, I need it to be in the GET query. This is my code for now. This is working but I converted them into string. But some argue that it's not reliable to use the string data type. Although this is working, I am still looking for the HEX values since this is uniform in size. It's always 8 digit. When using DEC, I receive some 9 and some 8 digits. and I want my DB structure to be uniform. Anyways, I hope you could help me :) Thanks a lot. (My another problem now is that the uID is not sent to the web server on the PC but it is serially printed and the client is certified to be connected. but it does not reflect on my DB. I'm using XAMPP, Firewall off, IP both correct. Port is 80. but manual encoding of the argument is working, like localhost/add_data_php?rfid=12345678 [it does reflect on the DB] I know this is not the scope of the library but since you managed it to be working with ETH I hope you can help me. :) May be because it needs delay? or on or off of the SS pins of each? your help will be much appreciated. :))
#include <SPI.h>
#include <MFRC522.h>
#include <Ethernet.h>
#define SS_PIN 9
#define RST_PIN 8
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress server(192,168,0,104); // numeric IP for server (no DNS) (reduce sketch size)
IPAddress ip(192,168,0,103); //numeric IP of the ETHERNET shield (STATIC)
EthernetClient client; //Initialize the Ethernet client library(port 80 is HTTP default):
int first=0;
int counter=0;
String uID;
void setup() {
Serial.begin(9600); // Initialize serial communications with the PC
// disable SD SPI
pinMode(4, OUTPUT);
digitalWrite(4, HIGH);
// disable w5100 SPI
pinMode(10, OUTPUT);
digitalWrite(10, HIGH);
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
//Serial.println("Scan a MIFARE Classic PICC to demonstrate Value Blocks.");
Ethernet.begin(mac, ip); //we used a STATIC address to start ETHERNET
// print your local IP address:
Serial.print("My IP address: ");
for (byte thisByte = 0; thisByte < 4; thisByte++) {
// print the value of each byte of the IP address:
Serial.print(Ethernet.localIP()[thisByte], DEC);
Serial.print(".");
}
// give the Ethernet shield a second to initialize:
delay(1000);
Serial.println("connecting...");
}
void loop() {
// Prepare key - all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
MFRC522::MIFARE_Key key;
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
//Serial.print("Card UID:");
int val1=(mfrc522.uid.uidByte[0]);
int val2=(mfrc522.uid.uidByte[1]);
int val3=(mfrc522.uid.uidByte[2]);
int val4=(mfrc522.uid.uidByte[3]);
String valA=String(val1);
String valB=String(val2);
String valC=String(val3);
String valD=String(val4);
uID=valA+valB+valC+valD;
Serial.print(uID);
Serial.println();
counter=counter+1;
Serial.print(counter);
//}
Serial.println();
// Halt PICC
mfrc522.PICC_HaltA();
// Stop encryption on PCD
mfrc522.PCD_StopCrypto1();
if (counter>first)
{//delay ifs
// enable w5100 SPI
if (client.connect(server, 80)) { //start of IF
Serial.println("connected");
// Make a HTTP request:
client.print("GET /add_data.php?rfid="); //dont make these println
client.print(uID); //dont make these println
client.println(" HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
Serial.print("SENT");
Serial.println();
first++;
Serial.print(first);
Serial.println();
client.stop();
} //end OF IF
}//delay ifs
}
from rfid.
i use this library and i have a problem
'class MFRC522' has no member named 'PCD_INT'
i need helpppp
from rfid.
From what I understand: @saiyojeff and @gaelperon solved their particular issues and this issue could be closed.
@Ouss99 should raise a different issue/ticket instead of commenting here.
from rfid.
that's work on arduino ?!?!?!
from rfid.
@gaelperon "'StringAdd' was not declared in this scope " what a data type ?
from rfid.
I can't seem to make it so that when a specific UID is passed through it will print a message
/*
- MFRC522 - Library to use ARDUINO RFID MODULE KIT 13.56 MHZ WITH TAGS SPI W AND R BY COOQROBOT.
- The library file MFRC522.h has a wealth of useful info. Please read it.
- The functions are documented in MFRC522.cpp.
- Based on code Dr.Leong ( WWW.B2CQSHOP.COM )
- Created by Miguel Balboa (circuitito.com), Jan, 2012.
- Rewritten by Søren Thing Andersen (access.thing.dk), fall of 2013 (Translation to English, refactored, comments, anti collision, cascade levels.)
- Released into the public domain.
- Sample program showing how to read data from a PICC using a MFRC522 reader on the Arduino SPI interface.
*----------------------------------------------------------------------------- empty_skull - Aggiunti pin per arduino Mega
- add pin configuration for arduino mega
- http://mac86project.altervista.org/
----------------------------------------------------------------------------- Nicola Coppola - Pin layout should be as follows:
- Signal Pin Pin Pin
-
Arduino Uno Arduino Mega MFRC522 board
-
- Reset 9 5 RST
- SPI SS 10 53 SDA
- SPI MOSI 11 51 MOSI
- SPI MISO 12 50 MISO
- SPI SCK 13 52 SCK
- The reader can be found on eBay for around 5 dollars. Search for "mf-rc522" on ebay.com.
*/
#include <SPI.h>
#include <MFRC522.h>
#define SS_PIN 10
#define RST_PIN 9
MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance.
int grantedUID = "7C 1F 2E 5B";
void setup() {
Serial.begin(230400); // Initialize serial communications with the PC
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println("Scan PICC to see UID and type...");
}
void loop() {
// Look for new cards
if ( ! mfrc522.PICC_IsNewCardPresent()) {
return;
}
// Select one of the cards
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
// Dump debug info about the card. PICC_HaltA() is automatically called.
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));
Serial.print("UID size : ");
Serial.println(mfrc522.uid.size);
Serial.print("Printing HEX UID : ");
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? " 0" : " ");
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println("");
unsigned long UID_unsigned;
UID_unsigned = mfrc522.uid.uidByte[0] << 24;
UID_unsigned += mfrc522.uid.uidByte[1] << 16;
UID_unsigned += mfrc522.uid.uidByte[2] << 8;
UID_unsigned += mfrc522.uid.uidByte[3];
Serial.println();
Serial.println("UID Unsigned int");
Serial.println(UID_unsigned);
String UID_string = (String)UID_unsigned;
long UID_LONG=(long)UID_unsigned;
Serial.println("UID Long :");
Serial.println(UID_LONG);
Serial.println("UID String :");
Serial.println(UID_string);
if(mfrc522.uid.uidByte == grantedUID) {
Serial.println("access granted");
}
}
from rfid.
send passive tags UID only when tagged to GET query pushingbox parse to gsheet. added weigand uhf data tags for uhf reader. parameter for parse to gsheet new column for 2nd sensor(uhf/passive) still work in progress.
references :-
http://shahrulnizam.com/ct-uno-lesson-wiegand-rfid-reader/
https://www.youtube.com/watch?v=fVBqUeksR1I
int count=0;
unsigned int rfid=0;
#include <SPI.h>
//#include <RFID.h>
#include <MFRC522.h>
#include <Ethernet.h>
void make_request(String& id); // make a badge request
//-------------------------------------------------------------------------------
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED }; //Setting MAC Address
char server[] = "api.pushingbox.com"; //pushingbox API server
IPAddress ip(192,168,1,2); //Arduino IP address. Only used when DHCP is turned off.
EthernetClient client; //define 'client' as object
String data; //GET query with data
float uhf;
float passive;
boolean koneksi = false;
// CONFIG RFID
#define SS_PIN 4
#define RST_PIN 8
MFRC522 mfrc522(SS_PIN, RST_PIN);
unsigned long previousMillis = 0, currentMillis = 0;
//------------------------------------------------------------------------------
void setup() {
Serial.begin(9600);
pinMode(2, INPUT_PULLUP);
pinMode(3, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(2), data0, FALLING);
attachInterrupt(digitalPinToInterrupt(3), data1, FALLING);
if (Ethernet.begin(mac) == 0) {
Serial.println("Failed to configure Ethernet using DHCP");
Ethernet.begin(mac, ip);
}
delay(1000);
SPI.begin();
// mfrc522.init();
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F("Device setup.."));
// // disable rfid
// pinMode(8, OUTPUT);
// digitalWrite(8, HIGH);
}
//------------------------------------------------------------------------------
void loop(){
if ( ! mfrc522.PICC_IsNewCardPresent()) {
// delay(1500);
// mfrc522.PCD_DumpVersionToSerial();
return;
}
if ( ! mfrc522.PICC_ReadCardSerial()) {
return;
}
Serial.println("");
unsigned long UID_unsigned;
UID_unsigned += mfrc522.uid.uidByte[2] << 8;
Serial.println();
Serial.println("UID Unsigned int");
Serial.println(UID_unsigned);
//-------------------------------------
if((count>=26)&&(rfid!=0))
{
rfid=rfid>>1;
Serial.print("RFID Tag: ");
Serial.println(rfid,DEC);
count=0;
//rfid=0;
return;
}
//-------------------------------------
uhf = rfid; // send database
// passive = UID_unsigned; // send database
kemasData(); //packing GET query with data
Serial.println("connecting...");
if (client.connect(server, 80)) {
sendData();
koneksi = true; //connected = true
//-------------------------------------
char c = client.read(); //save http header to c
Serial.print(c); //print http header to serial monitor
//-------------------------------------
Serial.println(uhf); //print sent value to serial monitor
Serial.println(passive); //print sent value to serial monitor
client.stop();
koneksi = false;
data = ""; //data reset
//-------------------------------------
}
else{
Serial.println("connection failed");
}
// loop
/* while(koneksi){
if (client.available()) {
char c = client.read(); //save http header to c
Serial.print(c); //print http header to serial monitor
}
if (!client.connected()) {
Serial.println();
Serial.println("disconnecting.");
Serial.print("RFID Sent :");
Serial.println(suhu); //print sent value to serial monitor
client.stop();
koneksi = false;
data = ""; //data reset
}
} */
delay(5000); // interval
}
//-------------------------------------
void kemasData(){
data+="";
data+="GET /pushingbox?devid=???&tempData="; //GET request query to pushingbox API
data+=uhf;
//data+=passive;
data+=" HTTP/1.1";
}
//-------------------------------------
void sendData(){
Serial.println("connected");
client.println(data);
client.println("Host: api.pushingbox.com");
client.println("Connection: close");
client.println();
}
//-------------------------------------
void data0()
{
rfid=(rfid<<1);
count++;
}
void data1()
{
rfid=(rfid<<1)|1;
count++;
}
from rfid.
Related Issues (20)
- Message spam if the approximate card is not registered (how to solve it?)
- PICC type: Unknown type HOT 1
- How to extend this library for spresense board HOT 1
- Firmware version
- RST not works HOT 1
- Rfid
- Compile error with Arduino ESP32 release 2.0.8 HOT 5
- WARNING: Communication failure, is the MFRC522 properly connected? what is the problem?
- RC522 Mini Not Work vs RC522 Normal HOT 5
- How to get 5 bytes UID ? HOT 3
- Help i can't get the RC522 module for RFID to work. HOT 4
- Card Avaliable Function
- RFID tag shows lines "-----" instead of actual values
- Example "Minimal-SPI" does not compile HOT 1
- "the ordered comparison of pointer with integer zero" Fix for RP2040 (earlephilhower core > 3.3x)
- Help! How does the uid data is return to the buffer array in PICC_Select
- Help me? ARDUINO RC522
- Missing L1 on Hardware - please help what typ to insert...
- CardReader do not detect new cards
- Unable to read a known version from the rc522. Getting 0x89 HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from rfid.