![]() ![]() So we execute the code above as many times as we want to write to different cards. This is mainly because we do not want to write the same information on different cards. import RPi.GPIO as GPIOĪ notable difference between rfidReader.py and rfidWriter.py is that we do not have a while loop in the latter. We create a file called rfidWriter.py and paste the code below. We can see how this works in the code below. To write information on the RFID card, we use another method of the RFID object: rfid.write(). This tells us that our RFID card has the ID 1002059512185 while the RFID tag has the ID 588633495959. You should see something like this being printed to the terminal: Run the Python code above by entering the command sudo python3 rfidReader.py in the terminal. We have placed this code in an infinite loop, which means that the Raspberry Pi will continuously read the output from the RFID module. To read the RFID card date, we call the read() function and store its output in the variables id and text.įinally, we print the ID and text of the card to the terminal with print(id) and print(text), respectively. Then we use rfid = SimpleMFRC522() to create a new object which we will call RFID. import RPi.GPIO as GPIOįirst, we import the necessary modules. ![]() Then, create a Python file rfidReader.py and paste the following code. To do this, connect the components as shown in the diagram above. ![]() Our first step will be to read the information on the RFID card. Then, install the MFRC522 Python library with the following command: sudo pip3 install mfrc522 Code to Read the RFID Card You also need to install pip3 with this command: sudo apt-get -y install python3-pip How to Program the RFID Card Reader with Pythonīefore we get started programming, make sure the SPI interface is enabled on your Raspberry Pi. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. Archives
December 2022
Categories |