Lab 1A
Prelab
During the prelab, I setup my Arduino IDE and installed the nessesary libraries.
Task 1: Blink
Task 2: Serial
The messages were sent with a baud rate of 11520.
Task 3: Analog Read/Temperature Sensing
When I squeezed the board heating it up, the temperature sensor reading increased from 33300 to 33700 units indicating the code works.
Task 4: Microphone
We can also test the microphone on the Artimis Nano. As shown in the video, the loudest frequency reading spikes whenever i snap my finger.
Task 5: Musical C Note
Finally, I wrote code that turns on the board’s LED when a musical c note is played. If not, the LED turns off.
Arduino code logic:
Discussion
In this lab, I learned the basics of working with Arduino and the Artimis Nano board. This lab also help verify that my board is functioning correctly.
Lab 1B
Prelab/ Computer Setup
I ran the following commands to set up my python virtual environment.
To verify that the Artemis was working properly, I verified that the MAC address was printed to terminal when running the ble_arduino script.
I then updated the MAC address in the connections.yaml folder. I also generated a UUID to prevent accedently connecting to another board and updated both the arduino_ble and connections.yaml.
The following setup and codebase allows my computer and the Artemis board to wirelessly communicate with each other. The UUID prevents me from accidently connecting to another board.
Task ECHO
I wrote a simple ECHO command that allows the Artemis to echo recieved commands back with “Robot says -> “ in front of it.
On the Arduino side:
On the Python side:
SEND_THREE_FLOATS
The next task was to extract three floats sent from my laptop and print them to the serial monitor.
On the Arduino side:
On the Python Side:
When the Python code is run, the following message is printed in the serial monitor.
Task GET_TIME_MILLIS
After that, I used the Artimis board’s timer to send a message with the timestamp the message was sent at. I leveraged the millis() function in Arduino to accomplish this.
On the Arduino side:
On the Python side:
Notification Handler
To allow Python to process data whenever a message from the Artemis board is sent, we can set up a notification handler. The notification handler shown below extracts the time and message number and prints it.
On the Python side:
Continuously Sending Messages
An important piece of information is ble’s data transfer rate. To determine this, I wrote a while loop that continuously sends timestamp messages for 5 seconds. The notification handler picks up these messages and prints them. During 5 seconds, 138 messages were outputted (28 messages/sec).
On the Arduino side:
On the Python side:
Sending Messages with an Array
Another method of data transmission is to populate an array with a bunch of messages and then send them. To do this, I defined a global array with 50 slots called time_stamps. I then populated this array with timestamps and then sent them to Python. All 50 messages were sent in around 1ms indicating a much faster data transfer rate.
On the Arduino side:
On the python side:
Sending Temperature and Time Data Simultaneously
Using two arrays in Arduino, we can send both time and temperature data. I created a new command GET_TEMP_READINGS which populated and sent these arrays. On the Python side, I implemented a new notification handler that used the recieved data to populate a corresponding arrays stored on my laptop. I then wrote python code that requested and printed the data from the python arrays.
Arduino Code:
Python Code (notification handler):
Python Code (Request Data):
Python Code (Print Data):
Tradeoffs Between Methods
For sending small packets of data at an infrequent rate, live sending data might be better as the data is sent as soon as it is processed on the microcontroller. It also might be better for debugging. This is bacause the data is in real time which might make troubleshooting a lot easier.
The second method can transfer data really fast. It sent 50 messages in less than a millisecond. However, this data is not in real time. Another disadvantage is that all of the data must be stored on the Artemis which has limited memory. Therefore, this method is ideal for senarios where you want to transmit collected sensor data in bulk quickly for later processing on a computer.
This begs the question of how much data can actually be stored on an Artemis? Our Artemis board has 384kb of storage. The data being transmitted is stored in floats which each take up 4 bytes. Therefore, 96,000 data points of either temperature or time data can be stored before the Artemis Nano runs out of memory.
Effective Data Rate and Overhead
To determine how message size affects transmission rate, I created an Arduino command SEND_MESSAGE that takes in a message size and constructs/transmits a character array of that size (1 element = 1byte). On the Python side, I loop through different message sizes and time how long it takes to recieve a reply. As shown from the plot, many short messages induce more overhead reducing the data transfer rate. Sending longer messages reduces total overhead as less messages are sent. For example, the data transmission rate for 5 byte messages was 20.86 bytes/sec while for 120 byte messages was 501.81 bytes/sec.
Arduino side:
Python side:
Reliability
To test reliability, I wrote an Arduino command called RELIABILITY which transfered 26 messages (containing the message number) with a given delay. I then wrote Python code that prints all of the messages recieved from the Arduino. I experimented with 0,20,100, and 200 ms delays. No matter the delay, all 26 transmitted messages were recieved in Python.
Arduino Side:
Python side
Discussion
In this lab, i gained familarity with BLE and refreshed by knowledge of Arduino/Python programming.