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 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.
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.
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.
From this, it was concluded that the bluetooth functionality works, and the lab tasts were begun.
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.
This was followed by a function where the board will send time information on command, sending the run time of the board in milliseconds.
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.
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.
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.