Lab 2: Bluetooth

Objective

    The goal is to communicate between the Artemis Nano and my computer via bluetooth while also analyzing the data transfer rate and latency.

USB Passthrough Bluetooth

    As shown below, I installed python3 onto my windows computer, along with pip and bleak.

    Installed Python3 on Windows

    Installed pip

Connect to the Artemis Board

    As shown below, the Arduino sketch was properly uploaded to the Artemis board. The blue LED blinked rapidly and then went away after a little while.
    The serial monitor is as intended as shown below:

    Serial monitor after uploading Arduino Code

Ping Your Robot

    I commented out the 'pass' in 'myRobotTasks()' and uncommented 'await theRobot.ping()'. As shown below, the average round-trip latency is 0.1125, and the variance is single modal and peaks at one point. Compared to the serial connection (115200), the wired connection transfered 84592 bytes which is clearly relatively less.

    Variance in Latency

Request a float

    I uncommented 'await theRobot.sendCommand'(Commands.REQ_FLOAT) to request a float. In the arduino code, as shown below, i put in a float that starts at res_cmd->data. I used memcpy(dstAddr, srcAddr, numBytes) and I initialized the float outside.

    As shown below, when I included a lot of sig figs for the float, it gave me an error.

    However, once I reduce the sig figs and ran it again, there was finally an output on the terminal. As shown below, the value does not completely match the value that was transmitted. This is potentially because of the error caused by transmitting via bluetooth.

Test the Data Rate

    To understand wireless data transfer rate, I sent an example of a 32-bit integer and a 64-bit integer. I counted the number of packages and the amount of time by using micros(). The following were the changes made in the code:
    First, the two types of integers were sent by editing the Arduino code as shown below:

    Secondly, the task was added to the python code to communicate to the robot so it perform the task of streaming integers, as shown below:

    Finally, unpack the stream that transmits a 4 byte and a 8 byte integer, that is what Iq represents, as shown below:

    The results for a 14 bytes and 64 bytes are shown in the plots below. They show that the average amount of time of 14 bytes is 11.0733 ms, whereas, for the 64 bytes it is 11.0315. The number of bytes sent does make a difference. For the 14-bytes, out of the 1000 packages sent 19.2% of them were lost, and for the 64 bytes, 20.5 percent were lost out of the same amount. As shown below, the histogram of the data transfer rate results reflects this.