Lab 1

Artemis/Bluetooth

In this lab, I familiarized myself with the Artemis Apollo3 Board and the Arduino IDE. In addition, I was able to get some practice with the Bluetooth module of the board and tested its communication functionalities and limits.


Lab 1A

Prelab

Setup

To prepare for this lab I first downloaded the most recent version of the Arduino IDE and downloaded the Sparkfun Apollo3 board. Then I connected to the Artemis board making sure to select the correct COM port.

Blink

The first task was to follow the example code given to make the onboard LED blink. Below is a video.

Serial

The second task was to run the Serial program on the Artemis board to get familiar with serial monitor. We tested UART communication between the board and the computer.

Analog Read

The third task was to test the onboard temperature sensor using the analogRead() function using an example code. As I put my finger nearer to the sensor, the temperature sensor output on the Serial monitor rose.

Microphone Output

The fourth task was to test out the microphone on the board. I used a video that had different frequencies and saw how the microphone picked up the different frequencies using the Serial monitor.

Additional 5000 Task

The last task was to make a program that would light up the onboard LED whenever a C note was played. In order to achieve this I combined the blink and the microphone examples together and edited the main loop function so that it would blink the LED. I edited the printLoudest() function on the given example microphone code and in the main loop, added an if statement that would light up the LED whenever it detected a frequency range between 260 and 265 Hz since that range corresponded to a C note. Below is a video where I tested it with and without a C note playing.

Lab 1 C Note

Lab 1B

Prelab

Setup

The setup for this lab involved creating a virtual Python environment with all the required packages for the course, along with the codebase needed for the lab tasks. After that, I configured Jupyter Lab to run the lab code and updated the necessary settings in the connection.yaml file, such as the MAC address and UUID, to enable my Artemis board to connect to my laptop. To ensure that only my laptop could pair with my board, I generated a random UUID in Python. Finally, I established a Bluetooth connection between my laptop and the board.

Lab 1 B Lab 1 B

Echo

The first thing we had to do was set up the echo command so that it would send a string value to the Artemis board. On the computer side, I augmented the message from the Artemis by adding an R.

echo echo1 echo1output

SEND_THREE_FLOATS

After finishing echo, I started on this command which was to send 3 floats from the artemis board back. I followed the already given code in previous commands to set this up. As shown below, I had three variables that would be hold the three float values and used the function get next value to find the next float sent.

3floats 3floats1

GET_TIME_MILLIS

For this task I used the function millis() to get the current time and sent the time stamp back with a T: prefix. The python code on the computer would then receive this time and print it back out. To do this I used the function receive_string to get the time back.

timemillis timemillis1

Notification Handler

To do this task I had to create a new function called notification handler that would automatically receive data from the baord and I made the function print out the data. This notification handler connects to the same UUID and converts the byte array to a string. I also used the function start_notify to set up the notification handler so it would work with the other commands. Now rather than having to use the function receive_string, the python side would automatically print out the data.

notif

GET_TIME_LOOP_MILLIS

For this next task, I set up a loop that would run for 2 seconds and generate the current time every 2 seconds. As soon as the data is made, it would send it back to the notification handler to print out. I just counted the number of strings that the notification handler spewed out. In 2 seconds, 83 time stamps were received. The effective data transfer rate is (83*4)/2 = 166 bytes/sec.

loop loop1

SEND_TIME_DATA

For this task I combined the previous task with a for loop that would send the generated time stamps one by one. Instead of sending the time stamps as soon as they were generated, I stored the time stamps in an array and once the array was filled, I send it to the computer using the for loop.

timedata timedata1

GET_TEMP_READINGS

For this task, I used the previous task and added a second array that would be responsible for keeping track of the temperature values from the sensor. I collected data using the getTempDegF() function and stored the generated temperature values into an array the same size as the time stamps. I made sure to generate the time stamps and the temperature together so that each temperature corresponded to its respective time stamp. I edited the notification handler so that it would store the readings into two separate lists. I ran into some trouble where without the print statements within the notificaton handler, I wouldn't get any data from the print statements outside the function. This was due to the print statements outside the function finishing before the notification handler so I had to add some extra logic to debug this issue. Throughout these tasks I did not use the same noticification handler but instead made several different versions. This made it imperative that I remember to use the function stop notify to ensure that I would get the correct data.

temp temp1

Discussion

The two methods above have their pros and cons. The first method allows for real time transfer which could be useful for when real time data is needed and slower data transfer rates are ok. The second method however is much faster as by storing the data and sending it in a batch, this method avoids real time delays and data loss. In terms of data storage capacity where the Artemis board was 384 kB of RAM, since we are sending out data into floats which are 4 bytes, around 96000 data points can be stored before the Artemis runs out of memory. For Task 7 when we were sending the temperature and time stamps, this means 48000 pairs of data could be send. However this number would be much less since the data is transmitted as a string which could take more bytes depending on the amount of digits in the number. For example a 3 digit string would be 3 bytes but a 12 digit one would take up around 12 bytes. This makes it hard to estimate how many strings.

Additional 5000 Tasks

Effective Data Rate and Overhead

For the additional tasks, I measured peformance between the board and the computer by testing different reply sizes. I used the len() function to get the actual bytes of the strings and I wrote a loop that sends messages of different byte sizes. Then I calculated the time between sending and receving the message. As shown in the graph below the smaller size 5 byte results had much lower data rates than the larger reply sizes. Due to the byte string constraints, I was only able to test up to 148 bytes where the data rate was much higher. To pick a right reply size depends on the latency and throughput of these package sizes since we would get a quicker acknowledgement in a smaller reply size but we are less efficient.

temp tempplot
Reliability

In addition to testing the data rate, I also tested the reliability by using the SEND_TIME_DATA function and I checked that no data from the array was lost. This time I upped the array size to much larger than 25 and used a counter to see if it caught all the messages which it did, showing that this is indeed reliable.

Conclusion

In conclusion, this lab was very useful to get acquianted with the lab and code environment. I was able to get acquainted more with the bluetooth library and get a refresher on C. I was also able to get familiar with the different methods of sending data between the board and the computer and get a sense of the performance in these data transfer rates and how important they can be.