semaf / mfrc522_i2c_library Goto Github PK
View Code? Open in Web Editor NEWMFRC522 i2c for Arduino and ESP8266
MFRC522 i2c for Arduino and ESP8266
Hello,
How can I use two of the RC522?
I did try to make a second MFRC522 class and duplicated the code.
So my try:
#include <Wire.h>
#include "MFRC522_I2C.h"
#define SDA_PIN 21
#define SCL_PIN 22
#define RST_PIN 2
MFRC522 mfrc522(0x2B, RST_PIN);
MFRC522 mfrc522_2(0x28, RST_PIN);
void setup() {
Serial.begin(115200);
Wire.begin(SDA_PIN, SCL_PIN);
mfrc522.PCD_Init();
mfrc522_2.PCD_Init();
ShowReaderDetails();
ShowReaderDetails_2();
Serial.println(F("Scan UID"));
}
void loop() {
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
return;
}
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();
if ( ! mfrc522_2.PICC_IsNewCardPresent() || ! mfrc522_2.PICC_ReadCardSerial() ) {
return;
}
for (byte i = 0; i < mfrc522_2.uid.size; i++) {
Serial.print(mfrc522_2.uid.uidByte[i], HEX);
}
Serial.println();
}
void ShowReaderDetails() {
byte v = mfrc522.PCD_ReadRegister(mfrc522.VersionReg);
Serial.print(F("MFRC522 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown)"));
Serial.println("");
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Communication failure, is the MFRC522 properly connected?"));
}
}
void ShowReaderDetails_2() {
byte v = mfrc522_2.PCD_ReadRegister(mfrc522_2.VersionReg);
Serial.print(F("MFRC522 - 2 Software Version: 0x"));
Serial.print(v, HEX);
if (v == 0x91)
Serial.print(F(" = v1.0"));
else if (v == 0x92)
Serial.print(F(" = v2.0"));
else
Serial.print(F(" (unknown)"));
Serial.println("");
if ((v == 0x00) || (v == 0xFF)) {
Serial.println(F("WARNING: Communication failure, is the MFRC522 - 2 properly connected?"));
}
}
The UIDs of the first device (0x2B) came up quickly, but the second device (0x28) made no output. Only if I put an nfc card on the first device, then came out an output.
Where is the problem?
in code defined AKey:
MFRC522::MIFARE_Key AKey = {keyByte: {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF}};
in code function from library:
MFRC522::StatusCode state = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, 4, AKey, &(mfrc522.uid));
ERROR:
byte PCD_Authenticate(byte command, byte blockAddr, MIFARE_Key *key, Uid uid);
^
libraries\MFRC522_I2C\src\MFRC522_I2C.h:364:7: note: no known conversion for argument 3 from 'MFRC522::MIFARE_Key' to 'MFRC522::MIFARE_Key'
exit status 1
no matching function for call to 'MFRC522::PCD_Authenticate(MFRC522::PICC_Command, int, MFRC522::MIFARE_Key&, MFRC522::Uid*)'
Hello,
In Arduino IDE and Platformio IDE i get the following Error when i just want try the demo:
MFRC522_i2c:9:1: error: 'MFRC522' does not name a type
Thanks
Hi!
In the function PCD_Authenticate the last 4 bytes of the UID have to be used, not the first.
The line 810 should be modified like:
sendData[8+i] = uid->uidByte[i+uid->size-4];
Thanks!
Compiling a sketch and using MFRC522_I2C_library the Arduino IDE reports this message (non blocking but present).
Can you fix it?
thanks. p.
c:\Users...\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp: In member function 'byte MFRC522::PCD_ReadRegister(byte)':
c:\Users...Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:83:51: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [enabled by default]
_TwoWireInstance->requestFrom(_chipAddress, _size);
^
In file included from c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src/MFRC522_I2C.h:82:0,
from c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:10:
C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\Wire\src/Wire.h:50:10: note: candidate 1: uint8_t TwoWire::requestFrom(int, int)
uint8_t requestFrom(int, int);
^
C:\Users...\AppData\Local\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\Wire\src/Wire.h:47:10: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)
uint8_t requestFrom(uint8_t, uint8_t);
^
c:\Users...\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp: In member function 'void MFRC522::PCD_ReadRegister(byte, byte, byte*, byte)':
c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:106:52: warning: ISO C++ says that these are ambiguous, even though the worst conversion for the first is better than the worst conversion for the second: [enabled by default]
_TwoWireInstance->requestFrom(_chipAddress, _count);
^
In file included from c:\Users....\Arduino\libraries\MFRC522_I2C_Library-master\src/MFRC522_I2C.h:82:0,
from c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:10:
C:\Users...\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\Wire\src/Wire.h:50:10: note: candidate 1: uint8_t TwoWire::requestFrom(int, int)
uint8_t requestFrom(int, int);
^
C:\Users...\Arduino15\packages\arduino\hardware\sam\1.6.12\libraries\Wire\src/Wire.h:47:10: note: candidate 2: uint8_t TwoWire::requestFrom(uint8_t, uint8_t)
uint8_t requestFrom(uint8_t, uint8_t);
^
c:\Users...\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp: In member function 'byte MFRC522::PCD_CommunicateWithPICC(byte, byte, byte*, byte, byte*, byte*, byte*, byte, bool)':
c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:458:20: warning: '_validBits' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (backLen < 2 || _validBits != 0) {
^
c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp: In member function 'void MFRC522::PICC_DumpMifareClassicSectorToSerial(MFRC522::Uid, MFRC522::MIFARE_Key*, byte)':
c:\Users...\Arduino\libraries\MFRC522_I2C_Library-master\src\MFRC522_I2C.cpp:1478:4: warning: 'invertedError' may be used uninitialized in this function [-Wmaybe-uninitialized]
if (invertedError) {
^
Is possible to use the IRQ pin of the module.
Right now it seams the IRQ is always low and from what I figured out is that it can be configured change state if a new RFID chip is scanned.
Does your code allow for this?
//Daniel Davidsen
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.