Ignacio Romo's GitHub for ECE 4160.

Home
1
2
3
4
5
6

Lab 2: Connecting to bluetooth, sending and receiving data.

This is a setup

Setting up the computer, having the board display a unique MAC address.

Before making the connection, the coding environment for bluetooth communication had to be set up. This involved running a Jupyter Lab notebook and the Arduino IDE. The jupyter notebook given by the class was used to communicate with the board, and the Arduino IDE was used as a serial monitor. As a test of the setup, the board was programmed to display its MAC address to the serial monitor, shown below.

The Artemis printed its MAC address to the serial monitor.

The Artemis will send data in the form of EStrings over bluetooth communication to the computer running Jupyter notebook. Before doing this, the bluetooth UUID had needed to be changed to a randomly generated one, to avoid interference with other boards with the default UUID. This meant that code on the board and jupyter notebook had to be changed.

Making connections

Testing the bluetooth connection and running some code to test it.

As a test of the bluetooth connection, each cell in "demo.ipynb" was run, which contained cells establishing a bluetooth link, sending and receiving data. Shown below is proof of a successful bluetooth connection.

Successful bluetooth connection

Then the sending/receiving functionality was tested, with the computer sending the "PING" command, expecting to receive "PONG" from the board. Note that this image was written after the notification handler was written, which will be explained here.

Ping Pong Test Successful

From this, it was concluded that the bluetooth functionality works, and the lab tasts were begun.

Take it or leave it

Write functions to receive and/or send a simple string.

Two functions were written to handle a basic string. The first one is ECHO, where the board receives a string, appends " :[", and sends the concatenated string back to the sender. This was by sending an EString which appending the incoming string with the string " :[". This was found to be successful, and sample results are shown below.

Echo test successful.

This was followed by a function where the board will send time information on command, sending the run time of the board in milliseconds.

Time test successful

Let me know when it's over

Deal with incoming data from the board the instant it's received.

To avoid using the ble.receive_string, which would only receive data when directed to, a notifcation handler was set up, which would execute a command whenever data is received. A simple notification handler was coded, which prints the received string.

Which is observed to be successful when the DANCE command is sent, then received without using an additional command.

Notification handler tested on DANCE

Reading the room

Have the board send temperature data from its onboard sensor.

After setting up the notification handler, a function was written to the board to send temperature information on command. At first this was done by sending a string with temperature data along with time data, and sending 5 data points taken 1s apart, and observed to be successful below.

Artemis has sent 5 time/temp data points.

After this, a new function was created that sends many temperature data points taken in a 5 second interval. This temperature data would then be added to an array. This required modifying the notification handler to add incoming data to an array,which worked as expected

Due to speed limitations with sending strings, it would be more practical to have the Arduino send data in batches while stopped. The Arduino has 384kB of RAM, meaning it can store 192,000 16-bit values, meaning that it can store the following amounts of data to be transmitted. The following data was calculated assuming that the full RAM space would be used to store data to be sent, which isn't the case in reality since many global variables and other things will take up memory. The data exists just to give a rough idea.

Sampling Rate (Hz) Time
500 6'24"
300 10'50"
150 21'20"
50 64'
20 160'

This leads to the conclusion that a large supply of data can be stored on the robot. It may be wise to erase the data after sending the data to free up space.

This is the end of reporting on lab 2. To go back home, press "home" below.

Home