Boxin Xu

Fast Robot 2023 · ECE 5160

Hi! I am Boxin. This website is used to document Fast Robot labs(ECE 5160) offered at Cornell University.


Lab 1

The Artemis Board

Introduction

This lab get me familar with SparkFun Artemis Nano board, which is the mini controller we use for this course. It integrated LED, temperature sensor, microphone, bluetooth module and so on. In this lab, I will go through the lab manual and setup Artemis Nano board.

Setup Arduino IDE

I already have Arduino IDE installed in my laptop, so I only need to follow setup instruction by Sparkfun to finish the Artemis setup. I installing the Arduino Core for Apollo3 as figure shown below.

I changed baud to 115200, to keep board and Arduino IDE compatible with each other.

...
Blink it Up

This part is simply follow setup instruction and run example code, which is included in the library, to blink the Artemis build in LED. LED lights up successful.

Serial Testing

By uploading sample Arduino serial schetch, I make sure the board have success connection via serial communication.

...
Temperature Sensor Testing

I upload the analog read example from Arduino library to read the temperature change when I put my finger on the sensor. Temperature changed slowly. But when I put my finger on sensor the reading goes up. And when my finger leave sensor, temperature drop slowly.

...
Microphone Output Testing

I upload the microphone output example from Arduino library to read the maximum frequency the board read. When I speak or whistl, the maximum frequency increased as shown in the figure.

...
Additional Task

In this part, the Artemis board need to detect a musical A sound and light up LED. Turn of LED if board does not detect a musical A. I set if maximum frequency go beyond a threshold, digital write the LED to HIGH; otherwise digital write the LED to LOW.


Lab 2

Bluetooth Communication

Pre Lab

Setup

In the pre lab, I update all requred packages and install virtual environment for the project. And I download the codebase provided by course. The codebase include 4 bluetooth schetches for Artemis borad and python scripts for laptop side.

Figure below shows the MAC address published by Artemis. I need to change 7 to 07 to make it work. Also, I need to generate UUID for the Artemis, recording both MAC address and UUID in python yaml file to build connection with Artemis.

...

Following figure shows the UUID

...

Codebase

The purpose of the MAC address is to uniquely identify my Artemis device, so that I can easily locate it among other devices that support Bluetooth. The UUID (Universal Unique Identifier) help laptop differentiate the different data types from Artemis. The Arduino schetches use bluetooth library to build bluetooth connection. It includes features such as send and receive different types of data. And it containes types of robot command. The workflow is: laptop send a command via bluetooth, Artemis receive bluetooth and execute the command. Then Artemis send collected data back to laptop.

Bluetooth Connenction

I am able to connect bluetooth in Windows 11 after I follow this instruction on Ed Discussion. Following figure shows laptop connect to Artemis successfully.

...
Echo Command

To get Echo command working properly, I need to add a command in python side to send the command, and also a command on Artemis to receive the Echo command and send whatever laptop said back to the laptop. I use ble.send_command(CMD.ECHO,'HiHello') in python to send robot the message, and receive message from Artemis over bluetooth by ble.receive_string(ble.uuid['RX_STRING']). In addition, I add a command case in Artemis, which clear the chracter array and append new character to the enhanced string. Then write the message back to laptop use tx_characteristic_string.writeValue(tx_estring_value.c_str()) Below is the output from terminal:

...
Get Time Command

The second task is very similar to the Echo command. The only 2 difference is: First, I don't need any input from laptop. Second, instead of transfer string, Artemis transfer float back to laptop. In the python side, I use ble.send_command(CMD.GET_TIME_MILLIS,''). In the Arduino schetch, I append tx_estring_value.append((float)millis()) I get output as following figure shown.

...
Notification Handler

Since we don't know the exact time of receving message back from Artemis, we want to create a notification handler to run asynchronous, and publish the data whenever laptop get them. I create the handler as following figure shown. It first decode the message then print the timestamp. Then extract and print time in terminal.

...
Get Temperature Command

To get temperature from Artemis, I use tx_estring_value.append((float)getTempDegC()) to append temperature to estring along with timestamp. In the Arduino schetch, I use a for loop to collect data and set time interval as 1s. Then send all 5 pairs of data via bluetooth once it done with data collection. Then I get result as shown:

...

However, if we want to get data as fast as possible in 5s, there will be a characteristic size limit. So I create 2 global arrays in Arduino schetch and put pair of temperature with timestamp in arrays. One array is used to store time and another is for temperature. After that, I match pairs and send data to laptop. Since python disconnect bluetooth without waiting to receive all data, I manually add sleeping time in python to wait for data transmission. The following video shows the result.

Limitation

If we are collecting data at 150HZ frequency, we have 150 samples per second. While 1 sample contain 16 bit, so 150 samples/s is equal to 2400 bit/s. The Artemis have 384 kB RAM, which equal to 3072000 bit, because 1 Byte equals to 8 bit. Therefore, without clear memory, assume all RAM is available, we can use 3072000 bit divived by 2400 bit/s, which is 1280s. So the maximum time we can use to store data is 1280s, under the assumption of 5s of 16-bit values taken at 150HZ.

Effective Data Rate and Overhead

I calculate effective data rate by using size of data in Byte divided by time used to transfer data. Times start at the moment of sending command from laptop to Artemis and end at the moment gets to the notification handler. In the Artemis side, I append in string length to add byte. I test data size of 5,50,100,120 and 150. From figure below we can see the larger the data size is, the higher effective data rate is.

...
Reliability

When I send data at a higher rate from robot to the computer, my computer read all the data published without missing anything. Because when notification handler processing speed is slower than Artemis sending speed, data will be stored on my laptop's system, which is much powerful than that of Artemis. The only problem is I have to put sleeping time in python to wait until data transfer finish. Otherwise the python will disconnect bluetooth before data transfer complete.