The following article was made by the guest author Bastian Brumbi made available:
The aim of this series is to exist Tonuino set to expand some features. To do this, we start with the basic concept of this project. The goal of the first part is that the corresponding MP3 file is played when a card is held and the volume can be set via the three additional buttons, the playback can be paused and the cards can be programmed.
To play the sound files, we need the DFPlayer from the Tonuino Set and a micro SD card (max. 32GB, FAT32) with the files. Here it is important that the files are named with numbers ("001.mp3" or "001Name.mp3") so that the DFPlayer can read them.
Hardware
First the hardware. The structure is required:- The Tonuino set, consisting of aNano, the MFRC522 RFID card reader, the DFPlayer and 10 RFID cards
- Microtre
- Loudspeaker
- If not yet available, a Breadboard with jumper cables and a 1kotm resistance from the Resistor kit
The components are wired as follows:
Microcontroller |
module |
note |
|
D 10 |
RC522 - SDA |
|
|
D 13 |
RC522 - SCK |
||
D 11 |
RC522 - Mosi |
||
D 12 |
RC522 - Miso |
||
- |
RC522 - IRQ |
Optional interrupt pin |
|
Gnd |
RC522 - GND |
|
|
D 9 |
RC522 - RST |
||
3V3 |
RC522 - 3.3V |
||
5V |
DFPlayer - VCC |
||
Gnd |
Dfplayer - GND |
||
D 3 |
DFPlayer - RX |
1kotm resistance |
|
D 2 |
DFPlayer - TX |
|
|
D 7 |
Button up |
||
D 6 |
Button OK |
||
D 5 |
Button DWN |
software
Next the program, the following libraries must also be installed:
These can simply be downloaded as a .zip file and added to Arduino IDE. The libraries can also be installed via the integrated library manager.
Copy or load them The following program In the Arduino Ide, choose the Nano And the right port and upload the program.
If you are the first time with that Nano Working microcontrollers, you must first have the CH340 Install driver
In the upper part of the program, the libraries are integrated and macros for the pins of the microcontroller are defined.
#include <Arduino.h> #include <Spi.h> #include <Mfrc522.h> #include "DfrobotdfPlayermini.h" #include <Software.h> #define Rst_pin 9 #define Ss_pin 10 #define Up 7 #define OK 6 #define Dwn 5
Now comes the initialization of the objects and variables.
Software softserial(2, 3); Dfrobotdfplayermini mydfplayer; Mfrc522 mfrc522(Ss_pin, Rst_pin); Mfrc522::Mibare_key key; Mfrc522::Status code status; byte sector = 1; // position in the memory byte blockadr = 4; byte data block[] = { // buffer to describe 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 }; byte buffer[18]; // buffer for reading byte trailer block = 7; Bool State = true; intimately Filecount = 4; // !!! Number of files, please adjust !!!
The following function is responsible for reading the data from the card. If the serial number of the card cannot be read, it can be concluded that an error in communication with the card has occurred and the function is through a earlyreturn ended prematurely. Then the key is applied and the content of the memory in the array is Buffer written.
void readcard() { // Read the RFID Stack -> Buffer IF ( ! mfrc522.Picc_readcarderial()) return; // card cannot be read -> demolition byte size = Sizeof(buffer); status = (Mfrc522::Status code) mfrc522.PCD_authenticate(Mfrc522::Picc_cmd_mf_auth_key_a, trailer block, &AMP;AMP;key, &AMP;AMP;(mfrc522.uid)); IF (status != Mfrc522::Status_ok) { Serial.print(F("PCD_authenticate () Failed:")); Serial.print(mfrc522.Get status code name(status)); return; } status = (Mfrc522::Status code) mfrc522.MIFARE_READ(blockadr, buffer, &AMP;AMP;size); IF (status != Mfrc522::Status_ok) { Serial.print(F("MIFARE_READ () Failed:")); Serial.print(mfrc522.Get status code name(status)); } mfrc522.Picc_halta(); mfrc522.PCD_StopCrypto1(); }
In the method Writecard () Just like the method before a reading error is ended at an early stage. Then the card is authenticated and the array data block written in the memory.
void writecard() { // Writing the DataBlock -> RFID Stack IF ( ! mfrc522.Picc_readcarderial()) return; // card cannot be read -> demolition status = (Mfrc522::Status code) mfrc522.PCD_authenticate(Mfrc522::Picc_cmd_mf_auth_key_a, trailer block, &AMP;AMP;key, &AMP;AMP;(mfrc522.uid)); IF (status != Mfrc522::Status_ok) { Serial.print(F("PCD_authenticate () Failed:")); Serial.print(mfrc522.Get status code(status)); return; } status = (Mfrc522::Status code) mfrc522.MIFARE_WRITE(blockadr, data block, 16); IF (status != Mfrc522::Status_ok) { Serial.print(F("MIFARE_WRITE () Failed:")); Serial.print(mfrc522.Get status code name(status)); } mfrc522.Picc_halta(); mfrc522.PCD_StopCrypto1(); }
This next method is carried out when a new card is scanned. In the first step, it is checked whether the marker is present. The marker consists of a 1st position 0 in the memory block 1. If this is not available, it is a new card, to which a file number must first be rewritten. This is implemented by pressing the buttons (select and confirm). If the marker is present, the corresponding file is played.
void startcard() { readcard(); // new card IF(buffer[0] != 1) { // marker not available mydfplayer.play(1); intimately I = 1; while(true) { IF(!digital read(Up)) { while(!digital read(Up)) delay(20); IF(I < Filecount) { I+=1; mydfplayer.next(); } Else { I = 1; mydfplayer.play(1); } } IF(!digital read(Dwn)) { while(!digital read(Dwn)) delay(20); IF(I > 1) { I-=1; mydfplayer.preview(); } Else { I = Filecount; mydfplayer.play(Filecount); } } IF(!digital read(OK)) { // confirm and describe while(!digital read(OK)) delay(20); data block[0] = 1; data block[1] = I; while(!mfrc522.Picc_isnewCardpresent()) delay(20); writecard(); return; } } } // registered card Else { mydfplayer.play(buffer[1]); } }
The function set up() is carried out once after the start. Here the starting functions of the objects are carried out and the key to the memory of the RFID card is written to the associated array.
void set up() { softserial.Begin(9600); Serial.Begin(115200); while(!mydfplayer.Begin(softserial, false, false)) { Serial.print(F("Undle to Begin")); delay(1000); } Spi.Begin(); mfrc522.PCD_init(); for (byte I = 0; I < 6; I++) { key.keybye[I] = 0xff; } pin mode(Up, Input_pullup); pin mode(OK, Input_pullup); pin mode(Dwn, Input_pullup); mydfplayer.volume(5); }
The Loop () Is the function that after the set up() is constantly repeated. If a new card is recognized, the method becomes Startcard () called. When a button has been pressed, the file is paused or continued, or the volume is changed.
void loop() { IF (mfrc522.Picc_isnewCardpresent()) { // Card recognized startcard(); } IF(!digital read(Up)) { while(!digital read(Up)) delay(20); // Waiting until button was let go mydfplayer.volume up(); } IF(!digital read(Dwn)) { while(!digital read(Dwn)) delay(20); // Waiting until button was let go mydfplayer.volumedown(); } IF(!digital read(OK)) { while(!digital read(OK)) delay(20); // Waiting until button was let go IF(State) { mydfplayer.pause(); State = 0; } Else { mydfplayer.start(); State = 1; } } }
Service
Next, keep a blank RFID card to the MFRC522 module, then you can select the MP3 file to be played via the outer buttons. The currently selected file is then played. If you have selected the correct file, confirm this by pressing the middle button. Remove the card and hold it again in front of the module. Now the number of the file to be played is saved in the 1kbyte memory of the tag and is played when the card is held again.
If you want to write a new file on the card, you can simply use a free app, such as NFC tools, format (other -> formats memory) and repeat the previous steps.
In the following parts we will expand our previous project with additional functions and modules. Among other things, an OLED display and an LED ring to display the progress, status and names.
Have fun recovery :)
4 Reacties
Andreas Wolter
@Michael: Danke für den Hinweis. Wir haben das in der Quelldatei korrigiert. Da haben sich Hilfszeichen zum Referenzierer hinzugesellt, die dort nicht hingehören.
Grüße,
Andreas Wolter
AZ-Delivery Blog
Michael
Hallo,
vielen Dank für die tolle Arbeit an diesem Projekt.
Wenn jemand die einzelnen Teile Schrittweise nachbauen möchte, muss der Code aus Teil 1 ein wenig angepasst werden, ansonsten wird in der Arduino IDE das Kompilieren mit Fehlermeldung abgebrochen.
In den Zeilen 40, 46 und 59 hat sich ein Fehler eingeschlichen und es muss jeweils die Zeichenfolge “amp;amp;amp;” gelöscht werden:
Zeile 40 und 59:
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &amp;key, &amp;(mfrc522.uid));
Korrektur:
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, trailerBlock, &key, &(mfrc522.uid));
Zeile 46:
status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockAddr, buffer, &amp;size);
Korrektur:
status = (MFRC522::StatusCode) mfrc522.MIFARE_Read(blockAddr, buffer, &size);
Viele Grüße
Michael
Andreas Wolter
@Oliver: es gibt keine blöden Fragen. Für solch einen Fall ist sie tatsächlich berechtigt. Ja über den Empfänger wird im Transponder induktiv eine Spannung erzeugt. Dadurch fließt Strom und der Chip kann seine Daten übertragen (wenn es sich wie hier um ein passives System handelt).
Rein theoretisch ist die Feldstärke zu schwach, um den Inhalt eines Magnetbandes zu verändern. Dazu kommt die erzeugte Frequenz, die von der Frequenz abweicht, die den Inhalt des Magnetbandes verändern kann.
Es lässt sich natürlich nicht 100%ig ausschließen. Aus meiner Erfahrung konnten RFID-Karten zusammen mit Bankkarten in einer Geldbörse den Magnetstreifen auf den Bankkarten ebenfalls nicht verändern.
Um wirklich sicher zu gehen, müssten Sie Tests durchführen.
Hier finden Sie noch einmal Details zur RFID Technik:
https://www.rfid-basis.de/rfid-technik.html
Hier sind berechnungen zur Feldstärke von RFID enthalten:
https://www.bsi.bund.de/SharedDocs/Downloads/DE/BSI/ElekAusweise/RFID/Mars_Teilbericht_1Therorie_pdf.pdf?__blob=publicationFile&v=1
Grüße,
Andreas Wolter
AZ-Delivery Blog
Oliver
Ich habe mir das TonUINO Set bestellt und freue mich eigentlich schon sehr das Projekt nachzubauen und später mal für meinen Bedarf zu erweitern/umzubauen.
Leider habe ich bisher genau 0 Erfahrung mit der RFID Technik und daher eine (blöde?) Frage:
Soweit ich es verstehe, werden die RFID Tags durch das Lesegerät induktiv mit Strom versorgt, es entsteht also ein Magnetfeld. Ist dieses Magnetfeld geeignet um Magnetbänder (hier Audiokassetten) zu beschädigen? Konkret habe ich vor meine Hörspielsammlung zu digitalisieren und jeder Kassette einen RFID Tag zu verpassen. Der Tag würde dann (als Karte) zwischen Cover und Kassette liegen, das ganze dann in der entsprechenden Hülle, welche dann auf dem Lesegerät liegen würde. Geht das? Oder laufe ich Gefahr meine wertvollen Kassetten zu beschädigen?