Assignments

Week 11: Interface and Application Programming

This week's group assignment required us to explore and compare as many tool options as possible for communicating with a microcontroller. We will be comparing the Arduino Serial Monitor with Tkinter.

Arduino Serial Monitor

Webserver for RFID module

To explore on how to program the Arduino IDE and work with communicating it with a microcontroller board using hte Arduino Serial Monitor, we decided to learn how to create a webserver which interacts with an RFID module. The webserver should be able print the UID of the RFID card scanned and refresh the page when a new one is being scanned. It will print the UID of the latest RFID card scanned.

The connections made:

RFID module Xiao board
VCC 3V3
GND GND
TXD D5
RXD D4

NOTE: set the mode of the RFID module to UART mode. Learn more about it here.

We uploaded the following code to the XIAO ESP32-C3.

#include <WiFi.h>
        #include <WebServer.h>
        #include <Adafruit_PN532.h>

        // Wi-Fi credentials
        const char* ssid = "STUDENT";
        const char* password = "LetMeIn!";

        // Web server on port 80
        WebServer server(80);

        // Create PN532 instance on Serial1 (UART)
        #define PN532_RX D5
        #define PN532_TX D4
        HardwareSerial mySerial(1);
        Adafruit_PN532 nfc(PN532_TX, &mySerial);

        // To store latest UID
        String lastUID = "No card scanned yet";

        void handleRoot() {
        String html = "<!DOCTYPE html><html><head><meta http-equiv='refresh' content='2'/>"
                        "<title>RFID Log</title></head><body>"
                        "<h1>Last scanned RFID UID:</h1>"
                        "<p>" + lastUID + "</p>"
                        "</body></html>";
        server.send(200, "text/html", html);
        }

        void setup() {
        Serial.begin(115200);
        delay(1000);

        // Start Wi-Fi
        Serial.println("Connecting to WiFi...");
        WiFi.begin(ssid, password);
        while (WiFi.status() != WL_CONNECTED) {
            delay(500);
            Serial.print(".");
        }
        Serial.println("\nConnected to WiFi");
        Serial.print("IP address: ");
        Serial.println(WiFi.localIP());

        // Start web server
        server.on("/", handleRoot);
        server.begin();
        Serial.println("Web server started");

        // Start RFID on Serial1
        mySerial.begin(115200, SERIAL_8N1, PN532_RX, PN532_TX);
        nfc.begin();

        uint32_t versiondata = nfc.getFirmwareVersion();
        if (!versiondata) {
            Serial.println("Didn't find PN532");
            while (1) delay(10);
        }

        // Configure board to read RFID tags
        nfc.SAMConfig();
        Serial.println("Waiting for RFID card...");
        }

        void loop() {
        server.handleClient();

        // Check for an RFID card
        uint8_t success;
        uint8_t uid[7];    // Buffer to store UID
        uint8_t uidLength; // UID length

        success = nfc.readPassiveTargetID(PN532_MIFARE_ISO14443A, uid, &uidLength);

        if (success) {
            Serial.print("RFID UID: ");
            String uidStr = "";
            for (uint8_t i = 0; i < uidLength; i++) {
            uidStr += String(uid[i], HEX);
            uidStr += " ";
            }
            Serial.println(uidStr);
            lastUID = uidStr;
            delay(1500); // debounce time
        }
        }
        

This is the result:

It was a success!

Tkinter

Tools Explored