Here is the whole programm:
//Pins ESP 32 Dev Module (AZ Delivery)
/* ESP RFID
* 5V 5V
* 3,3V 3,3V
* 25 RST //AS DEFINED IN PN5180ISO15693 nfc varable
* 26 NSS //AS DEFINED IN PN5180ISO15693 nfc varable
* 23 MOSI
* 19 MISO
* 18 SCK
* 27 BUSY //AS DEFINED IN PN5180ISO15693 nfc varable
* GND GND
* / GPIO
* / IRX
* / AUX
* / REX
*
*
*
* ESP DF Player Mini
* 5V VCC
* 17 100kOHM to GND RX // Hardwareserial TX
* 16 TX // Hardwareserial RX
* / DAC-R
* / DAC-L
* / SPK_1 //Speaker, Black Cable
* GND GND
* / SPK_2 //Speaker, Red Cable
*/
//****RFID Reader***
// Download from https://github.com/playfultechnology/PN5180-Library
#include <PN5180.h>
#include <PN5180ISO15693.h>
// Tag if the current Card
uint8_t lastUid[8];
// Each PN5180 reader requires unique NSS, BUSY, and RESET pins, as defined below
PN5180ISO15693 nfc = PN5180ISO15693(26,27,25);
//****RFID Tags****
//Number of Different Songs
int NumTags =21;
//RFID Tags
int rfid_id[][8]={
{0xE1,0xAF,0xE4,0xED,0x50,0x1,0x4,0xE0},//#0
{0x6C,0x27,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#1
{0x58,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#2
{0xE5,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#3
{0x7C,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#4
{0xFF,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#5
{0x8E,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#6
{0xE,0x2C,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#7
{0x54,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#8
{0xC6,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#9
{0x3F,0x2B,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#10
{0x8,0xCF,0xE0,0xC0,0x50,0x1,0x4,0xE0},//#11
{0xDA,0xCC,0xE0,0xC0,0x50,0x1,0x4,0xE0},//#12
{0x8,0xCD,0xE0,0xC0,0x50,0x1,0x4,0xE0},//#13
{0x98,0x27,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#14
{0xB0,0x25,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#15
{0x60,0x25,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#16
{0xE7,0x27,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#17
{0x22,0x27,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#18
{0x9E,0x24,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#19
{0xE8,0x24,0xE1,0xC0,0x50,0x1,0x4,0xE0},//#20
};
//****MP3 Player****
// This library exposes functions for playing sounds from DFPlayerMini module using the serial connection
// Download from https://github.com/DFRobot/DFRobotDFPlayerMini
#include <DFRobotDFPlayerMini.h>
#include <HardwareSerial.h>//=> SoftwareSerial.h funktioniert nicht bei ESP32 Chipsätzten. Statt dessen HardwareSerial Funktion
// Create an object to access the dfPlayer
DFRobotDFPlayerMini myDFPlayer;
// Initialise a soft serial interface
HardwareSerial MP3Serial(1); //SD3=TX, SD2=RX
//****SFX****
int EffektPin = 34;
//****State Machine****
unsigned long curMillis;
unsigned long prevRfidMillis = 0;
unsigned long millisBetweenRfid= 1000;
void loop(){
curMillis = millis();
RFID();
}
void setup(){
Serial.begin(115200);
Serial.println("Start");
RFIDSetup();
Serial.println("RFID Setup Finished");
MP3Setup();
}
void RFIDSetup(){
Serial.println("RFID Setup");
Serial.println(F("Initialising..."));
nfc.begin();
Serial.println(F("Resetting..."));
nfc.reset();
Serial.println(F("Enabling RF field..."));
nfc.setupRF();
Serial.println("RFID Initialised");
// Slight delay before activating next reader
delay(2000);
}
void RFID(){
if (curMillis - prevRfidMillis >= millisBetweenRfid) {
prevRfidMillis = curMillis;
// Variable to store the ID of any tag read by this reader
uint8_t thisUid[8];
// Try to read a tag ID (or "get inventory" in ISO15693-speak)
ISO15693ErrorCode rc = nfc.getInventory(thisUid);
// If the result code was that a card had been read
if(rc == ISO15693_EC_OK) {
// If this is the same ID as we read last frame
if(memcmp(thisUid, lastUid, 8) == 0) {
// Nothing to do
}
// If it's a different ID
else {
Serial.print(F("New Card Detected on Reader "));
Serial.print(F("..."));
for (int j=0; j<sizeof(thisUid); j++) {
Serial.print(thisUid[j],HEX);
Serial.print(",");
}
Serial.println();
// Update the array that keeps track of most recent ID
memcpy(lastUid, thisUid, sizeof(lastUid[0])*8);
// Has placing this card solved the puzzle?
RFIDCompare();
}
}
// If a card cannot be read
else {
// Test if we previously knew about a card (in which case it's just been removed
// The most significant (last) byte of a valid UID should always be 0xE0. e.g. E007C4A509C247A8
if(lastUid[7] == 0xE0){
Serial.print("Card ");
for (int j=0; j<sizeof(lastUid); j++) {
Serial.print(lastUid[j], HEX);
}
Serial.print(" removed from Reader ");
Serial.println();
// Update the array that keeps track of last known ID
memset(lastUid, 0, sizeof(lastUid[0])*8);
}
}
}
}
void RFIDCompare(){
//Serial.print("Die Kartennummer lautet: ");
//Serial.println(RFIDCode);
for (int i=0; i < NumTags; i++){
Serial.print("Array No. ");
Serial.print(i);
if (memcmp(lastUid, rfid_id[i], 8) != 0) {
Serial.print(". Searching for ");
for (int j=0; j<sizeof(lastUid); j++) {
Serial.print(lastUid[j], HEX);
}
Serial.print(", Compare to current tag ");
for (int j=0; j<sizeof(lastUid); j++) {
Serial.print(rfid_id[i][j], HEX);
}
Serial.println(": Wrong");
}
else {
Serial.println(": Correct");
MP3(i);
break;
}
}
}
void MP3Setup() {
// Initialise the software serial interface used to control the DFPlayer
Serial.print(F("Initialising software serial interface..."));
MP3Serial.begin(9600, SERIAL_8N1, 16, 17);
Serial.print(F("OK!"));
// Start communication with DFPlayer
Serial.print(F("Initialising DFPlayer..."));
if (myDFPlayer.begin(MP3Serial)) {
Serial.println(F("OK!"));
}
else {
Serial.println(F("Failed :("));
}
// Set volume (value from 0 to 30)
myDFPlayer.volume(16);
// Once setup is complete, enter the idle state
Serial.println("MP3 Setup Complete");
}
void MP3(int Songnumber){
delay(100);
myDFPlayer.play(Songnumber);
Serial.print("Playing Song ");
Serial.print(Songnumber);
delay(100);
}
When I put a Tog on the Reader (in this case Tag #4), this is what the serial monitor shows:
Start
RFID Setup
Initialising...
Resetting...
Enabling RF field...
RFID Initialised
RFID Setup Finished
Initialising software serial interface...OK!Initialising DFPlayer...OK!
MP3 Setup Complete
New Card Detected on Reader ...7C,2B,E1,C0,50,1,4,E0,
Array No. 0. Searching for 7C2BE1C05014E0, Compare to current tag E1AFE4ED5014E0: Wrong
Array No. 1. Searching for 7C2BE1C05014E0, Compare to current tag 6C27E1C05014E0: Wrong
Array No. 2. Searching for 7C2BE1C05014E0, Compare to current tag 582BE1C05014E0: Wrong
Array No. 3. Searching for 7C2BE1C05014E0, Compare to current tag E52BE1C05014E0: Wrong
Array No. 4. Searching for 7C2BE1C05014E0, Compare to current tag 7C2BE1C05014E0: Wrong
Array No. 5. Searching for 7C2BE1C05014E0, Compare to current tag FF2BE1C05014E0: Wrong
Array No. 6. Searching for 7C2BE1C05014E0, Compare to current tag 8E2BE1C05014E0: Wrong
Array No. 7. Searching for 7C2BE1C05014E0, Compare to current tag E2CE1C05014E0: Wrong
Array No. 8. Searching for 7C2BE1C05014E0, Compare to current tag 542BE1C05014E0: Wrong
Array No. 9. Searching for 7C2BE1C05014E0, Compare to current tag C62BE1C05014E0: Wrong
Array No. 10. Searching for 7C2BE1C05014E0, Compare to current tag 3F2BE1C05014E0: Wrong
Array No. 11. Searching for 7C2BE1C05014E0, Compare to current tag 8CFE0C05014E0: Wrong
Array No. 12. Searching for 7C2BE1C05014E0, Compare to current tag DACCE0C05014E0: Wrong
Array No. 13. Searching for 7C2BE1C05014E0, Compare to current tag 8CDE0C05014E0: Wrong
Array No. 14. Searching for 7C2BE1C05014E0, Compare to current tag 9827E1C05014E0: Wrong
Array No. 15. Searching for 7C2BE1C05014E0, Compare to current tag B025E1C05014E0: Wrong
Array No. 16. Searching for 7C2BE1C05014E0, Compare to current tag 6025E1C05014E0: Wrong
Array No. 17. Searching for 7C2BE1C05014E0, Compare to current tag E727E1C05014E0: Wrong
Array No. 18. Searching for 7C2BE1C05014E0, Compare to current tag 2227E1C05014E0: Wrong
Array No. 19. Searching for 7C2BE1C05014E0, Compare to current tag 9E24E1C05014E0: Wrong
Array No. 20. Searching for 7C2BE1C05014E0, Compare to current tag E824E1C05014E0: Wrong
Card 7C2BE1C05014E0 removed from Reader
As you can see, it does not recognize the tag. And I have no idea why.