FYP Feeds

Microcontroller connection

2025-07-11 20:02 Programming Tutorial Production Milestone
The first step was to establish effective communication with the microcontroller. For this project, an Elegoo Uno R3 was used; however, the concept would be nearly identical for most microcontrollers, as the Elegoo is based on the Arduino Uno design.
After some research, it became clear that communicating via a USB cable was relatively straightforward. The main requirement was simply identifying the port the microcontroller was using and ensuring that the port was opened each time a scene was loaded in the Unity engine.
    void attemptConnection()
    {
        try
        {
            freeSerialLink();

            serialPort = new SerialPort("COM3", 19200);
            serialPort.Open();
            // Start a separate thread to read serial data
            serialThread = new Thread(ReadSerial);
            serialThread.Start();
            SendDataToArduino("Wake up\n");
            Debug.Log("Serial port opened!");
        }
        catch (UnauthorizedAccessException e)
        {
            Debug.LogError("Access denied opening serial port: " + e.Message);
        }
        catch (Exception e)
        {
            Debug.LogError("Error opening serial port: " + e.Message);
        }
    }
To find the correct port, it was simply a matter of opening the Device Manager and locating the one listed as “Arduino Uno.”
After confirming that communication was successfully established, the next step was to decide what to connect to the Arduino in order to enhance interactivity and ensure it aligned with the scope of the project.
After thoughtful consideration, it was decided to use an RGB LED to represent the critter’s mood, an LED bar to display loading progress, and both an active and a passive buzzer to allow the critter to express itself vocally without relying on in-game audio.
The next step will be to complete the adoption sequence and ensure it includes both visual and auditory cues from the microcontroller.