Enabling the SPI Interface with Python
There was one more step — I had to enable the SPI interface.
In frameworks like Nerves, these interfaces are on by default. However, since I was working with Raspbian I needed to set some flags and reboot the machine. Now that the machines could talk over SPI, the next step (in some language ecosystems) is to starting shoving bits over the wire to registers.
The hard way to do this is to read the SPI and RFID reader specifications, including standards, data sheets, and registers.
The simple way, I found, is to use Python.
There's a fantastic Python library that interfaces with my RFID card reader called MFRC522, which I could Pip install. With the RFID reader and the fantastic MFRC522-python library, I was able to read and write data to RFID stickers.
The Internet Level — Connecting to a Flask App
Now, I’ve reached the “Internet” level of my IoT project — the Flask app. I used Python to connect my RFID reader to the Flask app, and ended with a complete book lending application.
Above is my site map for the Flask app. I have a landing page with three links — to add new books to my inventory, to lend out one of my books, and to view my inventory. The first two pages are the ones that interact with the RFID reader.
You can behold my artistic creation below, keeping in mind that this was an experiment and that I’m not a designer.
“Register Books” will allow me to type in the name of a book, click a button, and say, "Okay, this is the book that I want to register." Then, it will save it into the SQL database.
To lend out a book, I can scan the RFID sticker on the book through the RFID reader, and the app updates the status of the book.
Finally, I have inventory, which simply displays all my books and their status. You can see here that I’ve lent The Room to my friend Jace.
Fun fact, there's a bug-turned-feature on the lend screen, did you find it?
And that’s it for my Raspberry Pi, Python, RFID, and Flask app project. I learned a lot about how Python could help me through the process, and I’m excited to work on more stuff like this in the future.
If you’re interested in building your own IoT application, the team at Very is here to help. Check out our guide to learn the basics of IoT development here.